Skip to contentSkip to conversation

lib/logic_iomem: replace usage of found with dedicated list iterator variable

PATCH New Jakob Koschel 1 participant 1 message Mar 24, 2022 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/logic_iomem: replace usage of found with dedicated list iterator variable

To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body.

To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1].

This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit.

---
 lib/logic_iomem.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
lib/logic_iomem.c +7 -7
index 8c3365f26e51..62426a6f8103 100644
@@ -86,20 +86,20 @@ static void real_iounmap(volatile void __iomem *addr)
 void __iomem *ioremap(phys_addr_t offset, size_t size)
 {
 	void __iomem *ret = NULL;
-	struct logic_iomem_region *rreg, *found = NULL;
+	struct logic_iomem_region *rreg = NULL, *iter;
 	int i;
 
 	mutex_lock(&regions_mtx);
-	list_for_each_entry(rreg, &regions_list, list) {
-		if (rreg->res->start > offset)
+	list_for_each_entry(iter, &regions_list, list) {
+		if (iter->res->start > offset)
 			continue;
-		if (rreg->res->end < offset + size - 1)
+		if (iter->res->end < offset + size - 1)
 			continue;
-		found = rreg;
+		rreg = iter;
 		break;
 	}
 
-	if (!found)
+	if (!rreg)
 		goto out;
 
 	for (i = 0; i < MAX_AREAS; i++) {
@@ -108,7 +108,7 @@ void __iomem *ioremap(phys_addr_t offset, size_t size)
 		if (mapped_areas[i].ops)
 			continue;
 
-		offs = rreg->ops->map(offset - found->res->start,
+		offs = rreg->ops->map(offset - rreg->res->start,
 				      size, &mapped_areas[i].ops,
 				      &mapped_areas[i].priv);
 		if (offs < 0) {

base-commit: f443e374ae131c168a065ea1748feac6b2e76613

Signature · 1 line
2.25.1