History

resource: Add __resource_contains_unbound() for internal contains checks

__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.

Ilpo Järvinen committed 7 months ago

Commit edfaa811 parent 1ee47162 files · +19 −5Browse files

Unified · Split

2 files
  1. include/linux/ioport.h +17 −3
  2. kernel/resource.c +2 −2
include/linux/ioport.h+17−3
@@ -304,14 +304,28 @@ static inline unsigned long resource_ext_type(const struct resource *res) · 303 unmodified lines
304304 {
305305 return res->flags & IORESOURCE_EXT_TYPE_BITS;
306306 }
307−/* True iff r1 completely contains r2 */
308−static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
307+
308+/*
309+ * For checking if @r1 completely contains @r2 for resources that have real
310+ * addresses but are not yet crafted into the resource tree. Normally
311+ * resource_contains() should be used instead of this function as it checks
312+ * also IORESOURCE_UNSET flag.
313+ */
314+static inline bool __resource_contains_unbound(const struct resource *r1,
315+ const struct resource *r2)
309316 {
310317 if (resource_type(r1) != resource_type(r2))
311318 return false;
319+
320+ return r1->start <= r2->start && r1->end >= r2->end;
321+}
322+/* True iff r1 completely contains r2 */
323+static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
324+{
312325 if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
313326 return false;
314− return r1->start <= r2->start && r1->end >= r2->end;
327+
328+ return __resource_contains_unbound(r1, r2);
315329 }
316330
317331 /* True if any part of r1 overlaps r2 */
kernel/resource.c+2−2
@@ -754,7 +754,7 @@ static int __find_resource_space(struct resource *root, struct resource *old, · 753 unmodified lines
754754 /* Check for overflow after ALIGN() */
755755 avail.start = ALIGN(tmp.start, constraint->align);
756756 avail.end = tmp.end;
757− avail.flags = new->flags & ~IORESOURCE_UNSET;
757+ avail.flags = new->flags;
758758 if (avail.start >= tmp.start) {
759759 alloc.flags = avail.flags;
760760 if (alignf) {
@@ -765,7 +765,7 @@ static int __find_resource_space(struct resource *root, struct resource *old, · 4 unmodified lines
765765 }
766766 alloc.end = alloc.start + size - 1;
767767 if (alloc.start <= alloc.end &&
768− resource_contains(&avail, &alloc)) {
768+ __resource_contains_unbound(&avail, &alloc)) {
769769 new->start = alloc.start;
770770 new->end = alloc.end;
771771 return 0;