summaryrefslogtreecommitdiffstats
path: root/kernel/resource.c
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert@linux-m68k.org>2011-05-07 20:53:16 +0200
committerGeert Uytterhoeven <geert@linux-m68k.org>2011-07-30 21:21:39 +0200
commit1c388919d89ca35741e9c4d3255adf87f76f0c06 (patch)
tree3858d97ce2f91cdf6ec3badafbf66ef058e178a7 /kernel/resource.c
parent88efd0bbc0fe403a9948e6f94cc48b9f15ee4861 (diff)
downloadlinux-stable-1c388919d89ca35741e9c4d3255adf87f76f0c06.tar.gz
linux-stable-1c388919d89ca35741e9c4d3255adf87f76f0c06.tar.bz2
linux-stable-1c388919d89ca35741e9c4d3255adf87f76f0c06.zip
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>
Diffstat (limited to 'kernel/resource.c')
-rw-r--r--kernel/resource.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel/resource.c b/kernel/resource.c
index 3ff40178dce7..3b3cedc52592 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -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())