Re: [PATCH] nubus: Unconditionally register bus type

From: Greg Kroah-Hartman
Date: Tue May 08 2018 - 03:01:49 EST


On Mon, May 07, 2018 at 09:57:22AM +1000, Finn Thain wrote:
> On Sun, 6 May 2018, Greg Kroah-Hartman wrote:
>
> > > > Why not just have an "bus is registered" flag in your driver
> > > > register function that refuses to let drivers register with the
> > > > driver core if it isn't set?
> > >
> > > Perhaps that should happen in the core driver_register() function.
> > > BUG_ON is frowned upon, after all. Would that be acceptable?
> >
> > I don't understand what you mean here, perhaps make a patch to show it?
> >
>
> As an alternative to your suggestion (add flag to avoid the BUG_ON):
>
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -148,7 +148,10 @@ int driver_register(struct device_driver *drv)
> int ret;
> struct device_driver *other;
>
> - BUG_ON(!drv->bus->p);
> + if (!drv->bus->p) {
> + WARN_ONCE(1, "Cannot register driver with invalid bus\n");
> + return -EPROBE_DEFER;
> + }
>
> if ((drv->bus->probe && drv->probe) ||
> (drv->bus->remove && drv->remove) ||
>
> I'm not actually proposing this change; just responding to your question.
>
> For the bug at hand, I still prefer the patch at the beginning of this
> thread, because it seems to follow the conventional pattern.
>
> > > I found a few drivers that set a flag the way you describe, which
> > > could then be simplified.
> > >
> > > But that pattern is rare. Most buses use the postcore_initcall()
> > > pattern, and so my patch took the conventional approach.
> >
> > It all depends on link order, not necessarily the postcore stuff.
> >
> > > > And then fix your linking error, the bus should come first in link
> > > > order, before your drivers :)
> > > >
> > >
> > > I didn't encounter any errors. How shall I reproduce this?
> >
> > If you have not seen this error, then why change the code at all if it
> > is working properly?
>
> I never saw the link error you mentioned.
>
> Please see this thread for one example of how to hit the BUG_ON.
> https://marc.info/?l=linux-m68k&m=152522162801182&w=2
>
> Another way to trigger the BUG_ON is to set,
> CONFIG_ATARI=y
> CONFIG_MAC=y
> CONFIG_NUBUS=y
> CONFIG_MAC8390=y
> and try to boot the result on aranym.

See my other response in this thread describing the link order problem.
But if you can't resolve this that way, then yes, your original patch
should be fine.

thanks,

greg k-h