[PATCH] w1: mxc_w1: Use devm_clk_get_enabled() in mxc_w1_probe()

Uwe Kleine-König u.kleine-koenig at baylibre.com
Mon Nov 23 00:55:41 PST 2026


Hello,

On Sun, Nov 22, 2026 at 06:03:00PM +0100, Markus Elfring wrote:
> From: Markus Elfring <elfring at users.sourceforge.net>
> 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.
> 
> Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>

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.

> ---
>  drivers/w1/masters/mxc_w1.c | 20 ++++----------------
>  1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
> index 06be7bf0b715..f40ea120127c 100644
> --- a/drivers/w1/masters/mxc_w1.c
> +++ b/drivers/w1/masters/mxc_w1.c
> @@ -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;

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.

> -
> -out_disable_clk:
> -	clk_disable_unprepare(mdev->clk);
> -	return err;
>  }
>  
>  /*

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20261123/aec0d5f5/attachment-0001.sig>


More information about the linux-arm-kernel mailing list