* [PATCH 1/2] driver core: bus.h: document bus notifiers better @ 2023-01-10 12:42 Greg Kroah-Hartman 2023-01-10 12:42 ` [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c Greg Kroah-Hartman 2023-01-10 12:52 ` [PATCH 1/2] driver core: bus.h: document bus notifiers better Rafael J. Wysocki 0 siblings, 2 replies; 6+ messages in thread From: Greg Kroah-Hartman @ 2023-01-10 12:42 UTC (permalink / raw) To: linux-kernel; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki The bus notifier values are not documented all that well, so clean this up and make a real enumerated type for them and document them much better. Cc: "Rafael J. Wysocki" <rafael@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- include/linux/device/bus.h | 43 +++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index d529f644e92b..1e1a593348bc 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -257,21 +257,36 @@ extern int bus_register_notifier(struct bus_type *bus, extern int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb); -/* All 4 notifers below get called with the target struct device * - * as an argument. Note that those functions are likely to be called - * with the device lock held in the core, so be careful. +/** + * enum bus_notifier_event: Bus Notifier events that have happened + * + * These are the value passed to a bus notifier when a specific event happens. + * + * Note that bus notifiers are likely to be called with the device lock already + * held by the driver core, so be careful in any notifier callback as to what + * you do with the device structure. + * + * All bus notifiers are called with the target struct device * as an argument. + * + * BUS_NOTIFY_ADD_DEVICE: device is added to this bus + * BUS_NOTIFY_DEL_DEVICE: device is about to be removed from this bus + * BUS_NOTIFY_REMOVED_DEVICE: device is successfully removed from this bus + * BUS_NOTIFY_BIND_DRIVER: a driver is about to be bound to this device on this bus + * BUS_NOTIFY_BOUND_DRIVER: a driver is successfully bound to this device on this bus + * BUS_NOTIFY_UNBIND_DRIVER: a driver is about to be unbound from this device on this bus + * BUS_NOTIFY_UNBOUND_DRIVER: a driver is successfully unbound from this device on this bus + * BUS_NOTIFY_DRIVER_NOT_BOUND: a driver failed to be bound to this device on this bus */ -#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ -#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device to be removed */ -#define BUS_NOTIFY_REMOVED_DEVICE 0x00000003 /* device removed */ -#define BUS_NOTIFY_BIND_DRIVER 0x00000004 /* driver about to be - bound */ -#define BUS_NOTIFY_BOUND_DRIVER 0x00000005 /* driver bound to device */ -#define BUS_NOTIFY_UNBIND_DRIVER 0x00000006 /* driver about to be - unbound */ -#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is unbound - from the device */ -#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008 /* driver fails to be bound */ +enum bus_notifier_event { + BUS_NOTIFY_ADD_DEVICE = 0x00000001, + BUS_NOTIFY_DEL_DEVICE = 0x00000002, + BUS_NOTIFY_REMOVED_DEVICE = 0x00000003, + BUS_NOTIFY_BIND_DRIVER = 0x00000004, + BUS_NOTIFY_BOUND_DRIVER = 0x00000005, + BUS_NOTIFY_UNBIND_DRIVER = 0x00000006, + BUS_NOTIFY_UNBOUND_DRIVER = 0x00000007, + BUS_NOTIFY_DRIVER_NOT_BOUND = 0x00000008, +}; extern struct kset *bus_get_kset(struct bus_type *bus); -- 2.39.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c 2023-01-10 12:42 [PATCH 1/2] driver core: bus.h: document bus notifiers better Greg Kroah-Hartman @ 2023-01-10 12:42 ` Greg Kroah-Hartman 2023-01-10 12:55 ` Rafael J. Wysocki 2023-01-10 12:52 ` [PATCH 1/2] driver core: bus.h: document bus notifiers better Rafael J. Wysocki 1 sibling, 1 reply; 6+ messages in thread From: Greg Kroah-Hartman @ 2023-01-10 12:42 UTC (permalink / raw) To: linux-kernel; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki 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. Cc: "Rafael J. Wysocki" <rafael@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- drivers/base/base.h | 1 + drivers/base/bus.c | 8 ++++++++ drivers/base/core.c | 13 +++---------- drivers/base/dd.c | 28 +++++++--------------------- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 7d4803c03d3e..2e08258ce82e 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -130,6 +130,7 @@ struct kobject *virtual_device_parent(struct device *dev); extern int bus_add_device(struct device *dev); extern void bus_probe_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 void bus_remove_driver(struct device_driver *drv); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 428c26c6b615..cf1b8f00b4c0 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -850,6 +850,14 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) } 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) { return &bus->p->subsys; diff --git a/drivers/base/core.c b/drivers/base/core.c index a3e14143ec0c..af6a2761b31d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3453,10 +3453,7 @@ int device_add(struct device *dev) /* Notify clients of device addition. This call must come * after dpm_sysfs_add() and before kobject_uevent(). */ - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_ADD_DEVICE, dev); - + bus_notify(dev, BUS_NOTIFY_ADD_DEVICE); kobject_uevent(&dev->kobj, KOBJ_ADD); /* @@ -3636,9 +3633,7 @@ void device_del(struct device *dev) * before dpm_sysfs_remove(). */ noio_flag = memalloc_noio_save(); - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_DEL_DEVICE, dev); + bus_notify(dev, BUS_NOTIFY_DEL_DEVICE); dpm_sysfs_remove(dev); if (parent) @@ -3669,9 +3664,7 @@ void device_del(struct device *dev) device_platform_notify_remove(dev); device_links_purge(dev); - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_REMOVED_DEVICE, dev); + bus_notify(dev, BUS_NOTIFY_REMOVED_DEVICE); kobject_uevent(&dev->kobj, KOBJ_REMOVE); glue_dir = get_glue_dir(dev); kobject_del(&dev->kobj); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index e9b2f9c25efe..a519eaf1990c 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -413,10 +413,7 @@ static void driver_bound(struct device *dev) driver_deferred_probe_del(dev); driver_deferred_probe_trigger(); - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_BOUND_DRIVER, dev); - + bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER); kobject_uevent(&dev->kobj, KOBJ_BIND); } @@ -435,9 +432,7 @@ static int driver_sysfs_add(struct device *dev) { int ret; - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_BIND_DRIVER, dev); + bus_notify(dev, BUS_NOTIFY_BIND_DRIVER); ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, kobject_name(&dev->kobj)); @@ -502,9 +497,8 @@ int device_bind_driver(struct device *dev) device_links_force_bind(dev); driver_bound(dev); } - else if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_DRIVER_NOT_BOUND, dev); + else + bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); return ret; } EXPORT_SYMBOL_GPL(device_bind_driver); @@ -695,9 +689,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) probe_failed: driver_sysfs_remove(dev); sysfs_failed: - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_DRIVER_NOT_BOUND, dev); + bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); if (dev->bus && dev->bus->dma_cleanup) dev->bus->dma_cleanup(dev); pinctrl_bind_failed: @@ -1243,10 +1235,7 @@ static void __device_release_driver(struct device *dev, struct device *parent) driver_sysfs_remove(dev); - if (dev->bus) - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, - BUS_NOTIFY_UNBIND_DRIVER, - dev); + bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER); pm_runtime_put_sync(dev); @@ -1260,11 +1249,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) klist_remove(&dev->p->knode_driver); 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); } } -- 2.39.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c 2023-01-10 12:42 ` [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c Greg Kroah-Hartman @ 2023-01-10 12:55 ` Rafael J. Wysocki 2023-01-10 13:04 ` Greg Kroah-Hartman 0 siblings, 1 reply; 6+ messages in thread From: Rafael J. Wysocki @ 2023-01-10 12:55 UTC (permalink / raw) To: Greg Kroah-Hartman; +Cc: linux-kernel, Rafael J. Wysocki On Tue, Jan 10, 2023 at 1:43 PM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > 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. > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > --- > drivers/base/base.h | 1 + > drivers/base/bus.c | 8 ++++++++ > drivers/base/core.c | 13 +++---------- > drivers/base/dd.c | 28 +++++++--------------------- > 4 files changed, 19 insertions(+), 31 deletions(-) > > diff --git a/drivers/base/base.h b/drivers/base/base.h > index 7d4803c03d3e..2e08258ce82e 100644 > --- a/drivers/base/base.h > +++ b/drivers/base/base.h > @@ -130,6 +130,7 @@ struct kobject *virtual_device_parent(struct device *dev); > extern int bus_add_device(struct device *dev); > extern void bus_probe_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 void bus_remove_driver(struct device_driver *drv); > diff --git a/drivers/base/bus.c b/drivers/base/bus.c > index 428c26c6b615..cf1b8f00b4c0 100644 > --- a/drivers/base/bus.c > +++ b/drivers/base/bus.c > @@ -850,6 +850,14 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) > } > 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); I'm not sure if the local var is really helpful. Personally, I wouldn't use it, but anyway Reviewed-by: Rafael J. Wysocki <rafael@kernel.org> > +} > + > struct kset *bus_get_kset(struct bus_type *bus) > { > return &bus->p->subsys; > diff --git a/drivers/base/core.c b/drivers/base/core.c > index a3e14143ec0c..af6a2761b31d 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -3453,10 +3453,7 @@ int device_add(struct device *dev) > /* Notify clients of device addition. This call must come > * after dpm_sysfs_add() and before kobject_uevent(). > */ > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_ADD_DEVICE, dev); > - > + bus_notify(dev, BUS_NOTIFY_ADD_DEVICE); > kobject_uevent(&dev->kobj, KOBJ_ADD); > > /* > @@ -3636,9 +3633,7 @@ void device_del(struct device *dev) > * before dpm_sysfs_remove(). > */ > noio_flag = memalloc_noio_save(); > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_DEL_DEVICE, dev); > + bus_notify(dev, BUS_NOTIFY_DEL_DEVICE); > > dpm_sysfs_remove(dev); > if (parent) > @@ -3669,9 +3664,7 @@ void device_del(struct device *dev) > device_platform_notify_remove(dev); > device_links_purge(dev); > > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_REMOVED_DEVICE, dev); > + bus_notify(dev, BUS_NOTIFY_REMOVED_DEVICE); > kobject_uevent(&dev->kobj, KOBJ_REMOVE); > glue_dir = get_glue_dir(dev); > kobject_del(&dev->kobj); > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > index e9b2f9c25efe..a519eaf1990c 100644 > --- a/drivers/base/dd.c > +++ b/drivers/base/dd.c > @@ -413,10 +413,7 @@ static void driver_bound(struct device *dev) > driver_deferred_probe_del(dev); > driver_deferred_probe_trigger(); > > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_BOUND_DRIVER, dev); > - > + bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER); > kobject_uevent(&dev->kobj, KOBJ_BIND); > } > > @@ -435,9 +432,7 @@ static int driver_sysfs_add(struct device *dev) > { > int ret; > > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_BIND_DRIVER, dev); > + bus_notify(dev, BUS_NOTIFY_BIND_DRIVER); > > ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, > kobject_name(&dev->kobj)); > @@ -502,9 +497,8 @@ int device_bind_driver(struct device *dev) > device_links_force_bind(dev); > driver_bound(dev); > } > - else if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_DRIVER_NOT_BOUND, dev); > + else > + bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); > return ret; > } > EXPORT_SYMBOL_GPL(device_bind_driver); > @@ -695,9 +689,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) > probe_failed: > driver_sysfs_remove(dev); > sysfs_failed: > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_DRIVER_NOT_BOUND, dev); > + bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); > if (dev->bus && dev->bus->dma_cleanup) > dev->bus->dma_cleanup(dev); > pinctrl_bind_failed: > @@ -1243,10 +1235,7 @@ static void __device_release_driver(struct device *dev, struct device *parent) > > driver_sysfs_remove(dev); > > - if (dev->bus) > - blocking_notifier_call_chain(&dev->bus->p->bus_notifier, > - BUS_NOTIFY_UNBIND_DRIVER, > - dev); > + bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER); > > pm_runtime_put_sync(dev); > > @@ -1260,11 +1249,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) > > klist_remove(&dev->p->knode_driver); > 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); > } > } > -- > 2.39.0 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c 2023-01-10 12:55 ` Rafael J. Wysocki @ 2023-01-10 13:04 ` Greg Kroah-Hartman 0 siblings, 0 replies; 6+ messages in thread From: Greg Kroah-Hartman @ 2023-01-10 13:04 UTC (permalink / raw) To: Rafael J. Wysocki; +Cc: linux-kernel On Tue, Jan 10, 2023 at 01:55:51PM +0100, Rafael J. Wysocki wrote: > On Tue, Jan 10, 2023 at 1:43 PM Greg Kroah-Hartman > <gregkh@linuxfoundation.org> wrote: > > > > 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. > > > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > > --- > > drivers/base/base.h | 1 + > > drivers/base/bus.c | 8 ++++++++ > > drivers/base/core.c | 13 +++---------- > > drivers/base/dd.c | 28 +++++++--------------------- > > 4 files changed, 19 insertions(+), 31 deletions(-) > > > > diff --git a/drivers/base/base.h b/drivers/base/base.h > > index 7d4803c03d3e..2e08258ce82e 100644 > > --- a/drivers/base/base.h > > +++ b/drivers/base/base.h > > @@ -130,6 +130,7 @@ struct kobject *virtual_device_parent(struct device *dev); > > extern int bus_add_device(struct device *dev); > > extern void bus_probe_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 void bus_remove_driver(struct device_driver *drv); > > diff --git a/drivers/base/bus.c b/drivers/base/bus.c > > index 428c26c6b615..cf1b8f00b4c0 100644 > > --- a/drivers/base/bus.c > > +++ b/drivers/base/bus.c > > @@ -850,6 +850,14 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) > > } > > 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); > > I'm not sure if the local var is really helpful. Personally, I > wouldn't use it, but anyway > > Reviewed-by: Rafael J. Wysocki <rafael@kernel.org> It will be helpful in the next set of patches I send out for this file where I work to make all 'struct bus_type' variables in the kernel constant so they can go into read-only memory. Right now there are only 2 variables that we actually write to in the structure, one will move out to the private field and then the private pointer can go away as we already keep the reference in a different way. This will also fix up some layering violations that I know the platform driver code has, odds are it's in other parts of the kernel too that will be unearthed over time. Sorry for not making that more obvious, that patch series it not yet finished, more to come over the next few weeks... thanks for the reviews of these patches! greg k-h ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] driver core: bus.h: document bus notifiers better 2023-01-10 12:42 [PATCH 1/2] driver core: bus.h: document bus notifiers better Greg Kroah-Hartman 2023-01-10 12:42 ` [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c Greg Kroah-Hartman @ 2023-01-10 12:52 ` Rafael J. Wysocki 2023-01-10 13:04 ` Greg Kroah-Hartman 1 sibling, 1 reply; 6+ messages in thread From: Rafael J. Wysocki @ 2023-01-10 12:52 UTC (permalink / raw) To: Greg Kroah-Hartman; +Cc: linux-kernel, Rafael J. Wysocki On Tue, Jan 10, 2023 at 1:43 PM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > The bus notifier values are not documented all that well, so clean this > up and make a real enumerated type for them and document them much > better. > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > --- > include/linux/device/bus.h | 43 +++++++++++++++++++++++++------------- > 1 file changed, 29 insertions(+), 14 deletions(-) > > diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h > index d529f644e92b..1e1a593348bc 100644 > --- a/include/linux/device/bus.h > +++ b/include/linux/device/bus.h > @@ -257,21 +257,36 @@ extern int bus_register_notifier(struct bus_type *bus, > extern int bus_unregister_notifier(struct bus_type *bus, > struct notifier_block *nb); > > -/* All 4 notifers below get called with the target struct device * > - * as an argument. Note that those functions are likely to be called > - * with the device lock held in the core, so be careful. > +/** > + * enum bus_notifier_event: Bus Notifier events that have happened > + * > + * These are the value passed to a bus notifier when a specific event happens. > + * > + * Note that bus notifiers are likely to be called with the device lock already > + * held by the driver core, so be careful in any notifier callback as to what > + * you do with the device structure. > + * > + * All bus notifiers are called with the target struct device * as an argument. > + * > + * BUS_NOTIFY_ADD_DEVICE: device is added to this bus > + * BUS_NOTIFY_DEL_DEVICE: device is about to be removed from this bus > + * BUS_NOTIFY_REMOVED_DEVICE: device is successfully removed from this bus > + * BUS_NOTIFY_BIND_DRIVER: a driver is about to be bound to this device on this bus > + * BUS_NOTIFY_BOUND_DRIVER: a driver is successfully bound to this device on this bus > + * BUS_NOTIFY_UNBIND_DRIVER: a driver is about to be unbound from this device on this bus > + * BUS_NOTIFY_UNBOUND_DRIVER: a driver is successfully unbound from this device on this bus > + * BUS_NOTIFY_DRIVER_NOT_BOUND: a driver failed to be bound to this device on this bus > */ > -#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ > -#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device to be removed */ > -#define BUS_NOTIFY_REMOVED_DEVICE 0x00000003 /* device removed */ > -#define BUS_NOTIFY_BIND_DRIVER 0x00000004 /* driver about to be > - bound */ > -#define BUS_NOTIFY_BOUND_DRIVER 0x00000005 /* driver bound to device */ > -#define BUS_NOTIFY_UNBIND_DRIVER 0x00000006 /* driver about to be > - unbound */ > -#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is unbound > - from the device */ > -#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008 /* driver fails to be bound */ > +enum bus_notifier_event { > + BUS_NOTIFY_ADD_DEVICE = 0x00000001, > + BUS_NOTIFY_DEL_DEVICE = 0x00000002, > + BUS_NOTIFY_REMOVED_DEVICE = 0x00000003, > + BUS_NOTIFY_BIND_DRIVER = 0x00000004, > + BUS_NOTIFY_BOUND_DRIVER = 0x00000005, > + BUS_NOTIFY_UNBIND_DRIVER = 0x00000006, > + BUS_NOTIFY_UNBOUND_DRIVER = 0x00000007, > + BUS_NOTIFY_DRIVER_NOT_BOUND = 0x00000008, I'm wondering why the values are in hex (the 0x prefix doesn't matter for these numbers AFAICS) and what the initial zeros are for (AFAICS they don't matter either). > +}; > > extern struct kset *bus_get_kset(struct bus_type *bus); > > -- ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] driver core: bus.h: document bus notifiers better 2023-01-10 12:52 ` [PATCH 1/2] driver core: bus.h: document bus notifiers better Rafael J. Wysocki @ 2023-01-10 13:04 ` Greg Kroah-Hartman 0 siblings, 0 replies; 6+ messages in thread From: Greg Kroah-Hartman @ 2023-01-10 13:04 UTC (permalink / raw) To: Rafael J. Wysocki; +Cc: linux-kernel On Tue, Jan 10, 2023 at 01:52:24PM +0100, Rafael J. Wysocki wrote: > On Tue, Jan 10, 2023 at 1:43 PM Greg Kroah-Hartman > <gregkh@linuxfoundation.org> wrote: > > > > The bus notifier values are not documented all that well, so clean this > > up and make a real enumerated type for them and document them much > > better. > > > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > > --- > > include/linux/device/bus.h | 43 +++++++++++++++++++++++++------------- > > 1 file changed, 29 insertions(+), 14 deletions(-) > > > > diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h > > index d529f644e92b..1e1a593348bc 100644 > > --- a/include/linux/device/bus.h > > +++ b/include/linux/device/bus.h > > @@ -257,21 +257,36 @@ extern int bus_register_notifier(struct bus_type *bus, > > extern int bus_unregister_notifier(struct bus_type *bus, > > struct notifier_block *nb); > > > > -/* All 4 notifers below get called with the target struct device * > > - * as an argument. Note that those functions are likely to be called > > - * with the device lock held in the core, so be careful. > > +/** > > + * enum bus_notifier_event: Bus Notifier events that have happened > > + * > > + * These are the value passed to a bus notifier when a specific event happens. > > + * > > + * Note that bus notifiers are likely to be called with the device lock already > > + * held by the driver core, so be careful in any notifier callback as to what > > + * you do with the device structure. > > + * > > + * All bus notifiers are called with the target struct device * as an argument. > > + * > > + * BUS_NOTIFY_ADD_DEVICE: device is added to this bus > > + * BUS_NOTIFY_DEL_DEVICE: device is about to be removed from this bus > > + * BUS_NOTIFY_REMOVED_DEVICE: device is successfully removed from this bus > > + * BUS_NOTIFY_BIND_DRIVER: a driver is about to be bound to this device on this bus > > + * BUS_NOTIFY_BOUND_DRIVER: a driver is successfully bound to this device on this bus > > + * BUS_NOTIFY_UNBIND_DRIVER: a driver is about to be unbound from this device on this bus > > + * BUS_NOTIFY_UNBOUND_DRIVER: a driver is successfully unbound from this device on this bus > > + * BUS_NOTIFY_DRIVER_NOT_BOUND: a driver failed to be bound to this device on this bus > > */ > > -#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ > > -#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device to be removed */ > > -#define BUS_NOTIFY_REMOVED_DEVICE 0x00000003 /* device removed */ > > -#define BUS_NOTIFY_BIND_DRIVER 0x00000004 /* driver about to be > > - bound */ > > -#define BUS_NOTIFY_BOUND_DRIVER 0x00000005 /* driver bound to device */ > > -#define BUS_NOTIFY_UNBIND_DRIVER 0x00000006 /* driver about to be > > - unbound */ > > -#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is unbound > > - from the device */ > > -#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008 /* driver fails to be bound */ > > +enum bus_notifier_event { > > + BUS_NOTIFY_ADD_DEVICE = 0x00000001, > > + BUS_NOTIFY_DEL_DEVICE = 0x00000002, > > + BUS_NOTIFY_REMOVED_DEVICE = 0x00000003, > > + BUS_NOTIFY_BIND_DRIVER = 0x00000004, > > + BUS_NOTIFY_BOUND_DRIVER = 0x00000005, > > + BUS_NOTIFY_UNBIND_DRIVER = 0x00000006, > > + BUS_NOTIFY_UNBOUND_DRIVER = 0x00000007, > > + BUS_NOTIFY_DRIVER_NOT_BOUND = 0x00000008, > > I'm wondering why the values are in hex (the 0x prefix doesn't matter > for these numbers AFAICS) and what the initial zeros are for (AFAICS > they don't matter either). I have no idea why they are this way. I'll go change them to just be decimal, thanks! greg k-h ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-01-10 13:05 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-01-10 12:42 [PATCH 1/2] driver core: bus.h: document bus notifiers better Greg Kroah-Hartman 2023-01-10 12:42 ` [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c Greg Kroah-Hartman 2023-01-10 12:55 ` Rafael J. Wysocki 2023-01-10 13:04 ` Greg Kroah-Hartman 2023-01-10 12:52 ` [PATCH 1/2] driver core: bus.h: document bus notifiers better Rafael J. Wysocki 2023-01-10 13:04 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox