* [PATCH 1/1] pseries/hotplug-memory.c: Change rc variable to bool
@ 2019-08-01 23:10 Leonardo Bras
2019-08-02 7:18 ` David Hildenbrand
0 siblings, 1 reply; 4+ messages in thread
From: Leonardo Bras @ 2019-08-01 23:10 UTC (permalink / raw)
To: linuxppc-dev, linux-kernel
Cc: Leonardo Bras, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, David Hildenbrand, Greg Kroah-Hartman,
Rafael J. Wysocki, Nathan Fontenot, YueHaibing, Thomas Gleixner,
Mahesh Salgaonkar, Rob Herring
Changes the return variable to bool (as the return value) and
avoids doing a ternary operation before returning.
Also, since rc will always be true, there is no need to do
rc &= bool, as (true && X) will result in X.
Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
---
arch/powerpc/platforms/pseries/hotplug-memory.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 8e700390f3d6..392deb4855e5 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -338,7 +338,7 @@ static int pseries_remove_mem_node(struct device_node *np)
static bool lmb_is_removable(struct drmem_lmb *lmb)
{
int i, scns_per_block;
- int rc = 1;
+ bool rc = true;
unsigned long pfn, block_sz;
u64 phys_addr;
@@ -363,11 +363,11 @@ static bool lmb_is_removable(struct drmem_lmb *lmb)
if (!pfn_present(pfn))
continue;
- rc &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
+ rc = is_mem_section_removable(pfn, PAGES_PER_SECTION);
phys_addr += MIN_MEMORY_BLOCK_SIZE;
}
- return rc ? true : false;
+ return rc;
}
static int dlpar_add_lmb(struct drmem_lmb *);
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] pseries/hotplug-memory.c: Change rc variable to bool
2019-08-01 23:10 [PATCH 1/1] pseries/hotplug-memory.c: Change rc variable to bool Leonardo Bras
@ 2019-08-02 7:18 ` David Hildenbrand
2019-08-02 7:23 ` David Hildenbrand
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2019-08-02 7:18 UTC (permalink / raw)
To: Leonardo Bras, linuxppc-dev, linux-kernel
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Greg Kroah-Hartman, Rafael J. Wysocki, Nathan Fontenot,
YueHaibing, Thomas Gleixner, Mahesh Salgaonkar, Rob Herring
On 02.08.19 01:10, Leonardo Bras wrote:
> Changes the return variable to bool (as the return value) and
> avoids doing a ternary operation before returning.
>
> Also, since rc will always be true, there is no need to do
> rc &= bool, as (true && X) will result in X.
>
> Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
> ---
> arch/powerpc/platforms/pseries/hotplug-memory.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> index 8e700390f3d6..392deb4855e5 100644
> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> @@ -338,7 +338,7 @@ static int pseries_remove_mem_node(struct device_node *np)
> static bool lmb_is_removable(struct drmem_lmb *lmb)
> {
> int i, scns_per_block;
> - int rc = 1;
> + bool rc = true;
> unsigned long pfn, block_sz;
> u64 phys_addr;
>
> @@ -363,11 +363,11 @@ static bool lmb_is_removable(struct drmem_lmb *lmb)
> if (!pfn_present(pfn))
> continue;
>
> - rc &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
> + rc = is_mem_section_removable(pfn, PAGES_PER_SECTION);
No, that's wrong.
If is_mem_section_removable() is false in the first iteration but true
in the last iteration, you would return true instead of false, which
introduced a bug. We have to AND all sub-results, not simply use the
last one.
> phys_addr += MIN_MEMORY_BLOCK_SIZE;
> }
>
> - return rc ? true : false;
> + return rc;
> }
>
> static int dlpar_add_lmb(struct drmem_lmb *);
>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] pseries/hotplug-memory.c: Change rc variable to bool
2019-08-02 7:18 ` David Hildenbrand
@ 2019-08-02 7:23 ` David Hildenbrand
2019-08-02 13:48 ` Leonardo Bras
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2019-08-02 7:23 UTC (permalink / raw)
To: Leonardo Bras, linuxppc-dev, linux-kernel
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Greg Kroah-Hartman, Rafael J. Wysocki, Nathan Fontenot,
YueHaibing, Thomas Gleixner, Mahesh Salgaonkar, Rob Herring
On 02.08.19 09:18, David Hildenbrand wrote:
> On 02.08.19 01:10, Leonardo Bras wrote:
>> Changes the return variable to bool (as the return value) and
>> avoids doing a ternary operation before returning.
>>
>> Also, since rc will always be true, there is no need to do
>> rc &= bool, as (true && X) will result in X.
>>
>> Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
>> ---
>> arch/powerpc/platforms/pseries/hotplug-memory.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
>> index 8e700390f3d6..392deb4855e5 100644
>> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
>> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
>> @@ -338,7 +338,7 @@ static int pseries_remove_mem_node(struct device_node *np)
>> static bool lmb_is_removable(struct drmem_lmb *lmb)
>> {
>> int i, scns_per_block;
>> - int rc = 1;
>> + bool rc = true;
>> unsigned long pfn, block_sz;
>> u64 phys_addr;
>>
>> @@ -363,11 +363,11 @@ static bool lmb_is_removable(struct drmem_lmb *lmb)
>> if (!pfn_present(pfn))
>> continue;
>>
>> - rc &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
>> + rc = is_mem_section_removable(pfn, PAGES_PER_SECTION);
>
> No, that's wrong.
>
> If is_mem_section_removable() is false in the first iteration but true
> in the last iteration, you would return true instead of false, which
> introduced a bug. We have to AND all sub-results, not simply use the
> last one.
BTW, including such subtle changes in a "Change rc variable to bool"
patch should be avoided.
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] pseries/hotplug-memory.c: Change rc variable to bool
2019-08-02 7:23 ` David Hildenbrand
@ 2019-08-02 13:48 ` Leonardo Bras
0 siblings, 0 replies; 4+ messages in thread
From: Leonardo Bras @ 2019-08-02 13:48 UTC (permalink / raw)
To: David Hildenbrand, linuxppc-dev, linux-kernel
Cc: Rob Herring, Rafael J. Wysocki, YueHaibing, Mahesh Salgaonkar,
Paul Mackerras, Greg Kroah-Hartman, Nathan Fontenot,
Thomas Gleixner
[-- Attachment #1: Type: text/plain, Size: 284 bytes --]
On Fri, 2019-08-02 at 09:23 +0200, David Hildenbrand wrote:
> subtle changes in a "Change rc variable to bool"
> patch should be avoided.
You are right.
If it was a valid change, I should give it a patch for itself.
I will keep that in mind next time.
Thanks for helping!
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-02 13:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 23:10 [PATCH 1/1] pseries/hotplug-memory.c: Change rc variable to bool Leonardo Bras
2019-08-02 7:18 ` David Hildenbrand
2019-08-02 7:23 ` David Hildenbrand
2019-08-02 13:48 ` Leonardo Bras
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).