Skip to content

Commit

Permalink
resources: Add lookup_resource()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
geertu committed Jul 30, 2011
1 parent 88efd0b commit 1c38891
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/ioport.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ extern int allocate_resource(struct resource *root, struct resource *new,
resource_size_t,
resource_size_t),
void *alignf_data);
struct resource *lookup_resource(struct resource *root, resource_size_t start);
int adjust_resource(struct resource *res, resource_size_t start,
resource_size_t size);
resource_size_t resource_alignment(struct resource *res);
Expand Down
21 changes: 21 additions & 0 deletions kernel/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,27 @@ int allocate_resource(struct resource *root, struct resource *new,

EXPORT_SYMBOL(allocate_resource);

/**
* lookup_resource - find an existing resource by a resource start address
* @root: root resource descriptor
* @start: resource start address
*
* Returns a pointer to the resource if found, NULL otherwise
*/
struct resource *lookup_resource(struct resource *root, resource_size_t start)
{
struct resource *res;

read_lock(&resource_lock);
for (res = root->child; res; res = res->sibling) {
if (res->start == start)
break;
}
read_unlock(&resource_lock);

return res;
}

/*
* Insert a resource into the resource tree. If successful, return NULL,
* otherwise return the conflicting resource (compare to __request_resource())
Expand Down

0 comments on commit 1c38891

Please sign in to comment.