]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
resources: Add lookup_resource()
authorGeert Uytterhoeven <geert@linux-m68k.org>
Sat, 7 May 2011 18:53:16 +0000 (20:53 +0200)
committerGeert Uytterhoeven <geert@linux-m68k.org>
Sat, 30 Jul 2011 19:21:39 +0000 (21:21 +0200)
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>
include/linux/ioport.h
kernel/resource.c

index e9bb22cba764139cc69f3faa1e16f11cc0e05eb2..63eb429ecbe6c4d51a8aa9770e5bef4fe442a5af 100644 (file)
@@ -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);
index 3ff40178dce77d21fdd1ec508fc2baab5e87db84..3b3cedc52592164e11689375c4bb7d054df293cf 100644 (file)
@@ -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())