[PATCH v2 1/3] resource: Introduce a new helper resource_contains_addr()

From: Li Ming
Date: Wed Jul 02 2025 - 03:21:42 EST


In CXL subsystem, many functions need to check an address availability
by checking if the resource range contains the address. Providing a new
helper function resource_contains_addr() to check if the resource range
contains the input address.

Suggested-by: Alison Schofield <alison.schofield@xxxxxxxxx>
Signed-off-by: Li Ming <ming.li@xxxxxxxxxxxx>
---
v2:
* Implement a general helper resource_contains_addr(). (Alison)

base-commit: 0a46f60a9fe16f5596b6b4b3ee1a483ea7854136 cxl/fixes
---
include/linux/ioport.h | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index e8b2d6aa4013..75f5e9ccd549 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -308,6 +308,14 @@ static inline bool resource_contains(const struct resource *r1, const struct res
return r1->start <= r2->start && r1->end >= r2->end;
}

+/* True if res contains addr */
+static inline bool resource_contains_addr(const struct resource *res, const resource_size_t addr)
+{
+ if (res->flags & IORESOURCE_UNSET)
+ return false;
+ return res->start <= addr && addr <= res->end;
+}
+
/* True if any part of r1 overlaps r2 */
static inline bool resource_overlaps(const struct resource *r1, const struct resource *r2)
{
--
2.34.1