From patchwork Tue Feb 14 16:28:27 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: 13140514 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BDBCC05027 for ; Tue, 14 Feb 2023 16:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbjBNQ3D (ORCPT ); Tue, 14 Feb 2023 11:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbjBNQ3B (ORCPT ); Tue, 14 Feb 2023 11:29:01 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60D5B5B9F for ; Tue, 14 Feb 2023 08:28:55 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRyAk-0007T1-CZ; Tue, 14 Feb 2023 17:28:50 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRyAh-004v9W-A1; Tue, 14 Feb 2023 17:28:48 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRyAh-003WdO-C5; Tue, 14 Feb 2023 17:28:47 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Olivia Mackall , Herbert Xu Cc: linux-crypto@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 1/3] hwrng: xgene - Simplify using dev_err_probe() Date: Tue, 14 Feb 2023 17:28:27 +0100 Message-Id: <20230214162829.113148-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214162829.113148-1-u.kleine-koenig@pengutronix.de> References: <20230214162829.113148-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2260; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=5rPibkTxgwk9CqlfvS5PEBSxCYiLpBJ60L3YMoK8eqE=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBj67ahOPmTyyVKxLd3FqyXP2vSwhjMUWov8sCtV IftREIs/pKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY+u2oQAKCRDB/BR4rcrs CaCxB/9ysP09c2OzJhBi1iqJQO2uvNorgQ1aL2JqoukUjfsfNFVCq+1b8gSJNoW6F66JC7wU+HJ 5c3CheBZmul+U/U5pbQHgHbJAGoayHZjWH+5NXFi2LGzyew6jfiXV1cgoBaDVON3wWIg6dSADP+ 3E1jNm+Nl8OAPGicFKiQmtmwVDxb1Xz3wg8jibqlo1rn0rjQk8OjgpnlsBL9GubRvjUpxRpthUb Iy6nA2j84DdG3TC+5ptY6BXTwmqC1+WW0njvY+dq/mYKUWKlFAj9+LgwpP4mMz67/2FUEE6OgOx NPcFzjSsyZrfQphRG5qw89GK3/jDbdtnfuqFAt6sdJgPooqC 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.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-crypto@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org dev_err_probe simplifies the idiom: if (ret != -EPROBE_DEFER) dev_err(...) return ret; , emits the error code in a human readable way and even yields a useful entry in /sys/kernel/debug/devices_deferred in the EPROBE_DEFER case. So simplify and at the same time improve the driver by using dev_err_probe(). Signed-off-by: Uwe Kleine-König --- drivers/char/hw_random/xgene-rng.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/char/hw_random/xgene-rng.c b/drivers/char/hw_random/xgene-rng.c index 008e6db9ce01..a6a30686a58b 100644 --- a/drivers/char/hw_random/xgene-rng.c +++ b/drivers/char/hw_random/xgene-rng.c @@ -337,10 +337,8 @@ static int xgene_rng_probe(struct platform_device *pdev) rc = devm_request_irq(&pdev->dev, ctx->irq, xgene_rng_irq_handler, 0, dev_name(&pdev->dev), ctx); - if (rc) { - dev_err(&pdev->dev, "Could not request RNG alarm IRQ\n"); - return rc; - } + if (rc) + return dev_err_probe(&pdev->dev, rc, "Could not request RNG alarm IRQ\n"); /* Enable IP clock */ ctx->clk = devm_clk_get(&pdev->dev, NULL); @@ -348,30 +346,25 @@ static int xgene_rng_probe(struct platform_device *pdev) dev_warn(&pdev->dev, "Couldn't get the clock for RNG\n"); } else { rc = clk_prepare_enable(ctx->clk); - if (rc) { - dev_warn(&pdev->dev, - "clock prepare enable failed for RNG"); - return rc; - } + if (rc) + return dev_err_probe(&pdev->dev, rc, + "clock prepare enable failed for RNG"); } xgene_rng_func.priv = (unsigned long) ctx; rc = devm_hwrng_register(&pdev->dev, &xgene_rng_func); if (rc) { - dev_err(&pdev->dev, "RNG registering failed error %d\n", rc); if (!IS_ERR(ctx->clk)) clk_disable_unprepare(ctx->clk); - return rc; + return dev_err_probe(&pdev->dev, rc, "RNG registering failed\n"); } rc = device_init_wakeup(&pdev->dev, 1); if (rc) { - dev_err(&pdev->dev, "RNG device_init_wakeup failed error %d\n", - rc); if (!IS_ERR(ctx->clk)) clk_disable_unprepare(ctx->clk); - return rc; + return dev_err_probe(&pdev->dev, rc, "RNG device_init_wakeup failed\n"); } return 0; From patchwork Tue Feb 14 16:28:28 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: 13140512 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3A0AC6379F for ; Tue, 14 Feb 2023 16:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbjBNQ3C (ORCPT ); Tue, 14 Feb 2023 11:29:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbjBNQ3B (ORCPT ); Tue, 14 Feb 2023 11:29:01 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0DD222D4 for ; Tue, 14 Feb 2023 08:28:55 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRyAk-0007T2-CZ; Tue, 14 Feb 2023 17:28:50 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRyAh-004v9Z-DH; Tue, 14 Feb 2023 17:28:48 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRyAh-003WdR-I2; Tue, 14 Feb 2023 17:28:47 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Olivia Mackall , Herbert Xu Cc: linux-crypto@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 2/3] hwrng: xgene - Simplify using devm_clk_get_optional_enabled() Date: Tue, 14 Feb 2023 17:28:28 +0100 Message-Id: <20230214162829.113148-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214162829.113148-1-u.kleine-koenig@pengutronix.de> References: <20230214162829.113148-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3077; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=Vz3yripQ3g4PiE359obAYzbKycP82MKb8z3KxYjldXo=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBj67aknU6qDqpESz/f84Lm2/tYIcKi/3MhsPQld jmVKgDt3rqJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY+u2pAAKCRDB/BR4rcrs CZYUB/4k5bxtW92/zBLgaUovrVwNfEXXSVl36024UgPceP6sczHoylIadQTZNOLlNboSDT8FBH/ xY1UjcpM25cCgp8SXC9VggLgNOiuIjOy0fLoNKe+L79nYGMVQT9GgYrIvSN3rx+ewsEyzUB6rdk 3EzpaV+mUgGtoCkZxWfeZG67oKhl07rqN5DbV9xKxMuuSivoIWp8p8t3Yr8kMbavKEPBxIWh3Br m6p7SnZkbPZTyl50xhvsxjw83ephZ/q2I3kVWpTeKuYKTCPscz2q3fCGVr5T7eLILfKIEUrimmv Q/nU2bV7xpHu7liM3XoM15HGnKtOJj5p/NCZgRJ3YzuikO0h 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.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-crypto@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of ignoring errors returned by devm_clk_get() and manually enabling the clk for the whole lifetime of the bound device, use devm_clk_get_optional_enabled(). This is simpler and also more correct as it doesn't ignore errors. This is also more correct because now the call to clk_disable_unprepare() can be dropped from xgene_rng_remove() which happened while the hwrn device was still registered. With the devm callback disabling the clk happens correctly only after devm_hwrng_register() is undone. As a result struct xgene_rng_dev::clk is only used in xgene_rng_probe, and so the struct member can be replaced by a local variable. Signed-off-by: Uwe Kleine-König --- drivers/char/hw_random/xgene-rng.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/drivers/char/hw_random/xgene-rng.c b/drivers/char/hw_random/xgene-rng.c index a6a30686a58b..31662614a48f 100644 --- a/drivers/char/hw_random/xgene-rng.c +++ b/drivers/char/hw_random/xgene-rng.c @@ -84,7 +84,6 @@ struct xgene_rng_dev { unsigned long failure_ts;/* First failure timestamp */ struct timer_list failure_timer; struct device *dev; - struct clk *clk; }; static void xgene_rng_expired_timer(struct timer_list *t) @@ -314,6 +313,7 @@ static struct hwrng xgene_rng_func = { static int xgene_rng_probe(struct platform_device *pdev) { struct xgene_rng_dev *ctx; + struct clk *clk; int rc = 0; ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); @@ -341,45 +341,30 @@ static int xgene_rng_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, rc, "Could not request RNG alarm IRQ\n"); /* Enable IP clock */ - ctx->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(ctx->clk)) { - dev_warn(&pdev->dev, "Couldn't get the clock for RNG\n"); - } else { - rc = clk_prepare_enable(ctx->clk); - if (rc) - return dev_err_probe(&pdev->dev, rc, - "clock prepare enable failed for RNG"); - } + clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(clk), "Couldn't get the clock for RNG\n"); xgene_rng_func.priv = (unsigned long) ctx; rc = devm_hwrng_register(&pdev->dev, &xgene_rng_func); - if (rc) { - if (!IS_ERR(ctx->clk)) - clk_disable_unprepare(ctx->clk); + if (rc) return dev_err_probe(&pdev->dev, rc, "RNG registering failed\n"); - } rc = device_init_wakeup(&pdev->dev, 1); - if (rc) { - if (!IS_ERR(ctx->clk)) - clk_disable_unprepare(ctx->clk); + if (rc) return dev_err_probe(&pdev->dev, rc, "RNG device_init_wakeup failed\n"); - } return 0; } static int xgene_rng_remove(struct platform_device *pdev) { - struct xgene_rng_dev *ctx = platform_get_drvdata(pdev); int rc; rc = device_init_wakeup(&pdev->dev, 0); if (rc) dev_err(&pdev->dev, "RNG init wakeup failed error %d\n", rc); - if (!IS_ERR(ctx->clk)) - clk_disable_unprepare(ctx->clk); return rc; } From patchwork Tue Feb 14 16:28:29 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: 13140511 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E942FC61DA4 for ; Tue, 14 Feb 2023 16:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbjBNQ3B (ORCPT ); Tue, 14 Feb 2023 11:29:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjBNQ3B (ORCPT ); Tue, 14 Feb 2023 11:29:01 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3BFB2310C for ; Tue, 14 Feb 2023 08:28:55 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRyAk-0007T3-Cd; Tue, 14 Feb 2023 17:28:50 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRyAh-004v9c-Ha; Tue, 14 Feb 2023 17:28:48 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRyAh-003WdU-NX; Tue, 14 Feb 2023 17:28:47 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Olivia Mackall , Herbert Xu Cc: linux-crypto@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 3/3] hwrng: xgene - Improve error reporting for problems during .remove() Date: Tue, 14 Feb 2023 17:28:29 +0100 Message-Id: <20230214162829.113148-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214162829.113148-1-u.kleine-koenig@pengutronix.de> References: <20230214162829.113148-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=925; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=PjWIM9Lsfu0YcMuZQ80fU/9ZSI4Cgm2a0fAuurNww64=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBj67aoPdLglbDwvfB0j1NW8FNdARIZNu9oKc9OK K1va6QnrKCJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY+u2qAAKCRDB/BR4rcrs CfCwB/0S0mf2y5bKJasCwpjE7zxf0zFzFBpeu+U45r5ktuU7Q6eJqnXkp2r6wK7a5BNJs9UlCCX IR05iptRZQxV/xfkDUC18srDCID9f+dXetPoo0JNX7LMnrdDM+HLni4TsH+IKc7QcJKDgQcI99M uowQ5/XJmdZGSy+tauHlGn08BLW7k99Och4Snsnat4sVe9wL/wd+8g9vmYt604glyvj+ZtJIHxD 1UztRK7Y1hp1HU/WOXgUwCQLcRo0gt4oBbRSi9lkFwtXuSOelObAhG/C0e9cweArja2XZ7quWU9 1iuBcwH6WfkPV398hgH4ytPkU4B0atdUVNguV4QeH/FACUCQ 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.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-crypto@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Returning an error value in a platform driver's remove callback results in a generic error message being emitted by the driver core, but otherwise it doesn't make a difference. The device goes away anyhow. As the driver already emits a better error message than the core, suppress the generic error message by returning zero unconditionally. Signed-off-by: Uwe Kleine-König --- drivers/char/hw_random/xgene-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/xgene-rng.c b/drivers/char/hw_random/xgene-rng.c index 31662614a48f..c67d3185b5b6 100644 --- a/drivers/char/hw_random/xgene-rng.c +++ b/drivers/char/hw_random/xgene-rng.c @@ -366,7 +366,7 @@ static int xgene_rng_remove(struct platform_device *pdev) if (rc) dev_err(&pdev->dev, "RNG init wakeup failed error %d\n", rc); - return rc; + return 0; } static const struct of_device_id xgene_rng_of_match[] = {