fix race condition between device_del and device_add
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 15 lines · EunTaik Lee
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
Quoted 5 lines
The race condition exists because
kref_put()and the release function is not atomic.
Usingkobject_get_unless_zero()instead ofkobject_get()inget_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?
Quoted 1 line
Signed-off-by eun.taik.lee <[email protected]>
We need a "real" name here, I don't think your name has '.' in it, right?
Quoted 11 lines
--- drivers/base/core.c | 2 +- include/linux/kobject.h | 2 ++ lib/kobject.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)drivers/base/core.c +0
-0
drivers/base/core.c static struct kobject *get_device_parent(struct device · line 766
Quoted 7 lines
drivers/base/core.c +1
-1@@ -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