From nobody Sat Apr 11 05:11:57 2026 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 C76CBC00140 for ; Mon, 15 Aug 2022 22:10:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346748AbiHOWJ7 (ORCPT ); Mon, 15 Aug 2022 18:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345784AbiHOWIN (ORCPT ); Mon, 15 Aug 2022 18:08:13 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28119118474; Mon, 15 Aug 2022 12:38:01 -0700 (PDT) Received: from dslb-188-096-143-237.188.096.pools.vodafone-ip.de ([188.96.143.237] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1oNfuO-000485-Fg; Mon, 15 Aug 2022 21:37:56 +0200 From: Martin Kaiser To: Herbert Xu , Olivia Mackall Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 1/2] hwrng: imx-rngc - use devm_clk_get_enabled Date: Mon, 15 Aug 2022 21:37:42 +0200 Message-Id: <20220815193743.105926-2-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815193743.105926-1-martin@kaiser.cx> References: <20220815193743.105926-1-martin@kaiser.cx> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the new devm_clk_get_enabled function to get our clock. We don't have to disable and unprepare the clock ourselves any more in error paths and in the remove function. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/imx-rngc.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx= -rngc.c index 4345df012d8f..23f490204341 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -245,7 +245,7 @@ static int imx_rngc_probe(struct platform_device *pdev) if (IS_ERR(rngc->base)) return PTR_ERR(rngc->base); =20 - rngc->clk =3D devm_clk_get(&pdev->dev, NULL); + rngc->clk =3D devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(rngc->clk)) { dev_err(&pdev->dev, "Can not get rng_clk\n"); return PTR_ERR(rngc->clk); @@ -255,26 +255,20 @@ static int imx_rngc_probe(struct platform_device *pde= v) if (irq < 0) return irq; =20 - ret =3D clk_prepare_enable(rngc->clk); - if (ret) - return ret; - ver_id =3D readl(rngc->base + RNGC_VER_ID); rng_type =3D ver_id >> RNGC_TYPE_SHIFT; /* * This driver supports only RNGC and RNGB. (There's a different * driver for RNGA.) */ - if (rng_type !=3D RNGC_TYPE_RNGC && rng_type !=3D RNGC_TYPE_RNGB) { - ret =3D -ENODEV; - goto err; - } + if (rng_type !=3D RNGC_TYPE_RNGC && rng_type !=3D RNGC_TYPE_RNGB) + return -ENODEV; =20 ret =3D devm_request_irq(&pdev->dev, irq, imx_rngc_irq, 0, pdev->name, (void *)rngc); if (ret) { dev_err(rngc->dev, "Can't get interrupt working.\n"); - goto err; + return ret; } =20 init_completion(&rngc->rng_op_done); @@ -294,14 +288,14 @@ static int imx_rngc_probe(struct platform_device *pde= v) ret =3D imx_rngc_self_test(rngc); if (ret) { dev_err(rngc->dev, "self test failed\n"); - goto err; + return ret; } } =20 ret =3D hwrng_register(&rngc->rng); if (ret) { dev_err(&pdev->dev, "hwrng registration failed\n"); - goto err; + return ret; } =20 dev_info(&pdev->dev, @@ -309,11 +303,6 @@ static int imx_rngc_probe(struct platform_device *pdev) rng_type =3D=3D RNGC_TYPE_RNGB ? 'B' : 'C', (ver_id >> RNGC_VER_MAJ_SHIFT) & 0xff, ver_id & 0xff); return 0; - -err: - clk_disable_unprepare(rngc->clk); - - return ret; } =20 static int __exit imx_rngc_remove(struct platform_device *pdev) @@ -322,8 +311,6 @@ static int __exit imx_rngc_remove(struct platform_devic= e *pdev) =20 hwrng_unregister(&rngc->rng); =20 - clk_disable_unprepare(rngc->clk); - return 0; } =20 --=20 2.30.2 From nobody Sat Apr 11 05:11:57 2026 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 A1FE4C19F2C for ; Mon, 15 Aug 2022 22:09:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343660AbiHOWJw (ORCPT ); Mon, 15 Aug 2022 18:09:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346748AbiHOWH7 (ORCPT ); Mon, 15 Aug 2022 18:07:59 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 118D3118471; Mon, 15 Aug 2022 12:38:01 -0700 (PDT) Received: from dslb-188-096-143-237.188.096.pools.vodafone-ip.de ([188.96.143.237] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1oNfuP-000485-S1; Mon, 15 Aug 2022 21:37:57 +0200 From: Martin Kaiser To: Herbert Xu , Olivia Mackall Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 2/2] hwrng: imx-rngc - use devres for hwrng registration Date: Mon, 15 Aug 2022 21:37:43 +0200 Message-Id: <20220815193743.105926-3-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815193743.105926-1-martin@kaiser.cx> References: <20220815193743.105926-1-martin@kaiser.cx> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace hwrng_register with devm_hwrng_register and let devres unregister our hwrng when the device is removed. It's possible to do this now that devres also handles clock disable+uprepare. When we had to disable+unprepare the clock ourselves, we had to unregister the hwrng before this and couldn't use devres. There's nothing left to do for imx_rngc_remove, this function can go. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/imx-rngc.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx= -rngc.c index 23f490204341..97d8dc931ca6 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -292,7 +292,7 @@ static int imx_rngc_probe(struct platform_device *pdev) } } =20 - ret =3D hwrng_register(&rngc->rng); + ret =3D devm_hwrng_register(&pdev->dev, &rngc->rng); if (ret) { dev_err(&pdev->dev, "hwrng registration failed\n"); return ret; @@ -305,15 +305,6 @@ static int imx_rngc_probe(struct platform_device *pdev) return 0; } =20 -static int __exit imx_rngc_remove(struct platform_device *pdev) -{ - struct imx_rngc *rngc =3D platform_get_drvdata(pdev); - - hwrng_unregister(&rngc->rng); - - return 0; -} - static int __maybe_unused imx_rngc_suspend(struct device *dev) { struct imx_rngc *rngc =3D dev_get_drvdata(dev); @@ -346,7 +337,6 @@ static struct platform_driver imx_rngc_driver =3D { .pm =3D &imx_rngc_pm_ops, .of_match_table =3D imx_rngc_dt_ids, }, - .remove =3D __exit_p(imx_rngc_remove), }; =20 module_platform_driver_probe(imx_rngc_driver, imx_rngc_probe); --=20 2.30.2