From: Leon Romanovsky Manual gameport binding calls the driver's connect callback without the device lock, allowing it to race with generic sysfs probing. Normal probing would run CONFIG_DEBUG_TEST_DRIVER_REMOVE under gameport_mutex; a disconnect callback that unregisters a child port would then deadlock trying to acquire the same mutex. Use device_driver_attach_unrestricted() to centralize binding and failure cleanup without the debug removal cycle. Take the device lock with device_trylock() to serialize attachment with generic probing. Return -EBUSY on contention because waiting while holding gameport_mutex could deadlock with probe cleanup that needs it. Signed-off-by: Leon Romanovsky --- drivers/input/gameport/gameport.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index 9707b155bc947..88b1a3464bf3e 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c @@ -216,24 +216,12 @@ static int gameport_bind_driver(struct gameport *gameport, struct gameport_drive { int error; - gameport->dev.driver = &drv->driver; - if (drv->connect(gameport, drv)) { - gameport->dev.driver = NULL; - return -ENODEV; - } + if (!device_trylock(&gameport->dev)) + return -EBUSY; - error = device_bind_driver(&gameport->dev); - if (error) { - dev_warn(&gameport->dev, - "device_bind_driver() failed for %s (%s) and %s, error: %d\n", - gameport->phys, gameport->name, - drv->description, error); - drv->disconnect(gameport); - gameport->dev.driver = NULL; - return error; - } - - return 0; + error = device_driver_attach_unrestricted(&drv->driver, &gameport->dev); + device_unlock(&gameport->dev); + return error; } static void gameport_find_driver(struct gameport *gameport) -- 2.56.1