From patchwork Fri Oct 20 07:56:01 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: 13430245 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 271EFCDB474 for ; Fri, 20 Oct 2023 07:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=AIiiC+3BfceLifpbVXBRcZD3AMNvSzCwfYp4zdneQX0=; b=wslA7DxJi9vT3Z ccLVtWAa2r6J1jFaoGFq5hL4isri5IjtAv5PWTX0bzeNrGrIyBKeuo3XzzI7eDbEdVDvoJdm4yIeX 0bBShf9GfSu3ZmeNMM+s0o0lked8XddBYnXV3FBhGvMuS2waYmBqkg32EVuRLAURMOeBS3zP60yb3 b4DE5Ih2Xg+tkALcVqIUSPAth+1BJNoNyvewNg0WJGwpdPsco/5vlYx4nGANa04F+z0mOYrRduR6T RSNfOfsvapB21IdhLoIDagA+u+skBWJYxf2K95o1Gvau86G8uZBUnlNUimwhRmhg/UE/4xMUbMWqX 0sja59yZb2pfMCvBThZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtkO5-001Uft-2T; Fri, 20 Oct 2023 07:57:41 +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 1qtkNG-001UGr-2Z for linux-arm-kernel@lists.infradead.org; Fri, 20 Oct 2023 07:56:52 +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 1qtkN7-0003hX-Bo; Fri, 20 Oct 2023 09:56:41 +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 1qtkN5-002yWQ-Gz; Fri, 20 Oct 2023 09:56:39 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1qtkN5-002OKk-7g; Fri, 20 Oct 2023 09:56:39 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Herbert Xu , "David S. Miller" Cc: Maxime Coquelin , Alexandre Torgue , Linus Walleij , nicolas.toromanoff@foss.st.com, Colin Ian King , Rob Herring , linux-crypto@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH 39/42] crypto: stm32/cryp - Convert to platform remove callback returning void Date: Fri, 20 Oct 2023 09:56:01 +0200 Message-ID: <20231020075521.2121571-83-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020075521.2121571-44-u.kleine-koenig@pengutronix.de> References: <20231020075521.2121571-44-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2723; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=7A/4jfO5f6HPiPMVJM3k1eEGID7WdOBM8OghW+7z3ug=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlMjKWxBuHKyc8wcbd1mj6AxMptWcoLzYBnaw3U wg+jgwX8VSJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZTIylgAKCRCPgPtYfRL+ ThDwB/wK8d5usctRxniPVmWkOoFU/WfE+6gfYDF2lBAw5FKmcp0+xjRl5hPzamdDONa7wNHQggs vmLCxzAf9nSCzPtI4JlodbrDMzqLrJR2JHHxzh3pqh14ouxm6RsYMgUCK10LH07JW3eOtS3ZYNB MLRUbqq6zG2PI6MN8U4St7jnLxOJZ0Ry/idbzvxTD/Kq539lV98YNQYccHGjZziD5AQzMc9qosN X5tWmf9gRPJaaV2j5UoywSLzRCV3qveCSRxgZUIhdVgM/otC56pBRcSlxeWcyOqGREb7SYQOiKR UO+vpVfxREop/84pttO44tEJO6MF72B7eK4uFbPwzb7EXo9i 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-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231020_005650_834287_57520B03 X-CRM114-Status: GOOD ( 19.94 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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 driver adapted here suffered from this wrong assumption and had several error paths resulting in resource leaks. The check for cryp being non-NULL is harmless. This can never happen as .remove() is only called after .probe() completed successfully and in that case drvdata was set to a non-NULL value. So this check can just be dropped. If pm_runtime_get() fails, the other resources held by the device must still be freed. Only clk_disable_unprepare() should be skipped as the pm_runtime_get() failed to call clk_prepare_enable(). After these changes the remove function returns zero unconditionally and can trivially be converted to the prototype required for .remove_new(). Signed-off-by: Uwe Kleine-König --- drivers/crypto/stm32/stm32-cryp.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index f095f0065428..c3cbc2673338 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -2084,17 +2084,12 @@ static int stm32_cryp_probe(struct platform_device *pdev) return ret; } -static int stm32_cryp_remove(struct platform_device *pdev) +static void stm32_cryp_remove(struct platform_device *pdev) { struct stm32_cryp *cryp = platform_get_drvdata(pdev); int ret; - if (!cryp) - return -ENODEV; - - ret = pm_runtime_resume_and_get(cryp->dev); - if (ret < 0) - return ret; + ret = pm_runtime_get_sync(cryp->dev); if (cryp->caps->aeads_support) crypto_engine_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs)); @@ -2109,9 +2104,8 @@ static int stm32_cryp_remove(struct platform_device *pdev) pm_runtime_disable(cryp->dev); pm_runtime_put_noidle(cryp->dev); - clk_disable_unprepare(cryp->clk); - - return 0; + if (ret >= 0) + clk_disable_unprepare(cryp->clk); } #ifdef CONFIG_PM @@ -2148,7 +2142,7 @@ static const struct dev_pm_ops stm32_cryp_pm_ops = { static struct platform_driver stm32_cryp_driver = { .probe = stm32_cryp_probe, - .remove = stm32_cryp_remove, + .remove_new = stm32_cryp_remove, .driver = { .name = DRIVER_NAME, .pm = &stm32_cryp_pm_ops,