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

Alan Stern
2015-05-27T15:16:36Z

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.

Alan Stern