Skip to contentSkip to conversation

crypto/amlogic: Use devm APIs for clock management

PATCH In review Mohamad Raizudeen 2 participants 2 messages Sep 16 – Sep 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 crypto/amlogic: Use devm APIs for clock management

The driver currently gets the core clock and manually enables it using clk_prepare_enable(). This requires matching calls to clk_disable_unprepare() in the error paths and remove function.

Switch to devm_clk_get_enabled() instead. This lets the kernel handle enabling and disabling the clock automatically, which allow us to drop the manual cleanup code and keeps the probe function simple.

---
Changes in v4:
- Fix typo in meson_allocate_chanlist() function name.
- Add error_chanlist label to properly free chanlist if IRQ requests fail, preventing a memory leak.

Link to v3: https://lore.kernel.org/all/[email protected]/T/
Link to v2: https://lore.kernel.org/all/[email protected]/T/
Link to separate IRQ fix patch [1]: https://lore.kernel.org/all/[email protected]/T/

 drivers/crypto/amlogic/amlogic-gxl-core.c | 31 +++++++++--------------
 1 file changed, 12 insertions(+), 19 deletions(-)
drivers/crypto/amlogic/amlogic-gxl-core.c +12 -19
index 169c6eeb51e5..f292bb25674f 100644
@@ -243,34 +243,30 @@ static int meson_crypto_probe(struct platform_device *pdev)
 	if (IS_ERR(mc->base))
 		return PTR_ERR(mc->base);
 
-	mc->busclk = devm_clk_get(&pdev->dev, "blkmv");
+	mc->busclk = devm_clk_get_enabled(&pdev->dev, "blkmv");
 	if (IS_ERR(mc->busclk)) {
 		err = PTR_ERR(mc->busclk);
-		dev_err(&pdev->dev, "Cannot get core clock err=%d\n", err);
+		dev_err(&pdev->dev, "Cannot get/enable core clock err=%d\n", err);
 		return err;
 	}
 
+	err = meson_allocate_chanlist(mc);
+	if (err)
+		return err;
+
 	for (i = 0; i < MAXFLOW; i++) {
 		mc->irqs[i] = platform_get_irq(pdev, i);
-		if (mc->irqs[i] < 0)
-			return mc->irqs[i];
+		if (mc->irqs[i] < 0) {
+			err = mc->irqs[i];
+			goto error_chanlist;
+		}
 
 		err = devm_request_irq(&pdev->dev, mc->irqs[i], meson_irq_handler, 0,
 				       "gxl-crypto", mc);
 		if (err < 0)
-			return err;
-	}
-
-	err = clk_prepare_enable(mc->busclk);
-	if (err != 0) {
-		dev_err(&pdev->dev, "Cannot prepare_enable busclk\n");
-		return err;
+			goto error_chanlist;
 	}
 
-	err = meson_allocate_chanlist(mc);
-	if (err)
-		goto error_flow;
-
 	err = meson_register_algs(mc);
 	if (err)
 		goto error_alg;
@@ -289,9 +285,8 @@ static int meson_crypto_probe(struct platform_device *pdev)
 	return 0;
 error_alg:
 	meson_unregister_algs(mc);
+error_chanlist:
 	meson_free_chanlist(mc, MAXFLOW - 1);
-error_flow:
-	clk_disable_unprepare(mc->busclk);
 	return err;
 }
 
@@ -306,8 +301,6 @@ static void meson_crypto_remove(struct platform_device *pdev)
 	meson_unregister_algs(mc);
 
 	meson_free_chanlist(mc, MAXFLOW - 1);
-
-	clk_disable_unprepare(mc->busclk);
 }
 
 static const struct of_device_id meson_crypto_of_match_table[] = {
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 17 lines · Mohamad Raizudeen

The driver currently gets the core clock and manually enables it using clk_prepare_enable(). This requires matching calls to clk_disable_unprepare() in the error paths and remove function.

Switch to devm_clk_get_enabled() instead. This lets the kernel handle enabling and disabling the clock automatically, which allow us to drop the manual cleanup code and keeps the probe function simple.

---
Changes in v4:
- Fix typo in meson_allocate_chanlist() function name.
- Add error_chanlist label to properly free chanlist if IRQ requests fail, preventing a memory leak.

Quoted 6 lines

Link to v3: https://lore.kernel.org/all/[email protected]/T/
Link to v2: https://lore.kernel.org/all/[email protected]/T/
Link to separate IRQ fix patch [1]: https://lore.kernel.org/all/[email protected]/T/

 drivers/crypto/amlogic/amlogic-gxl-core.c | 31 +++++++++--------------
 1 file changed, 12 insertions(+), 19 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt