2023-11-15 11:15:04

by Jarkko Nikula

[permalink] [raw]
Subject: Re: [PATCH v3 02/25] i2c: designware: Fix PM calls order in dw_i2c_plat_probe()

On 11/10/23 20:11, Andy Shevchenko wrote:
> We should not mix managed calls with non-managed. This will break
> the calls order at the error path and ->remove() stages. Fix this
> by wrapping PM ops to become managed one.
>
> Fixes: 36d48fb5766a ("i2c: designware-platdrv: enable RuntimePM before registering to the core")
> Signed-off-by: Andy Shevchenko <[email protected]>

I fail to see what was broken in above commit and how this patch fixes it?

> ---
> drivers/i2c/busses/i2c-designware-platdrv.c | 28 ++++++++++++---------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
> index 855b698e99c0..8b0099e1bc26 100644
> --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> @@ -177,14 +177,26 @@ static int txgbe_i2c_request_regs(struct dw_i2c_dev *dev)
> return 0;
> }
>
> -static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
> +static void dw_i2c_plat_pm_cleanup(void *data)
> {
> + struct dw_i2c_dev *dev = data;
> +
> pm_runtime_disable(dev->dev);
>
> if (dev->shared_with_punit)
> pm_runtime_put_noidle(dev->dev);
> }
>
> +static int dw_i2c_plat_pm_setup(struct dw_i2c_dev *dev)
> +{
> + if (dev->shared_with_punit)
> + pm_runtime_get_noresume(dev->dev);
> +
> + pm_runtime_enable(dev->dev);
> +
> + return devm_add_action_or_reset(dev->dev, dw_i2c_plat_pm_cleanup, dev);
> +}
> +
> static int dw_i2c_plat_request_regs(struct dw_i2c_dev *dev)
> {
> struct platform_device *pdev = to_platform_device(dev->dev);
> @@ -381,19 +393,12 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
> pm_runtime_use_autosuspend(&pdev->dev);
> pm_runtime_set_active(&pdev->dev);
>
> - if (dev->shared_with_punit)
> - pm_runtime_get_noresume(&pdev->dev);
> -
> - pm_runtime_enable(&pdev->dev);
> -
> - ret = i2c_dw_probe(dev);
> + ret = dw_i2c_plat_pm_setup(dev);
> if (ret)
> - goto exit_probe;
> + goto exit_reset;
>
> - return ret;
> + return i2c_dw_probe(dev);
>
> -exit_probe:
> - dw_i2c_plat_pm_cleanup(dev);
> exit_reset:
> reset_control_assert(dev->rst);
> return ret;

Is it intended change the reset isn't asserted after this patch in case
i2c_dw_probe() fails?


2023-11-15 13:48:41

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v3 02/25] i2c: designware: Fix PM calls order in dw_i2c_plat_probe()

On Wed, Nov 15, 2023 at 01:14:36PM +0200, Jarkko Nikula wrote:
> On 11/10/23 20:11, Andy Shevchenko wrote:
> > We should not mix managed calls with non-managed. This will break
> > the calls order at the error path and ->remove() stages. Fix this
> > by wrapping PM ops to become managed one.
> >
> > Fixes: 36d48fb5766a ("i2c: designware-platdrv: enable RuntimePM before registering to the core")
> > Signed-off-by: Andy Shevchenko <[email protected]>
>
> I fail to see what was broken in above commit and how this patch fixes it?

The order of the unwiding probed flow is broken now as devm_*() mixed with
non-devm_*() calls. This makes all non-devm_*() calls that interleave devm_*()
ones to be also devm_*()-wrapped.

...

> Is it intended change the reset isn't asserted after this patch in case
> i2c_dw_probe() fails?

Did you miss that this is become managed with this patch and hence the above
is false scenario?

--
With Best Regards,
Andy Shevchenko


2023-11-15 13:51:47

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v3 02/25] i2c: designware: Fix PM calls order in dw_i2c_plat_probe()

On Wed, Nov 15, 2023 at 03:48:20PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 15, 2023 at 01:14:36PM +0200, Jarkko Nikula wrote:
> > On 11/10/23 20:11, Andy Shevchenko wrote:

...

> > Is it intended change the reset isn't asserted after this patch in case
> > i2c_dw_probe() fails?
>
> Did you miss that this is become managed with this patch and hence the above
> is false scenario?

Ah, I see now what you mean. Sorry, I though about next patch in mind.
Indeed, I need to amend this one.

--
With Best Regards,
Andy Shevchenko