Re: [PATCH v2] w1: mxc_w1: Enable clock before calling clk_get_rate() on it
From: Evgeniy Polyakov
Date: Tue May 08 2018 - 07:02:26 EST
Hi Stefan
02.05.2018, 11:55, "Stefan Potyra" <stefan.potyra@xxxxxxxxxxxxxx>:
> According to the API, you may only call clk_get_rate() after actually
> enabling it.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Fixes: a5fd9139f74c ("w1: add 1-wire master driver for i.MX27 / i.MX31")
> Signed-off-by: Stefan Potyra <Stefan.Potyra@xxxxxxxxxxxxxx>
Looks good to me, thank you!
Greg, please pull it into your tree, this also sounds like stable material, is it?
Acked-by: Evgeniy Polyakov <zbr@xxxxxxxxxxx>
> ---
> Âdrivers/w1/masters/mxc_w1.c | 20 +++++++++++++-------
> Â1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
> index 74f2e6e6202a..8851d441e5fd 100644
> --- a/drivers/w1/masters/mxc_w1.c
> +++ b/drivers/w1/masters/mxc_w1.c
> @@ -112,6 +112,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
> ÂÂÂÂÂÂÂÂÂ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,
> @@ -125,12 +129,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
>
> ÂÂÂÂÂÂÂÂÂres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> ÂÂÂÂÂÂÂÂÂmdev->regs = devm_ioremap_resource(&pdev->dev, res);
> - if (IS_ERR(mdev->regs))
> - return PTR_ERR(mdev->regs);
> -
> - err = clk_prepare_enable(mdev->clk);
> - if (err)
> - return err;
> + if (IS_ERR(mdev->regs)) {
> + err = PTR_ERR(mdev->regs);
> + goto out_disable_clk;
> + }
>
> ÂÂÂÂÂÂÂÂÂ/* Software reset 1-Wire module */
> ÂÂÂÂÂÂÂÂÂwriteb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);
> @@ -146,8 +148,12 @@ static int mxc_w1_probe(struct platform_device *pdev)
>
> ÂÂÂÂÂÂÂÂÂerr = w1_add_master_device(&mdev->bus_master);
> ÂÂÂÂÂÂÂÂÂif (err)
> - clk_disable_unprepare(mdev->clk);
> + goto out_disable_clk;
>
> + return 0;
> +
> +out_disable_clk:
> + clk_disable_unprepare(mdev->clk);
> ÂÂÂÂÂÂÂÂÂreturn err;
> Â}
>
> --
> 2.17.0