[PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove

André Apitzsch via B4 Relay posted 13 patches 12 months ago
[PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove
Posted by André Apitzsch via B4 Relay 12 months ago
From: André Apitzsch <git@apitzsch.eu>

The driver should disable or unprepare the clock on probe error and on
removing the module.

Remove regulator_bulk_disable(), because it is called by
imx214_power_off().

Acked-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: André Apitzsch <git@apitzsch.eu>
---
 drivers/media/i2c/imx214.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c
index 96d05acfeb66480770bb6291027dd023fdccb649..e8d35f8b0f8b57d64f03ff6f5ed9eac51a671e8e 100644
--- a/drivers/media/i2c/imx214.c
+++ b/drivers/media/i2c/imx214.c
@@ -1340,7 +1340,7 @@ static int imx214_probe(struct i2c_client *client)
 	v4l2_ctrl_handler_free(&imx214->ctrls);
 error_power_off:
 	pm_runtime_disable(imx214->dev);
-	regulator_bulk_disable(IMX214_NUM_SUPPLIES, imx214->supplies);
+	imx214_power_off(dev);
 
 	return ret;
 }
@@ -1356,6 +1356,8 @@ static void imx214_remove(struct i2c_client *client)
 	v4l2_ctrl_handler_free(&imx214->ctrls);
 
 	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev))
+		imx214_power_off(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
 }
 

-- 
2.47.1


Re: [PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove
Posted by Sakari Ailus 11 months, 1 week ago
Hi André,

Thanks for the update.

On Fri, Dec 20, 2024 at 02:26:11PM +0100, André Apitzsch via B4 Relay wrote:
> From: André Apitzsch <git@apitzsch.eu>
> 
> The driver should disable or unprepare the clock on probe error and on
> removing the module.
> 
> Remove regulator_bulk_disable(), because it is called by
> imx214_power_off().
> 
> Acked-by: Ricardo Ribalda <ribalda@chromium.org>
> Signed-off-by: André Apitzsch <git@apitzsch.eu>

This and the next one appear to be bugfixes. I think it'd be reasonable to
backport them. Any idea where this got broken, for the Fixes: tag? The bug
fixed by the last patch was probably introduced with the driver?

> ---
>  drivers/media/i2c/imx214.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c
> index 96d05acfeb66480770bb6291027dd023fdccb649..e8d35f8b0f8b57d64f03ff6f5ed9eac51a671e8e 100644
> --- a/drivers/media/i2c/imx214.c
> +++ b/drivers/media/i2c/imx214.c
> @@ -1340,7 +1340,7 @@ static int imx214_probe(struct i2c_client *client)
>  	v4l2_ctrl_handler_free(&imx214->ctrls);
>  error_power_off:
>  	pm_runtime_disable(imx214->dev);
> -	regulator_bulk_disable(IMX214_NUM_SUPPLIES, imx214->supplies);
> +	imx214_power_off(dev);
>  
>  	return ret;
>  }
> @@ -1356,6 +1356,8 @@ static void imx214_remove(struct i2c_client *client)
>  	v4l2_ctrl_handler_free(&imx214->ctrls);
>  
>  	pm_runtime_disable(&client->dev);
> +	if (!pm_runtime_status_suspended(&client->dev))
> +		imx214_power_off(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  }
>  
> 

-- 
Regards,

