Re: [PATCH 2/2] driver core: bus: move bus notifier logic into bus.c

From: Greg Kroah-Hartman
Date: Tue Jan 10 2023 - 08:04:59 EST


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@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxx>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > ---
> > 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@xxxxxxxxxx>

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