* [PATCH] i2c: busses: Fix error handling in synquacer_i2c_probe
@ 2022-03-16 6:47 Miaoqian Lin
[not found] ` <CAHp75Veae=8Ev-xU3zbVYh=AxbAPFayZD3MeRSrAGNNZ8LMBPg@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Miaoqian Lin @ 2022-03-16 6:47 UTC (permalink / raw)
To: Ard Biesheuvel, Andy Shevchenko, Wolfram Sang, linux-i2c, linux-kernel
Cc: linmq006
In the error handling path, the clk_prepare_enable() function
call should be balanced by a corresponding 'clk_disable_unprepare()'
call, as already done in the remove function.
Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C controller")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/i2c/busses/i2c-synquacer.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index e4026c5416b1..cd955224d629 100644
--- a/drivers/i2c/busses/i2c-synquacer.c
+++ b/drivers/i2c/busses/i2c-synquacer.c
@@ -569,22 +569,27 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE) {
dev_err(&pdev->dev, "PCLK missing or out of range (%d)\n",
i2c->pclkrate);
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_disable_clk;
}
i2c->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(i2c->base))
- return PTR_ERR(i2c->base);
+ if (IS_ERR(i2c->base)) {
+ ret = PTR_ERR(i2c->base);
+ goto err_disable_clk;
+ }
i2c->irq = platform_get_irq(pdev, 0);
- if (i2c->irq < 0)
- return i2c->irq;
+ if (i2c->irq < 0) {
+ ret = i2c->irq;
+ goto err_disable_clk;
+ }
ret = devm_request_irq(&pdev->dev, i2c->irq, synquacer_i2c_isr,
0, dev_name(&pdev->dev), i2c);
if (ret < 0) {
dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
- return ret;
+ goto err_disable_clk;
}
i2c->state = STATE_IDLE;
@@ -607,7 +612,7 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
ret = i2c_add_numbered_adapter(&i2c->adapter);
if (ret) {
dev_err(&pdev->dev, "failed to add bus to i2c core\n");
- return ret;
+ goto err_disable_clk;
}
platform_set_drvdata(pdev, i2c);
@@ -616,6 +621,11 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
dev_name(&i2c->adapter.dev));
return 0;
+
+err_disable_clk:
+ if (!IS_ERR(i2c->pclk))
+ clk_disable_unprepare(i2c->pclk);
+ return ret;
}
static int synquacer_i2c_remove(struct platform_device *pdev)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: busses: Fix error handling in synquacer_i2c_probe
[not found] ` <CAHp75Veae=8Ev-xU3zbVYh=AxbAPFayZD3MeRSrAGNNZ8LMBPg@mail.gmail.com>
@ 2022-03-16 7:18 ` Miaoqian Lin
2022-03-16 15:42 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Miaoqian Lin @ 2022-03-16 7:18 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Ard Biesheuvel, Wolfram Sang, linux-i2c, linux-kernel
Hi, Andy Shevchenko
On Wed, Mar 16, 2022 at 09:04:06AM +0200, Andy Shevchenko wrote:
>
> > In the error handling path, the clk_prepare_enable() function
> > call should be balanced by a corresponding 'clk_disable_unprepare()'
> > call, as already done in the remove function.
>
>
> It’s not good to mix devm approach with non-devm.
>
Thanks for your review. I'm sorry, I don't quite understand. Could you please explain more? What functions are your referring to? Thanks.
>
> >
> > Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C
> > controller")
> > Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> > ---
> > drivers/i2c/busses/i2c-synquacer.c | 24 +++++++++++++++++-------
> > 1 file changed, 17 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-
> > synquacer.c
> > index e4026c5416b1..cd955224d629 100644
> > --- a/drivers/i2c/busses/i2c-synquacer.c
> > +++ b/drivers/i2c/busses/i2c-synquacer.c
> > @@ -569,22 +569,27 @@ static int synquacer_i2c_probe(struct
> > platform_device *pdev)
> > i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE) {
> > dev_err(&pdev->dev, "PCLK missing or out of range (%d)\n",
> > i2c->pclkrate);
> > - return -EINVAL;
> > + ret = -EINVAL;
> > + goto err_disable_clk;
> > }
> >
> > i2c->base = devm_platform_ioremap_resource(pdev, 0);
> > - if (IS_ERR(i2c->base))
> > - return PTR_ERR(i2c->base);
> > + if (IS_ERR(i2c->base)) {
> > + ret = PTR_ERR(i2c->base);
> > + goto err_disable_clk;
> > + }
> >
> > i2c->irq = platform_get_irq(pdev, 0);
> > - if (i2c->irq < 0)
> > - return i2c->irq;
> > + if (i2c->irq < 0) {
> > + ret = i2c->irq;
> > + goto err_disable_clk;
> > + }
> >
> > ret = devm_request_irq(&pdev->dev, i2c->irq, synquacer_i2c_isr,
> > 0, dev_name(&pdev->dev), i2c);
> > if (ret < 0) {
> > dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
> > - return ret;
> > + goto err_disable_clk;
> > }
> >
> > i2c->state = STATE_IDLE;
> > @@ -607,7 +612,7 @@ static int synquacer_i2c_probe(struct platform_device
> > *pdev)
> > ret = i2c_add_numbered_adapter(&i2c->adapter);
> > if (ret) {
> > dev_err(&pdev->dev, "failed to add bus to i2c core\n");
> > - return ret;
> > + goto err_disable_clk;
> > }
> >
> > platform_set_drvdata(pdev, i2c);
> > @@ -616,6 +621,11 @@ static int synquacer_i2c_probe(struct platform_device
> > *pdev)
> > dev_name(&i2c->adapter.dev));
> >
> > return 0;
> > +
> > +err_disable_clk:
> > + if (!IS_ERR(i2c->pclk))
> > + clk_disable_unprepare(i2c->pclk);
> > + return ret;
> > }
> >
> > static int synquacer_i2c_remove(struct platform_device *pdev)
> > --
> > 2.17.1
> >
> >
>
> --
> With Best Regards,
> Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: busses: Fix error handling in synquacer_i2c_probe
2022-03-16 7:18 ` Miaoqian Lin
@ 2022-03-16 15:42 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-03-16 15:42 UTC (permalink / raw)
To: Miaoqian Lin; +Cc: Ard Biesheuvel, Wolfram Sang, linux-i2c, linux-kernel
On Wed, Mar 16, 2022 at 9:18 AM Miaoqian Lin <linmq006@gmail.com> wrote:
>
> Hi, Andy Shevchenko
>
> On Wed, Mar 16, 2022 at 09:04:06AM +0200, Andy Shevchenko wrote:
> >
> > > In the error handling path, the clk_prepare_enable() function
> > > call should be balanced by a corresponding 'clk_disable_unprepare()'
> > > call, as already done in the remove function.
> >
> >
> > It’s not good to mix devm approach with non-devm.
> >
> Thanks for your review. I'm sorry, I don't quite understand. Could you please explain more? What functions are your referring to? Thanks.
Your entire patch is broken. The error handling in ->probe() and
complete ->remove() now have asymmetrical ordering.
On top of that the CCF is NULL aware (and error pointer IIRC), so no
need to have additional checks.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-16 15:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 6:47 [PATCH] i2c: busses: Fix error handling in synquacer_i2c_probe Miaoqian Lin
[not found] ` <CAHp75Veae=8Ev-xU3zbVYh=AxbAPFayZD3MeRSrAGNNZ8LMBPg@mail.gmail.com>
2022-03-16 7:18 ` Miaoqian Lin
2022-03-16 15:42 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.