mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
To: EunTaik Lee <eun.taik.lee@samsung.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fix race condition between device_del and device_add
Date: Mon, 30 Mar 2015 12:04:11 +0200	[thread overview]
Message-ID: <20150330100411.GB15916@kroah.com> (raw)
In-Reply-To: <4A.CC.15273.32219155@epcpsbgx1.samsung.com>

On Mon, Mar 30, 2015 at 09:06:43AM +0000, EunTaik Lee wrote:
> There is a possible race condition when a device
> is added while another device with the same parent
> , with ref count of one, is deleted.
> 
>  CPU0    CPU1
> device_add()   device_del()
>   get_device_parent()     put_device(parent);
>     kobj = kobject_get(k);     kobject_put()
>           kref_put()
>        refcount=0
>       refcount is 0
>       WARNS it was 0 but
>       return kobj            frees kobj
> uses the freed parent kobj
> 
> The race condition exists because kref_put() and the
> release function is not atomic.
> Using kobject_get_unless_zero() instead of
> kobject_get() in get_device_parent() will prevent
> this race condition.

The bus that the device is on should prevent this, why isn't that
working for you?  What type of device/bus do you see this problem on?

> Signed-off-by: eun.taik.lee <eun.taik.lee@samsung.com>

We need a "real" name here, I don't think your name has '.' in it,
right?

> ---
>  drivers/base/core.c     |    2 +-
>  include/linux/kobject.h |    2 ++
>  lib/kobject.c           |    2 +-
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 07304a3..ec2f211 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -761,7 +761,7 @@ static struct kobject *get_device_parent(struct device
> *dev,
>    spin_lock(&dev->class->p->glue_dirs.list_lock);
>    list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry)
>     if (k->parent == parent_kobj) {
> -    kobj = kobject_get(k);
> +    kobj = kobject_get_unless_zero(k);
>      break;

Your email client turned all tabs to spaces and made the patch unable to
be applied.

thanks,

greg k-h

           reply	other threads:[~2015-03-30 10:04 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <4A.CC.15273.32219155@epcpsbgx1.samsung.com>]

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=20150330100411.GB15916@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=eun.taik.lee@samsung.com \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®