hwrng: pic32 - use devm_clk_get_enabled
authorMartin Kaiser <martin@kaiser.cx>
Tue, 4 Jul 2023 17:32:01 +0000 (19:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:42:31 +0000 (09:42 +0200)
[ Upstream commit 6755ad74aac0fb1c79b14724feb81b2f6ff25847 ]

Use devm_clk_get_enabled in the pic32 driver. Ensure that the clock is
enabled as long as the driver is registered with the hwrng core.

Fixes: 7ea39973d1e5 ("hwrng: pic32 - Use device-managed registration API")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/hw_random/pic32-rng.c

index 99c8bd0859a1487cfe933e9e9309d82cafc07b90..e04a054e89307e0b03973e146300f531f396c9a8 100644 (file)
@@ -36,7 +36,6 @@
 struct pic32_rng {
        void __iomem    *base;
        struct hwrng    rng;
-       struct clk      *clk;
 };
 
 /*
@@ -70,6 +69,7 @@ static int pic32_rng_read(struct hwrng *rng, void *buf, size_t max,
 static int pic32_rng_probe(struct platform_device *pdev)
 {
        struct pic32_rng *priv;
+       struct clk *clk;
        u32 v;
        int ret;
 
@@ -81,13 +81,9 @@ static int pic32_rng_probe(struct platform_device *pdev)
        if (IS_ERR(priv->base))
                return PTR_ERR(priv->base);
 
-       priv->clk = devm_clk_get(&pdev->dev, NULL);
-       if (IS_ERR(priv->clk))
-               return PTR_ERR(priv->clk);
-
-       ret = clk_prepare_enable(priv->clk);
-       if (ret)
-               return ret;
+       clk = devm_clk_get_enabled(&pdev->dev, NULL);
+       if (IS_ERR(clk))
+               return PTR_ERR(clk);
 
        /* enable TRNG in enhanced mode */
        v = TRNGEN | TRNGMOD;
@@ -98,15 +94,11 @@ static int pic32_rng_probe(struct platform_device *pdev)
 
        ret = devm_hwrng_register(&pdev->dev, &priv->rng);
        if (ret)
-               goto err_register;
+               return ret;
 
        platform_set_drvdata(pdev, priv);
 
        return 0;
-
-err_register:
-       clk_disable_unprepare(priv->clk);
-       return ret;
 }
 
 static int pic32_rng_remove(struct platform_device *pdev)
@@ -114,7 +106,6 @@ static int pic32_rng_remove(struct platform_device *pdev)
        struct pic32_rng *rng = platform_get_drvdata(pdev);
 
        writel(0, rng->base + RNGCON);
-       clk_disable_unprepare(rng->clk);
        return 0;
 }