Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: mtu3: 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 (mostly) ignored
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.

The function mtu3_remove() can only return a non-zero value if
ssusb->dr_mode is neiter USB_DR_MODE_PERIPHERAL nor USB_DR_MODE_HOST nor
USB_DR_MODE_OTG. In this case however the probe callback doesn't succeed
and so the remove callback isn't called at all. So the code branch
resulting in this error path could just be dropped were it not for the
compiler choking on "enumeration value 'USB_DR_MODE_UNKNOWN' not handled
in switch [-Werror=switch]". So instead replace this code path by a
WARN_ON and then mtu3_remove() be converted to return void trivially.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20231020151537.2202675-2-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Uwe Kleine-König and committed by
Greg Kroah-Hartman
46b6fc53 8e99dc78

+12 -6
+12 -6
drivers/usb/mtu3/mtu3_plat.c
··· 451 451 return ret; 452 452 } 453 453 454 - static int mtu3_remove(struct platform_device *pdev) 454 + static void mtu3_remove(struct platform_device *pdev) 455 455 { 456 456 struct ssusb_mtk *ssusb = platform_get_drvdata(pdev); 457 457 ··· 469 469 ssusb_gadget_exit(ssusb); 470 470 ssusb_host_exit(ssusb); 471 471 break; 472 - default: 473 - return -EINVAL; 472 + case USB_DR_MODE_UNKNOWN: 473 + /* 474 + * This cannot happen because with dr_mode == 475 + * USB_DR_MODE_UNKNOWN, .probe() doesn't succeed and so 476 + * .remove() wouldn't be called at all. However (little 477 + * surprising) the compiler isn't smart enough to see that, so 478 + * we explicitly have this case item to not make the compiler 479 + * wail about an unhandled enumeration value. 480 + */ 481 + break; 474 482 } 475 483 476 484 ssusb_rscs_exit(ssusb); ··· 486 478 pm_runtime_disable(&pdev->dev); 487 479 pm_runtime_put_noidle(&pdev->dev); 488 480 pm_runtime_set_suspended(&pdev->dev); 489 - 490 - return 0; 491 481 } 492 482 493 483 static int resume_ip_and_ports(struct ssusb_mtk *ssusb, pm_message_t msg) ··· 621 615 622 616 static struct platform_driver mtu3_driver = { 623 617 .probe = mtu3_probe, 624 - .remove = mtu3_remove, 618 + .remove_new = mtu3_remove, 625 619 .driver = { 626 620 .name = MTU3_DRIVER_NAME, 627 621 .pm = DEV_PM_OPS,