Skip to contentSkip to conversation

resource: Replace open coded resource_overlaps()

PATCH Applied Andy Shevchenko 2 participants 4 messages Sep 15 – Sep 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 resource: Replace open coded resource_overlaps()

In iomem_map_sanity_check() a piece of code resembles the content of the resource_overlaps(). Replace open coded piece with the call to the existing helper.

---
 kernel/resource.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
kernel/resource.c +6 -8
index 54d7199695fb..cfc1a00e86aa 100644
@@ -1833,7 +1833,7 @@ __setup("reserve=", reserve_setup);
  */
 int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
 {
-	resource_size_t end = addr + size - 1;
+	struct resource mem = DEFINE_RES_MEM(addr, size);
 	struct resource *p;
 	int err = 0;
 
@@ -1843,12 +1843,10 @@ int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
 		 * We can probably skip the resources without
 		 * IORESOURCE_IO attribute?
 		 */
-		if (p->start > end)
+		if (!resource_overlaps(p, &mem))
 			continue;
-		if (p->end < addr)
-			continue;
-		if (PFN_DOWN(p->start) <= PFN_DOWN(addr) &&
-		    PFN_DOWN(p->end) >= PFN_DOWN(end))
+		if (PFN_DOWN(p->start) <= PFN_DOWN(mem.start) &&
+		    PFN_DOWN(p->end) >= PFN_DOWN(mem.end))
 			continue;
 		/*
 		 * if a resource is "BUSY", it's not a hardware resource
@@ -1859,8 +1857,8 @@ int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
 		if (p->flags & IORESOURCE_BUSY)
 			continue;
 
-		pr_debug("resource sanity check: requesting [mem %pa-%pa], which spans more than %s %pR\n",
-			&addr, &end, p->name, p);
+		pr_debug("resource sanity check: requesting %pR, which spans more than %s %pR\n",
+			 &mem, p->name, p);
 		err = -1;
 		break;
 	}
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · Andy Shevchenko

In iomem_map_sanity_check() a piece of code resembles the content of the resource_overlaps(). Replace open coded piece with the call to the existing helper.

---
kernel/resource.c | 14 ++++++--------

1 file changed, 6 insertions(+), 8 deletions(-)
kernel/resource.c +4 -6
index 54d7199695fb..cfc1a00e86aa 100644
@@ -1833,7 +1833,7 @@ __setup("reserve=", reserve_setup);
 */
 int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
 {
-	resource_size_t end = addr + size - 1;
+	struct resource mem = DEFINE_RES_MEM(addr, size);
 	struct resource *p;
 	int err = 0;
 
@@ -1843,12 +1843,10 @@ int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
 		 * We can probably skip the resources without
 		 * IORESOURCE_IO attribute?
 		 */
-		if (p->start > end)
+		if (!resource_overlaps(p, &mem))
 			continue;
-		if (p->end < addr)
-			continue;
-		if (PFN_DOWN(p->start) <= PFN_DOWN(addr) &&
-		    PFN_DOWN(p->end) >= PFN_DOWN(end))
+		if (PFN_DOWN(p->start) <= PFN_DOWN(mem.start) &&
+		    PFN_DOWN(p->end) >= PFN_DOWN(mem.end))
 			continue;
 		/*
 		 * if a resource is "BUSY", it's not a hardware resource

kernel/resource.c int iomem_map_sanity_check(resource_size_t addr, unsigned long size) · line 1861

Quoted 7 lines
kernel/resource.c +2 -2
@@ -1859,8 +1857,8 @@ int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
 		if (p->flags & IORESOURCE_BUSY)
 			continue;
 
-		pr_debug("resource sanity check: requesting [mem %pa-%pa], which spans more than %s %pR\n",
-			&addr, &end, p->name, p);
+		pr_debug("resource sanity check: requesting %pR, which spans more than %s %pR\n",
+			 &mem, p->name, p);

This swap is not mentioned in the changelog and it does change the output a bit: %pa prints 0x1000, %pR pads the numbers to 10 hex digits, so the debug line gains a bunch of zeros. Debug only, so I don't care much, but a line in the changelog saying the print changed with it would be good?

Other than that, LGTM

kernel/resource.c int iomem_map_sanity_check(resource_size_t addr, unsigned long size) · line 1864

Quoted 4 lines
kernel/resource.c +0 -0
 		err = -1;
 		break;
 	}

--- Thanks!
https://lore.kernel.org/all/[email protected]/

#2 lore raw
Quoted 2 lines · Bradley Morgan

On 15 September 2026 09:53:53 BST, Andy Shevchenko <[email protected]> wrote:

...

Quoted 8 lines

kernel/resource.c int iomem_map_sanity_check(resource_size_t addr, unsigned long size) · line 1861

Quoted 2 lines
kernel/resource.c +2 -0
+		pr_debug("resource sanity check: requesting %pR, which spans more than %s %pR\n",
+			 &mem, p->name, p);

This swap is not mentioned in the changelog and it does change the output a bit: %pa prints 0x1000, %pR pads the numbers to 10 hex digits, so the debug line gains a bunch of zeros. Debug only, so I don't care much, but a line in the changelog saying the print changed with it would be good?

Sure, Will do in v2.

Quoted 3 lines

Other than that, LGTM

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Bradley Morgan

On 15 September 2026 09:53:53 BST, Andy Shevchenko <[email protected]> wrote:

...

Quoted 10 lines
Quoted 8 lines

kernel/resource.c int iomem_map_sanity_check(resource_size_t addr, unsigned long size) · line 1861

Quoted 2 lines
kernel/resource.c +2 -0
+		pr_debug("resource sanity check: requesting %pR, which spans more than %s %pR\n",
+			 &mem, p->name, p);

This swap is not mentioned in the changelog and it does change the output a bit: %pa prints 0x1000, %pR pads the numbers to 10 hex digits, so the debug line gains a bunch of zeros. Debug only, so I don't care much, but a line in the changelog saying the print changed with it would be good?

Sure, Will do in v2.

Andrew already applied that, but if you can suggest the text, he might amend it there. In any case it's not a big deal, I think.

Signature · 2 lines
With Best Regards,
Andy Shevchenko