All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@deeprootsystems.com>
To: Mike Chan <mike@android.com>
Cc: linux-omap@vger.kernel.org
Subject: Re: [PATCH] omap: resource: Fix race in register_resource()
Date: Tue, 08 Sep 2009 15:39:05 -0700	[thread overview]
Message-ID: <87k509kqnq.fsf@deeprootsystems.com> (raw)
In-Reply-To: <1252006638-1697-1-git-send-email-mike@android.com> (Mike Chan's message of "Thu\,  3 Sep 2009 12\:37\:18 -0700")

Mike Chan <mike@android.com> writes:

> 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>

Functionally, this looks fine.  Some procedural details still to work
out:

Are you the original author of this?  or was it Chunqiu or Limei?  The
changelog should be prefixed with a From: line of the original author
(handled by git-format-patch) if it was not you.  Also add the other's
signoffs if appropriate.

What tree does this apply to?  It's not specified, and does not apply
to either current PM branch or pm-2.6.29. 

Kevin

> ---
>  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

  reply	other threads:[~2009-09-08 22:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-03 19:37 [PATCH] omap: resource: Fix race in register_resource() Mike Chan
2009-09-08 22:39 ` Kevin Hilman [this message]
2009-09-08 23:55   ` Mike Chan
  -- strict thread matches above, loose matches on Subject: below --
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=87k509kqnq.fsf@deeprootsystems.com \
    --to=khilman@deeprootsystems.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=mike@android.com \
    /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.