Skip to content

Commit

Permalink
w1: mxc_w1: Enable clock before calling clk_get_rate() on it
Browse files Browse the repository at this point in the history
commit 955bc61 upstream.

According to the API, you may only call clk_get_rate() after actually
enabling it.

Found by Linux Driver Verification project (linuxtesting.org).

Fixes: a5fd913 ("w1: add 1-wire master driver for i.MX27 / i.MX31")
Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Stefan Potyra authored and gregkh committed Jul 3, 2018
1 parent e2f8857 commit 7d49aed
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions drivers/w1/masters/mxc_w1.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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,
Expand All @@ -126,12 +130,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);
Expand All @@ -147,8 +149,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;
}

Expand Down

0 comments on commit 7d49aed

Please sign in to comment.