Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c388919 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven
Browse files

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: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
parent 88efd0bb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+21 −0
Original line number Diff line number Diff line
@@ -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())