Skip to contentSkip to conversation

pseries/hotplug-memory.c: Change rc variable to bool

PATCH Superseded Leonardo Bras 2 participants 4 messages Aug 1, 2019 – Aug 2, 2019 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pseries/hotplug-memory.c: Change rc variable to bool

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.

---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/hotplug-memory.c +3 -3
index 8e700390f3d6..392deb4855e5 100644
@@ -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 *);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 25 lines · Leonardo Bras

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.

---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
index 8e700390f3d6..392deb4855e5 100644
@@ -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;
 

arch/powerpc/platforms/pseries/hotplug-memory.c static bool lmb_is_removable(struct drmem_lmb *lmb) · line 366

Quoted 5 lines
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
@@ -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.

Quoted 9 lines
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
 		phys_addr += MIN_MEMORY_BLOCK_SIZE;
 	}
 
-	return rc ? true : false;
+	return rc;
 }
 
 static int dlpar_add_lmb(struct drmem_lmb *);
Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
Quoted 34 lines · David Hildenbrand
Quoted 25 lines · Leonardo Bras

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.

---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
index 8e700390f3d6..392deb4855e5 100644
@@ -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;
 

arch/powerpc/platforms/pseries/hotplug-memory.c static bool lmb_is_removable(struct drmem_lmb *lmb) · line 366

Quoted 5 lines
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
@@ -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.

Quoted 4 lines

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.

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
Quoted 2 lines · David Hildenbrand

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!