Sakari Ailus
Re: [PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove
Posted by André Apitzsch 11 months, 1 week ago
Hi Sakari,

Am Mittwoch, dem 08.01.2025 um 11:51 +0000 schrieb Sakari Ailus:
> Hi André,
> 
> Thanks for the update.
> 
> On Fri, Dec 20, 2024 at 02:26:11PM +0100, André Apitzsch via B4 Relay
> wrote:
> > From: André Apitzsch <git@apitzsch.eu>
> > 
> > The driver should disable or unprepare the clock on probe error and
> > on
> > removing the module.
> > 
> > Remove regulator_bulk_disable(), because it is called by
> > imx214_power_off().
> > 
> > Acked-by: Ricardo Ribalda <ribalda@chromium.org>
> > Signed-off-by: André Apitzsch <git@apitzsch.eu>
> 
> This and the next one appear to be bugfixes. I think it'd be
> reasonable to backport them. Any idea where this got broken, for the
> Fixes: tag?
> The bug fixed by the last patch was probably introduced with the
> driver?
> 

I think both, the missing imx214_power_off() and the wrong link
frequency where introduced with
> 436190596241 ("media: imx214: Add imx214 camera sensor driver")

The first one could also be considered as a fix for the incomplete
> 9bc92332cc3f ("media: imx214: Fix the error handling in imx214_probe()")

Shall I submit a new version with the Fixes: tag?

Regards,
André

> > ---
> >  drivers/media/i2c/imx214.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/i2c/imx214.c
> > b/drivers/media/i2c/imx214.c
> > index
> > 96d05acfeb66480770bb6291027dd023fdccb649..e8d35f8b0f8b57d64f03ff6f5
> > ed9eac51a671e8e 100644
> > --- a/drivers/media/i2c/imx214.c
> > +++ b/drivers/media/i2c/imx214.c
> > @@ -1340,7 +1340,7 @@ static int imx214_probe(struct i2c_client
> > *client)
> >  	v4l2_ctrl_handler_free(&imx214->ctrls);
> >  error_power_off:
> >  	pm_runtime_disable(imx214->dev);
> > -	regulator_bulk_disable(IMX214_NUM_SUPPLIES, imx214-
> > >supplies);
> > +	imx214_power_off(dev);
> >  
> >  	return ret;
> >  }
> > @@ -1356,6 +1356,8 @@ static void imx214_remove(struct i2c_client
> > *client)
> >  	v4l2_ctrl_handler_free(&imx214->ctrls);
> >  
> >  	pm_runtime_disable(&client->dev);
> > +	if (!pm_runtime_status_suspended(&client->dev))
> > +		imx214_power_off(&client->dev);
> >  	pm_runtime_set_suspended(&client->dev);
> >  }
> >  
> > 
> 
Re: [PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove
Posted by Sakari Ailus 11 months, 1 week ago
Hi André,

On Wed, Jan 08, 2025 at 10:46:51PM +0100, André Apitzsch wrote:
> Hi Sakari,
> 
> Am Mittwoch, dem 08.01.2025 um 11:51 +0000 schrieb Sakari Ailus:
> > Hi André,
> > 
> > Thanks for the update.
> > 
> > On Fri, Dec 20, 2024 at 02:26:11PM +0100, André Apitzsch via B4 Relay
> > wrote:
> > > From: André Apitzsch <git@apitzsch.eu>
> > > 
> > > The driver should disable or unprepare the clock on probe error and
> > > on
> > > removing the module.
> > > 
> > > Remove regulator_bulk_disable(), because it is called by
> > > imx214_power_off().
> > > 
> > > Acked-by: Ricardo Ribalda <ribalda@chromium.org>
> > > Signed-off-by: André Apitzsch <git@apitzsch.eu>
> > 
> > This and the next one appear to be bugfixes. I think it'd be
> > reasonable to backport them. Any idea where this got broken, for the
> > Fixes: tag?
> > The bug fixed by the last patch was probably introduced with the
> > driver?
> > 
> 
> I think both, the missing imx214_power_off() and the wrong link
> frequency where introduced with
> > 436190596241 ("media: imx214: Add imx214 camera sensor driver")
> 
> The first one could also be considered as a fix for the incomplete
> > 9bc92332cc3f ("media: imx214: Fix the error handling in imx214_probe()")

This one seems to have missed review. :-(

> 
> Shall I submit a new version with the Fixes: tag?

I checked the fix again and it seems the problem isn't as simple:
pm_runtime_idle() call leads to powering the device off. It needs to either
be resumed first or the call to imx214_power_off() be omitted.

I tried to find a good example but the few I found are buggy. :-( Getting
runtime PM right is just hard. I'll drop the last patch and post another to
address the problem (plus the intended example drivers) if you're fine with
that.

-- 
Kind regards,

Sakari Ailus
Re: [PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove
Posted by André Apitzsch 11 months, 1 week ago
Hi Sakari,

Am Donnerstag, dem 09.01.2025 um 08:59 +0000 schrieb Sakari Ailus:
> Hi André,
> 
> On Wed, Jan 08, 2025 at 10:46:51PM +0100, André Apitzsch wrote:
> > Hi Sakari,
> > 
> > Am Mittwoch, dem 08.01.2025 um 11:51 +0000 schrieb Sakari Ailus:
> > > Hi André,
> > > 
> > > Thanks for the update.
> > > 
> > > On Fri, Dec 20, 2024 at 02:26:11PM +0100, André Apitzsch via B4
> > > Relay
> > > wrote:
> > > > From: André Apitzsch <git@apitzsch.eu>
> > > > 
> > > > The driver should disable or unprepare the clock on probe error
> > > > and
> > > > on
> > > > removing the module.
> > > > 
> > > > Remove regulator_bulk_disable(), because it is called by
> > > > imx214_power_off().
> > > > 
> > > > Acked-by: Ricardo Ribalda <ribalda@chromium.org>
> > > > Signed-off-by: André Apitzsch <git@apitzsch.eu>
> > > 
> > > This and the next one appear to be bugfixes. I think it'd be
> > > reasonable to backport them. Any idea where this got broken, for
> > > the
> > > Fixes: tag?
> > > The bug fixed by the last patch was probably introduced with the
> > > driver?
> > > 
> > 
> > I think both, the missing imx214_power_off() and the wrong link
> > frequency where introduced with
> > > 436190596241 ("media: imx214: Add imx214 camera sensor driver")
> > 
> > The first one could also be considered as a fix for the incomplete
> > > 9bc92332cc3f ("media: imx214: Fix the error handling in
> > > imx214_probe()")
> 
> This one seems to have missed review. :-(
> 
> > 
> > Shall I submit a new version with the Fixes: tag?
> 
> I checked the fix again and it seems the problem isn't as simple:
> pm_runtime_idle() call leads to powering the device off. It needs to
> either be resumed first or the call to imx214_power_off() be omitted.
> 
> I tried to find a good example but the few I found are buggy. :-(
> Getting runtime PM right is just hard. I'll drop the last patch and
> post another to address the problem (plus the intended example
> drivers) if you're fine with that.
> 

Fine by me. Go ahead.

Regards,
André
Re: [PATCH v6 12/13] media: i2c: imx214: Fix clock handling on probe error or remove
Posted by Sakari Ailus 11 months, 1 week ago
On Thu, Jan 09, 2025 at 08:59:43AM +0000, Sakari Ailus wrote:
> I tried to find a good example but the few I found are buggy. :-( Getting
> runtime PM right is just hard. I'll drop the last patch and post another to

I meant to say this patch, not the last one.

-- 
Sakari Ailus