Skip to content

Commit 1c38891

Browse files
committed
resources: Add lookup_resource()
Add a function to find an existing resource by a resource start address. This allows to implement simple allocators (with a malloc/free-alike API) on top of the resource system. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
1 parent 88efd0b commit 1c38891

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎include/linux/ioport.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ extern int allocate_resource(struct resource *root, struct resource *new,
132132
resource_size_t,
133133
resource_size_t),
134134
void *alignf_data);
135+
struct resource *lookup_resource(struct resource *root, resource_size_t start);
135136
int adjust_resource(struct resource *res, resource_size_t start,
136137
resource_size_t size);
137138
resource_size_t resource_alignment(struct resource *res);

‎kernel/resource.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,27 @@ int allocate_resource(struct resource *root, struct resource *new,
553553

554554
EXPORT_SYMBOL(allocate_resource);
555555

556+
/**
557+
* lookup_resource - find an existing resource by a resource start address
558+
* @root: root resource descriptor
559+
* @start: resource start address
560+
*
561+
* Returns a pointer to the resource if found, NULL otherwise
562+
*/
563+
struct resource *lookup_resource(struct resource *root, resource_size_t start)
564+
{
565+
struct resource *res;
566+
567+
read_lock(&resource_lock);
568+
for (res = root->child; res; res = res->sibling) {
569+
if (res->start == start)
570+
break;
571+
}
572+
read_unlock(&resource_lock);
573+
574+
return res;
575+
}
576+
556577
/*
557578
* Insert a resource into the resource tree. If successful, return NULL,
558579
* otherwise return the conflicting resource (compare to __request_resource())

0 commit comments

Comments
 (0)