Message ID | 1253230331-701-1-git-send-email-mike@android.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Kevin Hilman |
Headers | show |
On Thu, Sep 17, 2009 at 4:32 PM, Mike Chan <mike@android.com> wrote: > 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 | Â 13 ++++++++----- > Â 1 files changed, 8 insertions(+), 5 deletions(-) > > diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c > index 111020a..4631912 100644 > --- a/arch/arm/plat-omap/resource.c > +++ b/arch/arm/plat-omap/resource.c > @@ -255,6 +255,7 @@ int resource_refresh(void) > Â */ > Â int resource_register(struct shared_resource *resp) > Â { > + Â Â Â int ret = 0; > Â Â Â Â if (!resp) > Â Â Â Â Â Â Â Â return -EINVAL; > > @@ -262,12 +263,13 @@ 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); > > - Â Â Â down(&res_mutex); > Â Â Â Â /* Add the resource to the resource list */ > Â Â Â Â list_add(&resp->node, &res_list); > > @@ -275,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 > > Kevin, this should be based off of your pm branch (2.6.30?) -- Mike -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c index 111020a..4631912 100644 --- a/arch/arm/plat-omap/resource.c +++ b/arch/arm/plat-omap/resource.c @@ -255,6 +255,7 @@ int resource_refresh(void) */ int resource_register(struct shared_resource *resp) { + int ret = 0; if (!resp) return -EINVAL; @@ -262,12 +263,13 @@ 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); - down(&res_mutex); /* Add the resource to the resource list */ list_add(&resp->node, &res_list); @@ -275,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);
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 | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)