Commit 18d7f891 authored by David Fries's avatar David Fries Committed by Greg Kroah-Hartman

w1: avoid recursive device_add

__w1_attach_slave_device calls device_add which calls w1_bus_notify
which calls the w1_bq27000 slave driver, which calls
platform_device_add and device_add and deadlocks on getting
&(&priv->bus_notifier)->rwsem as it is still held in the previous
device_add.  This avoids the problem by processing the family
add/remove outside of the slave device_add call.

Commit 47eba33a introduced this deadlock and added
a KOBJ_ADD, as the add was already reported in device_register two add
events were being sent.  This change suppresses the device_register
add so that any slave device sysfs entries are setup before the add
goes out.

Belisko Marek reported this change fixed the deadlock he was seeing on
ARM device tree, while testing on my x86-64 system never saw the
deadlock.
Reported-by: default avatarBelisko Marek <marek.belisko@gmail.com>
Signed-off-by: default avatarDavid Fries <David@Fries.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 593ceb0c
...@@ -614,27 +614,11 @@ static int w1_uevent(struct device *dev, struct kobj_uevent_env *env) ...@@ -614,27 +614,11 @@ static int w1_uevent(struct device *dev, struct kobj_uevent_env *env)
return err; return err;
} }
/* static int w1_family_notify(unsigned long action, struct w1_slave *sl)
* Handle sysfs file creation and removal here, before userspace is told that
* the device is added / removed from the system
*/
static int w1_bus_notify(struct notifier_block *nb, unsigned long action,
void *data)
{ {
struct device *dev = data;
struct w1_slave *sl;
struct w1_family_ops *fops; struct w1_family_ops *fops;
int err; int err;
/*
* Only care about slave devices at the moment. Yes, we should use a
* separate "type" for this, but for now, look at the release function
* to know which type it is...
*/
if (dev->release != w1_slave_release)
return 0;
sl = dev_to_w1_slave(dev);
fops = sl->family->fops; fops = sl->family->fops;
if (!fops) if (!fops)
...@@ -673,10 +657,6 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action, ...@@ -673,10 +657,6 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action,
return 0; return 0;
} }
static struct notifier_block w1_bus_nb = {
.notifier_call = w1_bus_notify,
};
static int __w1_attach_slave_device(struct w1_slave *sl) static int __w1_attach_slave_device(struct w1_slave *sl)
{ {
int err; int err;
...@@ -698,6 +678,9 @@ static int __w1_attach_slave_device(struct w1_slave *sl) ...@@ -698,6 +678,9 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
dev_dbg(&sl->dev, "%s: registering %s as %p.\n", __func__, dev_dbg(&sl->dev, "%s: registering %s as %p.\n", __func__,
dev_name(&sl->dev), sl); dev_name(&sl->dev), sl);
/* suppress for w1_family_notify before sending KOBJ_ADD */
dev_set_uevent_suppress(&sl->dev, true);
err = device_register(&sl->dev); err = device_register(&sl->dev);
if (err < 0) { if (err < 0) {
dev_err(&sl->dev, dev_err(&sl->dev,
...@@ -705,7 +688,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl) ...@@ -705,7 +688,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
dev_name(&sl->dev), err); dev_name(&sl->dev), err);
return err; return err;
} }
w1_family_notify(BUS_NOTIFY_ADD_DEVICE, sl);
dev_set_uevent_suppress(&sl->dev, false); dev_set_uevent_suppress(&sl->dev, false);
kobject_uevent(&sl->dev.kobj, KOBJ_ADD); kobject_uevent(&sl->dev.kobj, KOBJ_ADD);
...@@ -799,6 +782,7 @@ int w1_unref_slave(struct w1_slave *sl) ...@@ -799,6 +782,7 @@ int w1_unref_slave(struct w1_slave *sl)
msg.type = W1_SLAVE_REMOVE; msg.type = W1_SLAVE_REMOVE;
w1_netlink_send(sl->master, &msg); w1_netlink_send(sl->master, &msg);
w1_family_notify(BUS_NOTIFY_DEL_DEVICE, sl);
device_unregister(&sl->dev); device_unregister(&sl->dev);
#ifdef DEBUG #ifdef DEBUG
memset(sl, 0, sizeof(*sl)); memset(sl, 0, sizeof(*sl));
...@@ -1186,10 +1170,6 @@ static int __init w1_init(void) ...@@ -1186,10 +1170,6 @@ static int __init w1_init(void)
goto err_out_exit_init; goto err_out_exit_init;
} }
retval = bus_register_notifier(&w1_bus_type, &w1_bus_nb);
if (retval)
goto err_out_bus_unregister;
retval = driver_register(&w1_master_driver); retval = driver_register(&w1_master_driver);
if (retval) { if (retval) {
printk(KERN_ERR printk(KERN_ERR
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment