Skip to content

Commit 3d56e5a

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
usb: gadget: aspeed_udc: Convert to platform remove callback returning void
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). ast_udc_remove() is one of these functions that return an error code after doing only a partial cleanup. Replace the core's error message by a more drastic one and still convert the driver to .remove_new(). Note the only semantic change here is the changed error message. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20231026221701.2521483-2-u.kleine-koenig@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c309771 commit 3d56e5a

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

drivers/usb/gadget/udc/aspeed_udc.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,15 +1432,24 @@ static void ast_udc_init_hw(struct ast_udc_dev *udc)
14321432
ast_udc_write(udc, 0, AST_UDC_EP0_CTRL);
14331433
}
14341434

1435-
static int ast_udc_remove(struct platform_device *pdev)
1435+
static void ast_udc_remove(struct platform_device *pdev)
14361436
{
14371437
struct ast_udc_dev *udc = platform_get_drvdata(pdev);
14381438
unsigned long flags;
14391439
u32 ctrl;
14401440

14411441
usb_del_gadget_udc(&udc->gadget);
1442-
if (udc->driver)
1443-
return -EBUSY;
1442+
if (udc->driver) {
1443+
/*
1444+
* This is broken as only some cleanup is skipped, *udev is
1445+
* freed and the register mapping goes away. Any further usage
1446+
* probably crashes. Also the device is unbound, so the skipped
1447+
* cleanup is never catched up later.
1448+
*/
1449+
dev_alert(&pdev->dev,
1450+
"Driver is busy and still going away. Fasten your seat belts!\n");
1451+
return;
1452+
}
14441453

14451454
spin_lock_irqsave(&udc->lock, flags);
14461455

@@ -1459,8 +1468,6 @@ static int ast_udc_remove(struct platform_device *pdev)
14591468
udc->ep0_buf_dma);
14601469

14611470
udc->ep0_buf = NULL;
1462-
1463-
return 0;
14641471
}
14651472

14661473
static int ast_udc_probe(struct platform_device *pdev)
@@ -1581,7 +1588,7 @@ MODULE_DEVICE_TABLE(of, ast_udc_of_dt_ids);
15811588

15821589
static struct platform_driver ast_udc_driver = {
15831590
.probe = ast_udc_probe,
1584-
.remove = ast_udc_remove,
1591+
.remove_new = ast_udc_remove,
15851592
.driver = {
15861593
.name = KBUILD_MODNAME,
15871594
.of_match_table = ast_udc_of_dt_ids,

0 commit comments

Comments
 (0)