Re: [PATCH] usb: ulpi: don't register drivers if bus doesn't exist

From: Greg KH
Date: Wed May 27 2015 - 11:21:28 EST


On Wed, May 27, 2015 at 11:16:34AM -0400, Alan Stern wrote:
> On Wed, 27 May 2015, Heikki Krogerus wrote:
>
> > This problem is not ulpi specific. We have the same issue with every
> > single bus. With a bus like PCI it's just really unlikely to hit it
> > because PCI bus driver uses postcore_initcall. But if there was
> > a PCI driver that used postcore_initcall itself, maybe a gpio
> > controller driver for example, exactly the same panic would happen
> > that we see happening when a driver tries to register itself with ulpi
> > bus before ulpi bus has been registered.
> >
> > I can appreciate now that fixing the core problem like I2C did is
> > wrong, but I still feel that the driver core should provide something
> > like the helper for checking if the bus was registered already or not.
> > Otherwise all the bus drivers should really have a variable like Sudip
> > suggested for checking it, but that would be boilerplate, no?
>
> This sounds like a tricky problem.
>
> What is a driver supposed to do if it wants to register itself with a
> bus that hasn't been registered yet? It can't just sit around
> and wait for the bus to be registered. But the only alternative is to
> let its initialization fail, which means the driver will never be used.
>
> The only solution I can think of is for the driver core to keep a list
> of pending drivers in struct bus_type, for before the bus has been
> registered. When the bus finally does get registered, the core should
> then register all the drivers waiting on that list.

Ugh, no, that's a mess. The bus needs to be registered first, if it
wasn't then something "bad" happened in the design, or the registration
failed. If registration failed, then the driver should also fail when
it tries to register the bus.

Maybe we need to test for this in the driver core, not allowing drivers
for busses that are not registered, that might solve the main problem
here. I'll try to look at it tonight.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/