RE: [PATCH v2 1/3] resource: Introduce a new helper resource_contains_addr()
From: Shiju Jose
Date: Thu Jul 03 2025 - 05:53:10 EST
>-----Original Message-----
>From: Li Ming <ming.li@xxxxxxxxxxxx>
>Sent: 02 July 2025 08:20
>To: akpm@xxxxxxxxxxxxxxxxxxxx; andriy.shevchenko@xxxxxxxxxxxxxxx;
>bhelgaas@xxxxxxxxxx; ilpo.jarvinen@xxxxxxxxxxxxxxx; dave@xxxxxxxxxxxx;
>Jonathan Cameron <jonathan.cameron@xxxxxxxxxx>; dave.jiang@xxxxxxxxx;
>alison.schofield@xxxxxxxxx; vishal.l.verma@xxxxxxxxx; ira.weiny@xxxxxxxxx;
>dan.j.williams@xxxxxxxxx; Shiju Jose <shiju.jose@xxxxxxxxxx>
>Cc: linux-cxl@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Li Ming
><ming.li@xxxxxxxxxxxx>
>Subject: [PATCH v2 1/3] resource: Introduce a new helper
>resource_contains_addr()
>
>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>
Tested-by: Shiju Jose <shiju.jose@xxxxxxxxxx>
>---
>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