From: Mike Chan <mike@android.com>
To: linux-omap@vger.kernel.org
Cc: khilman@deeprootsystems.com, Mike Chan <mike@android.com>
Subject: [PATCH] omap: resource: Fix race in register_resource()
Date: Thu, 3 Sep 2009 12:37:18 -0700 [thread overview]
Message-ID: <1252006638-1697-1-git-send-email-mike@android.com> (raw)
Checking if the resource is already registered and adding to the list
must be atomic or bad things can happen.
Signed-off-by: Mike Chan <mike@android.com>
---
arch/arm/plat-omap/resource.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c
index e9ace13..9d20249 100644
--- a/arch/arm/plat-omap/resource.c
+++ b/arch/arm/plat-omap/resource.c
@@ -253,6 +253,7 @@ int resource_refresh(void)
*/
int resource_register(struct shared_resource *resp)
{
+ int ret = 0;
if (!resp)
return -EINVAL;
@@ -260,13 +261,15 @@ int resource_register(struct shared_resource *resp)
return -EINVAL;
/* Verify that the resource is not already registered */
- if (resource_lookup(resp->name))
- return -EEXIST;
+ down(&res_mutex);
+ if (_resource_lookup(resp->name)) {
+ ret = -EEXIST;
+ goto out;
+ }
INIT_LIST_HEAD(&resp->users_list);
mutex_init(&resp->resource_mutex);
- down(&res_mutex);
/* Add the resource to the resource list */
list_add(&resp->node, &res_list);
@@ -274,10 +277,11 @@ int resource_register(struct shared_resource *resp)
if (resp->ops->init)
resp->ops->init(resp);
- up(&res_mutex);
pr_debug("resource: registered %s\n", resp->name);
- return 0;
+out:
+ up(&res_mutex);
+ return ret;
}
EXPORT_SYMBOL(resource_register);
--
1.5.4.5
next reply other threads:[~2009-09-03 19:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-03 19:37 Mike Chan [this message]
2009-09-08 22:39 ` [PATCH] omap: resource: Fix race in register_resource() Kevin Hilman
2009-09-08 23:55 ` Mike Chan
2009-09-17 23:32 Mike Chan
2009-09-17 23:41 ` Mike Chan
2009-09-30 16:44 ` Kevin Hilman
2009-09-30 23:49 ` Kevin Hilman
2009-09-30 23:58 ` Mike Chan
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=1252006638-1697-1-git-send-email-mike@android.com \
--to=mike@android.com \
--cc=khilman@deeprootsystems.com \
--cc=linux-omap@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.