Commit d486ccb2 authored by Alistair Popple's avatar Alistair Popple Committed by Linus Torvalds

kernel/resource: allow region_intersects users to hold resource_lock

Introduce a version of region_intersects() that can be called with the
resource_lock already held.

This will be used in a future fix to __request_free_mem_region().

[akpm@linux-foundation.org: make __region_intersects static]

Link: https://lkml.kernel.org/r/20210419070109.4780-1-apopple@nvidia.comSigned-off-by: default avatarAlistair Popple <apopple@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Muchun Song <smuchun@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 97523a4e
...@@ -502,6 +502,34 @@ int __weak page_is_ram(unsigned long pfn) ...@@ -502,6 +502,34 @@ int __weak page_is_ram(unsigned long pfn)
} }
EXPORT_SYMBOL_GPL(page_is_ram); EXPORT_SYMBOL_GPL(page_is_ram);
static int __region_intersects(resource_size_t start, size_t size,
unsigned long flags, unsigned long desc)
{
struct resource res;
int type = 0; int other = 0;
struct resource *p;
res.start = start;
res.end = start + size - 1;
for (p = iomem_resource.child; p ; p = p->sibling) {
bool is_type = (((p->flags & flags) == flags) &&
((desc == IORES_DESC_NONE) ||
(desc == p->desc)));
if (resource_overlaps(p, &res))
is_type ? type++ : other++;
}
if (type == 0)
return REGION_DISJOINT;
if (other == 0)
return REGION_INTERSECTS;
return REGION_MIXED;
}
/** /**
* region_intersects() - determine intersection of region with known resources * region_intersects() - determine intersection of region with known resources
* @start: region start address * @start: region start address
...@@ -525,31 +553,13 @@ EXPORT_SYMBOL_GPL(page_is_ram); ...@@ -525,31 +553,13 @@ EXPORT_SYMBOL_GPL(page_is_ram);
int region_intersects(resource_size_t start, size_t size, unsigned long flags, int region_intersects(resource_size_t start, size_t size, unsigned long flags,
unsigned long desc) unsigned long desc)
{ {
struct resource res; int ret;
int type = 0; int other = 0;
struct resource *p;
res.start = start;
res.end = start + size - 1;
read_lock(&resource_lock); read_lock(&resource_lock);
for (p = iomem_resource.child; p ; p = p->sibling) { ret = __region_intersects(start, size, flags, desc);
bool is_type = (((p->flags & flags) == flags) &&
((desc == IORES_DESC_NONE) ||
(desc == p->desc)));
if (resource_overlaps(p, &res))
is_type ? type++ : other++;
}
read_unlock(&resource_lock); read_unlock(&resource_lock);
if (type == 0) return ret;
return REGION_DISJOINT;
if (other == 0)
return REGION_INTERSECTS;
return REGION_MIXED;
} }
EXPORT_SYMBOL_GPL(region_intersects); EXPORT_SYMBOL_GPL(region_intersects);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment