]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
resource: Add __resource_contains_unbound() for internal contains checks
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 24 Mar 2026 16:56:24 +0000 (18:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 26 Mar 2026 20:00:39 +0000 (15:00 -0500)
__find_resource_space() currently uses resource_contains() but for
tentative resources that are not yet crafted into the resource tree. As
resource_contains() checks that IORESOURCE_UNSET is not set for either of
the resources, the caller has to hack around this problem by clearing the
IORESOURCE_UNSET flag (essentially lying to resource_contains()).

Instead of the hack, introduce __resource_contains_unbound() for cases like
this.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Xifer <xiferdev@gmail.com>
Link: https://patch.msgid.link/20260324165633.4583-2-ilpo.jarvinen@linux.intel.com
include/linux/ioport.h
kernel/resource.c

index 5533a5debf3f2cfceb4051cc1c8912043fbd3652..19d5e04564d94c90900c4ed9f180b35e900ea5c1 100644 (file)
@@ -304,14 +304,28 @@ static inline unsigned long resource_ext_type(const struct resource *res)
 {
        return res->flags & IORESOURCE_EXT_TYPE_BITS;
 }
-/* True iff r1 completely contains r2 */
-static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
+
+/*
+ * For checking if @r1 completely contains @r2 for resources that have real
+ * addresses but are not yet crafted into the resource tree. Normally
+ * resource_contains() should be used instead of this function as it checks
+ * also IORESOURCE_UNSET flag.
+ */
+static inline bool __resource_contains_unbound(const struct resource *r1,
+                                              const struct resource *r2)
 {
        if (resource_type(r1) != resource_type(r2))
                return false;
+
+       return r1->start <= r2->start && r1->end >= r2->end;
+}
+/* True iff r1 completely contains r2 */
+static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
+{
        if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
                return false;
-       return r1->start <= r2->start && r1->end >= r2->end;
+
+       return __resource_contains_unbound(r1, r2);
 }
 
 /* True if any part of r1 overlaps r2 */
index bb966699da31dc7b9bcbb4045e55cce93b5c464d..1e2f1dfc0eddad571b68364d3be1a8f63e6d8572 100644 (file)
@@ -754,7 +754,7 @@ static int __find_resource_space(struct resource *root, struct resource *old,
                /* Check for overflow after ALIGN() */
                avail.start = ALIGN(tmp.start, constraint->align);
                avail.end = tmp.end;
-               avail.flags = new->flags & ~IORESOURCE_UNSET;
+               avail.flags = new->flags;
                if (avail.start >= tmp.start) {
                        alloc.flags = avail.flags;
                        if (alignf) {
@@ -765,7 +765,7 @@ static int __find_resource_space(struct resource *root, struct resource *old,
                        }
                        alloc.end = alloc.start + size - 1;
                        if (alloc.start <= alloc.end &&
-                           resource_contains(&avail, &alloc)) {
+                           __resource_contains_unbound(&avail, &alloc)) {
                                new->start = alloc.start;
                                new->end = alloc.end;
                                return 0;