Re: [PATCH 2/4] i2c: designware-platdrv: fix unbalanced clk enable and prepare

From: Jisheng Zhang
Date: Wed Apr 20 2016 - 22:46:26 EST


Dear Jarkko, Andy,

On Wed, 20 Apr 2016 17:16:00 +0300 Andy Shevchenko wrote:

> On Wed, 2016-04-20 at 15:55 +0300, Jarkko Nikula wrote:
> > On 04/14/2016 03:53 PM, Jisheng Zhang wrote:
> > >
> > > If i2c_dw_probe() fail, we should call i2c_dw_plat_prepare_clk() to
> > > disable and unprepare the clk, otherwise the clk enable and prepare
> > > is left unbalanced.
> > >
> > > Signed-off-by: Jisheng Zhang <jszhang@xxxxxxxxxxx>
> > > ---
> > > Â drivers/i2c/busses/i2c-designware-platdrv.c | 2 ++
> > > Â 1 file changed, 2 insertions(+)
> > >
> > > diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c
> > > b/drivers/i2c/busses/i2c-designware-platdrv.c
> > > index 00f9e99..1488cea 100644
> > > --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> > > +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> > > @@ -268,6 +268,8 @@ rpm_disable:
> > > ÂÂ pm_runtime_put_noidle(&pdev->dev);
> > > ÂÂ }
> > >
> > > + i2c_dw_plat_prepare_clk(dev, false);
> > > +
> > > ÂÂ return r;
> > > Â }
> > >
> > This is a bit unclear to me does devm_clk_get take care of clk
> > disablingÂ
> > in case of probe error or driver removal?
> >
> > I see Andy's 1cb715ca4694 ("i2c-designware: move to managed functionsÂ
> > (devm_*)") removed it but at quick look drivers/clk/clk-devres.c:Â
> > devm_clk_release() calls only clk_put and I don't see disable is doneÂ
> > down the path.
>
> The following is a mistake of the mentioned patch.
> -ÂÂÂÂÂÂÂclk_disable_unprepare(dev->clk);
>
> I did at the same mistake in dw_dmac driver which had been fixed later
> in the commit 8be4f523b480 ("dmaengine: dw: fix regression in dw_probe()
> function").
>

As Andy pointed out, managed devm_clk_get can only automatically put clk
but doesn't unprepare and disable the clk

Thanks,
Jisheng