From: Geert Uytterhoeven <geert@linux-m68k.org>
To: linux-kernel@vger.kernel.org, sparclinux@vger.kernel.org,
linux-m68k@lists.linux-m68k.org
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH 2/4] resources: Add lookup_resource()
Date: Sat, 21 May 2011 21:39:14 +0200 [thread overview]
Message-ID: <1306006756-32009-3-git-send-email-geert@linux-m68k.org> (raw)
In-Reply-To: <1306006756-32009-1-git-send-email-geert@linux-m68k.org>
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 | 1 +
kernel/resource.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index e9bb22c..63eb429 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -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);
diff --git a/kernel/resource.c b/kernel/resource.c
index 798e2fa..8d0b479 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -473,6 +473,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())
--
1.7.0.4
next prev parent reply other threads:[~2011-05-21 19:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1306006756-32009-1-git-send-email-geert@linux-m68k.org>
2011-05-21 19:39 ` [PATCH 1/4] sparc: _sparc_find_resource() should check for exact matches Geert Uytterhoeven
2011-05-21 19:39 ` Geert Uytterhoeven [this message]
2011-05-21 19:39 ` [PATCH 3/4] m68k/amiga: Chip RAM - Use lookup_resource() Geert Uytterhoeven
2011-05-21 19:39 ` [PATCH 4/4] sparc: iounmap() and *_free_coherent() " Geert Uytterhoeven
2011-05-23 6:46 ` David Miller
[not found] ` <1306006756-32009-2-git-send-email-geert@linux-m68k.org>
2011-05-23 6:45 ` [PATCH 1/4] sparc: _sparc_find_resource() should check for exact matches David Miller
2011-05-31 7:47 ` [PATCH 0/4] resources: Add lookup_resource() Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1306006756-32009-3-git-send-email-geert@linux-m68k.org \
--to=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox