Re: [PATCH v2 1/2] mfd: intel_quark_i2c_gpio: remove clock tree on error path

From: Lee Jones
Date: Wed Mar 16 2016 - 04:47:12 EST


On Thu, 10 Mar 2016, Andy Shevchenko wrote:

> On Fri, 2016-02-19 at 10:42 +0200, Andy Shevchenko wrote:
> > There is a potential resource leak in case when ->probe() fails. We
> > have to
> > unregister and remove clock tree which is done here.
> >
> > This is a follow up to previously pushed commit c4726abce63b ("mfd:
> > intel_quark_i2c_gpio: Use clkdev_create()") that prevents double
> > free() when
> > clkdev_drop() followed by kfree() in devm_kcalloc() release stage.
> >
> > I leave Fixes tag here, but the backporting will require to backport
> > the commit
> > c4726abce63b ("mfd: intel_quark_i2c_gpio: Use clkdev_create()")
> > first.
>
> Lee, ping?

Pings don't serve any purpose but to irritate. This patch hasn't
been forgotten, it's in the pile.

The last few weeks have been pretty crazy. Please bear with me while I
play catch-up.

> > Fixes: 60ae5b9f5cdd (mfd: intel_quark_i2c_gpio: Add Intel Quark X1000
> > I2C-GPIO MFD Driver)
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> > ---
> > v2:
> > - do not unregister clock before lookup (Stephen)
> > Âdrivers/mfd/intel_quark_i2c_gpio.c | 25 +++++++++++++++++--------
> > Â1 file changed, 17 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/mfd/intel_quark_i2c_gpio.c
> > b/drivers/mfd/intel_quark_i2c_gpio.c
> > index bdc5e27..7450f5d 100644
> > --- a/drivers/mfd/intel_quark_i2c_gpio.c
> > +++ b/drivers/mfd/intel_quark_i2c_gpio.c
> > @@ -139,6 +139,7 @@ static int intel_quark_register_i2c_clk(struct
> > intel_quark_mfd *quark_mfd)
> > Â INTEL_QUARK_I2C_CONT
> > ROLLER_CLK);
> > Â
> > Â if (!quark_mfd->i2c_clk_lookup) {
> > + clk_unregister(quark_mfd->i2c_clk);
> > Â dev_err(&pdev->dev, "Fixed clk register failed\n");
> > Â return -ENOMEM;
> > Â }
> > @@ -150,7 +151,7 @@ static void intel_quark_unregister_i2c_clk(struct
> > pci_dev *pdev)
> > Â{
> > Â struct intel_quark_mfd *quark_mfd = dev_get_drvdata(&pdev-
> > >dev);
> > Â
> > - if (!quark_mfd->i2c_clk || !quark_mfd->i2c_clk_lookup)
> > + if (!quark_mfd->i2c_clk_lookup)
> > Â return;
> > Â
> > Â clkdev_drop(quark_mfd->i2c_clk_lookup);
> > @@ -246,25 +247,33 @@ static int intel_quark_mfd_probe(struct pci_dev
> > *pdev,
> > Â quark_mfd = devm_kzalloc(&pdev->dev, sizeof(*quark_mfd),
> > GFP_KERNEL);
> > Â if (!quark_mfd)
> > Â return -ENOMEM;
> > +
> > Â quark_mfd->pdev = pdev;
> > + dev_set_drvdata(&pdev->dev, quark_mfd);
> > Â
> > Â ret = intel_quark_register_i2c_clk(quark_mfd);
> > Â if (ret)
> > Â return ret;
> > Â
> > - dev_set_drvdata(&pdev->dev, quark_mfd);
> > -
> > Â ret = intel_quark_i2c_setup(pdev,
> > &intel_quark_mfd_cells[1]);
> > Â if (ret)
> > - return ret;
> > + goto err_unregister_i2c_clk;
> > Â
> > Â ret = intel_quark_gpio_setup(pdev,
> > &intel_quark_mfd_cells[0]);
> > Â if (ret)
> > - return ret;
> > + goto err_unregister_i2c_clk;
> > Â
> > - return mfd_add_devices(&pdev->dev, 0, intel_quark_mfd_cells,
> > - ÂÂÂÂÂÂÂARRAY_SIZE(intel_quark_mfd_cells),
> > NULL, 0,
> > - ÂÂÂÂÂÂÂNULL);
> > + ret = mfd_add_devices(&pdev->dev, 0, intel_quark_mfd_cells,
> > + ÂÂÂÂÂÂARRAY_SIZE(intel_quark_mfd_cells),
> > NULL, 0,
> > + ÂÂÂÂÂÂNULL);
> > + if (ret)
> > + goto err_unregister_i2c_clk;
> > +
> > + return 0;
> > +
> > +err_unregister_i2c_clk:
> > + intel_quark_unregister_i2c_clk(pdev);
> > + return ret;
> > Â}
> > Â
> > Âstatic void intel_quark_mfd_remove(struct pci_dev *pdev)
>

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org â Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog