Skip to content

Commit

Permalink
usb: misc: onboard_hub: Invert driver registration order
Browse files Browse the repository at this point in the history
The onboard_hub 'driver' consists of two drivers, a platform
driver and a USB driver. Currently when the onboard hub driver
is initialized it first registers the platform driver, then the
USB driver. This results in a race condition when the 'attach'
work is executed, which is scheduled when the platform device
is probed. The purpose of fhe 'attach' work is to bind elegible
USB hub devices to the onboard_hub USB driver. This fails if
the work runs before the USB driver has been registered.

Register the USB driver first, then the platform driver. This
increases the chances that the onboard_hub USB devices are probed
before their corresponding platform device, which the USB driver
tries to locate in _probe(). The driver already handles this
situation and defers probing if the onboard hub platform device
doesn't exist yet.

Cc: stable@vger.kernel.org
Fixes: 8bc0636 ("usb: misc: Add onboard_usb_hub driver")
Link: https://lore.kernel.org/lkml/Y6W00vQm3jfLflUJ@hovoldconsulting.com/T/#m0d64295f017942fd988f7c53425db302d61952b4
Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Link: https://lore.kernel.org/r/20230110172954.v2.1.I75494ebee7027a50235ce4b1e930fa73a578fbe2@changeid
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Matthias Kaehlcke authored and Greg Kroah-Hartman committed Jan 17, 2023
1 parent fac4b86 commit e585435
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/usb/misc/onboard_usb_hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@ static int __init onboard_hub_init(void)
{
int ret;

ret = platform_driver_register(&onboard_hub_driver);
ret = usb_register_device_driver(&onboard_hub_usbdev_driver, THIS_MODULE);
if (ret)
return ret;

ret = usb_register_device_driver(&onboard_hub_usbdev_driver, THIS_MODULE);
ret = platform_driver_register(&onboard_hub_driver);
if (ret)
platform_driver_unregister(&onboard_hub_driver);
usb_deregister_device_driver(&onboard_hub_usbdev_driver);

return ret;
}
Expand Down

0 comments on commit e585435

Please sign in to comment.