From patchwork Fri Oct 20 15:15:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13430869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D005FCDB474 for ; Fri, 20 Oct 2023 15:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=bc35yOlvo7gMAt6p8UvPS3UHqC9Rd7j7/WZ/iRf/6b8=; b=uWcx/AKBsOecW+vqo5sIAbvMa3 8o32Npp02EdXqO0Th5atebF1KoDckpjESgc4mC7C7f/6AFuhbUGpZQuDIr1vfobOF/AcSF6QSxap7 B2MBCRZK7rMoTQwGiYzMDBHg+eyjl/KzcsorNb9z1YBLIkfkqRhkiPeXwz80nHySU5ZL7TMPKJ0RH KOMdPFtVPW/rzThSWVNpMtYfedKm6mCyAXabnEHdWkESzYy3j22VEMEE8tJUGaxKpNNP8YgSdplP5 A4yvisGsD/IrSIRgaVgQ0Q1O+/jQfk8UcHWx/DhnOCBqC5kFqEcDFw4CIqqbXyfWNp2KMgO2uEjp/ V7IdnR4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtrEA-002aaS-1M; Fri, 20 Oct 2023 15:15:54 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtrE7-002aY5-0W for linux-mediatek@lists.infradead.org; Fri, 20 Oct 2023 15:15:53 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qtrE1-0000gr-7N; Fri, 20 Oct 2023 17:15:45 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtrDz-0033cB-Rt; Fri, 20 Oct 2023 17:15:43 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1qtrDz-002aWP-Hr; Fri, 20 Oct 2023 17:15:43 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Chunfeng Yun , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-mediatek@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH v3] usb: mtu3: Convert to platform remove callback returning void Date: Fri, 20 Oct 2023 17:15:38 +0200 Message-ID: <20231020151537.2202675-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3276; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=5te6rft8Xh5PpQ5BujZTLunAUrXlCOfxv6+ytIbWu1s=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlMpmavi4cw3Qhslrae61n6rVTXG6x9s3KACxnO hzTEfBb3TyJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZTKZmgAKCRCPgPtYfRL+ TtGSCACF02KJb7auDo0h7N6WUMVosNAziZMu/RGTzB2lD48oG18EHIe8hC6/GAuDSo4w/vJnNY4 KbFLZudnARtOcfCG9DV7R0d6LwhBz+jxag4CkQknvRTSIoBn4eeRA2BF7evsTLgAGO6ol/OH/SU D5Z56+U3CP2SRd+SDybUgG98JY1mZzUNhjRPi/fWFOVHi+rneeW3C/01SKTfCHoaI68g3wiZU11 NF/2FjRw7uDHKQQNQa7fCgibq4NBXII4wvp4eVETqmzpUPPqCQ28Hhc/yddBCwcbHKC39OWVzuX MiO3QQ07y/tqZeuu+d7R9CHBFBuwAPc0nm4mgsuriEFKKUjl X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231020_081551_218098_D0BA14C3 X-CRM114-Status: GOOD ( 19.63 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 --- Changes since v2 that sent with Message-Id: 20230914200251.919584-1-u.kleine-koenig@pengutronix.de: - Drop WARN_ON - Rebase to a newer tree Changes since (implicit) v1 sent with Message-Id: 20230709163335.3458886-1-u.kleine-koenig@pengutronix.de: - Keep case USB_DR_MODE_UNKNOWN to cope for the compiler being called with -Werror=switch. - Rebase to a newer tree drivers/usb/mtu3/mtu3_plat.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) base-commit: 2030579113a1b1b5bfd7ff24c0852847836d8fd1 diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 6f264b129243..6858ed9fc3b2 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -451,7 +451,7 @@ static int mtu3_probe(struct platform_device *pdev) return ret; } -static int mtu3_remove(struct platform_device *pdev) +static void mtu3_remove(struct platform_device *pdev) { struct ssusb_mtk *ssusb = platform_get_drvdata(pdev); @@ -469,8 +469,16 @@ static int mtu3_remove(struct platform_device *pdev) ssusb_gadget_exit(ssusb); ssusb_host_exit(ssusb); break; - default: - return -EINVAL; + case USB_DR_MODE_UNKNOWN: + /* + * This cannot happen because with dr_mode == + * USB_DR_MODE_UNKNOWN, .probe() doesn't succeed and so + * .remove() wouldn't be called at all. However (little + * surprising) the compiler isn't smart enough to see that, so + * we explicitly have this case item to not make the compiler + * wail about an unhandled enumeration value. + */ + break; } ssusb_rscs_exit(ssusb); @@ -478,8 +486,6 @@ static int mtu3_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); pm_runtime_set_suspended(&pdev->dev); - - return 0; } static int resume_ip_and_ports(struct ssusb_mtk *ssusb, pm_message_t msg) @@ -615,7 +621,7 @@ MODULE_DEVICE_TABLE(of, mtu3_of_match); static struct platform_driver mtu3_driver = { .probe = mtu3_probe, - .remove = mtu3_remove, + .remove_new = mtu3_remove, .driver = { .name = MTU3_DRIVER_NAME, .pm = DEV_PM_OPS,