Skip to contentSkip to conversation

w1: mxc_w1: Use devm_clk_get_enabled() in mxc_w1_probe()

PATCH In review Markus Elfring 2 participants 3 messages Nov 22 – Nov 23

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

PATCH 1/1 w1: mxc_w1: Use devm_clk_get_enabled() in mxc_w1_probe()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Nov 2026 17:52:20 +0100

* Reuse existing functionality from devm_clk_get_enabled() instead of keeping duplicate source code.

* Omit a clk_disable_unprepare() call on an error handling path and in the implementation of the function “mxc_w1_remove”.

* Delete the label “out_disable_clk”.

This issue was detected by using the Coccinelle software.

---
 drivers/w1/masters/mxc_w1.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/w1/masters/mxc_w1.c +4 -16
index 06be7bf0b715..f40ea120127c 100644
@@ -98,14 +98,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (!mdev)
 		return -ENOMEM;
 
-	mdev->clk = devm_clk_get(&pdev->dev, NULL);
+	mdev->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
-	err = clk_prepare_enable(mdev->clk);
-	if (err)
-		return err;
-
 	clkrate = clk_get_rate(mdev->clk);
 	if (clkrate < 10000000)
 		dev_warn(&pdev->dev,
@@ -118,10 +114,8 @@ static int mxc_w1_probe(struct platform_device *pdev)
 			 "Incorrect time base frequency %lu Hz\n", clkrate);
 
 	mdev->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(mdev->regs)) {
-		err = PTR_ERR(mdev->regs);
-		goto out_disable_clk;
-	}
+	if (IS_ERR(mdev->regs))
+		return PTR_ERR(mdev->regs);
 
 	/* Software reset 1-Wire module */
 	writeb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);
@@ -137,13 +131,9 @@ static int mxc_w1_probe(struct platform_device *pdev)
 
 	err = w1_add_master_device(&mdev->bus_master);
 	if (err)
-		goto out_disable_clk;
+		return err;
 
 	return 0;
-
-out_disable_clk:
-	clk_disable_unprepare(mdev->clk);
-	return err;
 }
 
 /*
@@ -154,8 +144,6 @@ static void mxc_w1_remove(struct platform_device *pdev)
 	struct mxc_w1_device *mdev = platform_get_drvdata(pdev);
 
 	w1_remove_master_device(&mdev->bus_master);
-
-	clk_disable_unprepare(mdev->clk);
 }
 
 static const struct of_device_id mxc_w1_dt_ids[] = {
Signature · 1 line
2.56.1
#1 lore raw

Hello,

Quoted 6 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Nov 2026 17:52:20 +0100

* Reuse existing functionality from devm_clk_get_enabled() instead of keeping duplicate source code.

Quoted 8 lines

* Omit a clk_disable_unprepare() call on an error handling path and in the implementation of the function “mxc_w1_remove”.

* Delete the label “out_disable_clk”.

This issue was detected by using the Coccinelle software.

Not a big issue, but for me the commit log is too detailed, most of the things mentioned here are trivially visible from the patch. So I'd just write:

w1: mxc_w1: Simplify probe routine using devm_clk_get_enabled()

devm_clk_get_enabled() combines the functionality of devm_clk_get() and clk_prepare_enable() with an automatic cleanup callback registered to disable the clock in the error paths and at unbind time.

Simplify accordingly.

Quoted 38 lines
---
 drivers/w1/masters/mxc_w1.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/w1/masters/mxc_w1.c +3 -9
index 06be7bf0b715..f40ea120127c 100644
@@ -98,14 +98,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (!mdev)
 		return -ENOMEM;
 
-	mdev->clk = devm_clk_get(&pdev->dev, NULL);
+	mdev->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
-	err = clk_prepare_enable(mdev->clk);
-	if (err)
-		return err;
-
 	clkrate = clk_get_rate(mdev->clk);
 	if (clkrate < 10000000)
 		dev_warn(&pdev->dev,
@@ -118,10 +114,8 @@ static int mxc_w1_probe(struct platform_device *pdev)
 			 "Incorrect time base frequency %lu Hz\n", clkrate);
 
 	mdev->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(mdev->regs)) {
-		err = PTR_ERR(mdev->regs);
-		goto out_disable_clk;
-	}
+	if (IS_ERR(mdev->regs))
+		return PTR_ERR(mdev->regs);
 
 	/* Software reset 1-Wire module */
 	writeb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);

drivers/w1/masters/mxc_w1.c static int mxc_w1_probe(struct platform_device *pdev) · line 136

Quoted 7 lines
drivers/w1/masters/mxc_w1.c +1 -1
@@ -137,13 +131,9 @@ static int mxc_w1_probe(struct platform_device *pdev)
 
 	err = w1_add_master_device(&mdev->bus_master);
 	if (err)
-		goto out_disable_clk;
+		return err;
 
 	return 0;

This can be shortend to

	return w1_add_master_device(....);

. Looking at w1_add_master_device() there are error paths that don't emit an error message, not sure they are all -ENOMEM. dev_err_probe() wouldn't hurt.

drivers/w1/masters/mxc_w1.c static int mxc_w1_probe(struct platform_device *pdev) · line 139

Quoted 7 lines
drivers/w1/masters/mxc_w1.c +0 -4
-
-out_disable_clk:
-	clk_disable_unprepare(mdev->clk);
-	return err;
 }
 
 /*

Best regards
Uwe

#2 lore raw
Quoted 4 lines

Not a big issue, but for me the commit log is too detailed, most of the things mentioned here are trivially visible from the patch. So I'd just write:

Quoted 8 lines

w1: mxc_w1: Simplify probe routine using devm_clk_get_enabled()

devm_clk_get_enabled() combines the functionality of devm_clk_get() and clk_prepare_enable() with an automatic cleanup callback registered to disable the clock in the error paths and at unbind time.

Simplify accordingly.

How will the wording preferences evolve further for such change descriptions?

Regards,
Markus