Commit ed9f9181 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

driver core: bus: move bus notifier logic into bus.c

The logic to touch the bus notifier was open-coded in numberous places
in the driver core.  Clean that up by creating a local bus_notify()
function and have everyone call this function instead, making the
reading of the caller code simpler and easier to maintain over time.
Reviewed-by: default avatarRafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230111092331.3946745-2-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 504450d0
...@@ -130,6 +130,7 @@ struct kobject *virtual_device_parent(struct device *dev); ...@@ -130,6 +130,7 @@ struct kobject *virtual_device_parent(struct device *dev);
extern int bus_add_device(struct device *dev); extern int bus_add_device(struct device *dev);
extern void bus_probe_device(struct device *dev); extern void bus_probe_device(struct device *dev);
extern void bus_remove_device(struct device *dev); extern void bus_remove_device(struct device *dev);
void bus_notify(struct device *dev, enum bus_notifier_event value);
extern int bus_add_driver(struct device_driver *drv); extern int bus_add_driver(struct device_driver *drv);
extern void bus_remove_driver(struct device_driver *drv); extern void bus_remove_driver(struct device_driver *drv);
......
...@@ -850,6 +850,14 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) ...@@ -850,6 +850,14 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb)
} }
EXPORT_SYMBOL_GPL(bus_unregister_notifier); EXPORT_SYMBOL_GPL(bus_unregister_notifier);
void bus_notify(struct device *dev, enum bus_notifier_event value)
{
struct bus_type *bus = dev->bus;
if (bus)
blocking_notifier_call_chain(&bus->p->bus_notifier, value, dev);
}
struct kset *bus_get_kset(struct bus_type *bus) struct kset *bus_get_kset(struct bus_type *bus)
{ {
return &bus->p->subsys; return &bus->p->subsys;
......
...@@ -3453,10 +3453,7 @@ int device_add(struct device *dev) ...@@ -3453,10 +3453,7 @@ int device_add(struct device *dev)
/* Notify clients of device addition. This call must come /* Notify clients of device addition. This call must come
* after dpm_sysfs_add() and before kobject_uevent(). * after dpm_sysfs_add() and before kobject_uevent().
*/ */
if (dev->bus) bus_notify(dev, BUS_NOTIFY_ADD_DEVICE);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_ADD_DEVICE, dev);
kobject_uevent(&dev->kobj, KOBJ_ADD); kobject_uevent(&dev->kobj, KOBJ_ADD);
/* /*
...@@ -3637,9 +3634,7 @@ void device_del(struct device *dev) ...@@ -3637,9 +3634,7 @@ void device_del(struct device *dev)
* before dpm_sysfs_remove(). * before dpm_sysfs_remove().
*/ */
noio_flag = memalloc_noio_save(); noio_flag = memalloc_noio_save();
if (dev->bus) bus_notify(dev, BUS_NOTIFY_DEL_DEVICE);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev);
dpm_sysfs_remove(dev); dpm_sysfs_remove(dev);
if (parent) if (parent)
...@@ -3670,9 +3665,7 @@ void device_del(struct device *dev) ...@@ -3670,9 +3665,7 @@ void device_del(struct device *dev)
device_platform_notify_remove(dev); device_platform_notify_remove(dev);
device_links_purge(dev); device_links_purge(dev);
if (dev->bus) bus_notify(dev, BUS_NOTIFY_REMOVED_DEVICE);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_REMOVED_DEVICE, dev);
kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_uevent(&dev->kobj, KOBJ_REMOVE);
glue_dir = get_glue_dir(dev); glue_dir = get_glue_dir(dev);
kobject_del(&dev->kobj); kobject_del(&dev->kobj);
......
...@@ -411,10 +411,7 @@ static void driver_bound(struct device *dev) ...@@ -411,10 +411,7 @@ static void driver_bound(struct device *dev)
driver_deferred_probe_del(dev); driver_deferred_probe_del(dev);
driver_deferred_probe_trigger(); driver_deferred_probe_trigger();
if (dev->bus) bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_BOUND_DRIVER, dev);
kobject_uevent(&dev->kobj, KOBJ_BIND); kobject_uevent(&dev->kobj, KOBJ_BIND);
} }
...@@ -433,9 +430,7 @@ static int driver_sysfs_add(struct device *dev) ...@@ -433,9 +430,7 @@ static int driver_sysfs_add(struct device *dev)
{ {
int ret; int ret;
if (dev->bus) bus_notify(dev, BUS_NOTIFY_BIND_DRIVER);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_BIND_DRIVER, dev);
ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
kobject_name(&dev->kobj)); kobject_name(&dev->kobj));
...@@ -500,9 +495,8 @@ int device_bind_driver(struct device *dev) ...@@ -500,9 +495,8 @@ int device_bind_driver(struct device *dev)
device_links_force_bind(dev); device_links_force_bind(dev);
driver_bound(dev); driver_bound(dev);
} }
else if (dev->bus) else
blocking_notifier_call_chain(&dev->bus->p->bus_notifier, bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(device_bind_driver); EXPORT_SYMBOL_GPL(device_bind_driver);
...@@ -693,9 +687,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) ...@@ -693,9 +687,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
probe_failed: probe_failed:
driver_sysfs_remove(dev); driver_sysfs_remove(dev);
sysfs_failed: sysfs_failed:
if (dev->bus) bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
if (dev->bus && dev->bus->dma_cleanup) if (dev->bus && dev->bus->dma_cleanup)
dev->bus->dma_cleanup(dev); dev->bus->dma_cleanup(dev);
pinctrl_bind_failed: pinctrl_bind_failed:
...@@ -1241,10 +1233,7 @@ static void __device_release_driver(struct device *dev, struct device *parent) ...@@ -1241,10 +1233,7 @@ static void __device_release_driver(struct device *dev, struct device *parent)
driver_sysfs_remove(dev); driver_sysfs_remove(dev);
if (dev->bus) bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER);
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_UNBIND_DRIVER,
dev);
pm_runtime_put_sync(dev); pm_runtime_put_sync(dev);
...@@ -1258,11 +1247,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) ...@@ -1258,11 +1247,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
klist_remove(&dev->p->knode_driver); klist_remove(&dev->p->knode_driver);
device_pm_check_callbacks(dev); device_pm_check_callbacks(dev);
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_UNBOUND_DRIVER,
dev);
bus_notify(dev, BUS_NOTIFY_UNBOUND_DRIVER);
kobject_uevent(&dev->kobj, KOBJ_UNBIND); kobject_uevent(&dev->kobj, KOBJ_UNBIND);
} }
} }
......
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