linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use()
@ 2023-04-25  9:47 Martin Kepplinger
  2023-05-16 13:22 ` Sakari Ailus
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Kepplinger @ 2023-04-25  9:47 UTC (permalink / raw)
  To: laurent.pinchart
  Cc: kernel, linux-kernel, linux-media, martin.kepplinger, mchehab,
	sakari.ailus

pm_runtime_get_if_in_use() does not only return nonzero values when
the device is in use, it can return a negative errno too.

And especially during resuming from system suspend, when runtime pm
is not yet up again, -EAGAIN is being returned, so the subsequent
pm_runtime_put() call results in a refcount underflow.

Fix system-resume by handling -EAGAIN of pm_runtime_get_if_in_use().

Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
---

revision history
----------------
v2 (thank you Sakari and Laurent):
* drop the other patch (the streaming-state in suspend/resume needs to
  be solved differently).
* Sakari pointed out that many drivers are affected by this and that
  runtime-pm might need changes instead. I think this patch doesn't hurt
  and could serve as a reminder to do so.

v1: initial submission:
https://lore.kernel.org/linux-media/20230405092904.1129395-1-martin.kepplinger@puri.sm/

 drivers/media/i2c/hi846.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
index 306dc35e925f..f8709cdf28b3 100644
--- a/drivers/media/i2c/hi846.c
+++ b/drivers/media/i2c/hi846.c
@@ -1353,7 +1353,8 @@ static int hi846_set_ctrl(struct v4l2_ctrl *ctrl)
 					 exposure_max);
 	}
 
-	if (!pm_runtime_get_if_in_use(&client->dev))
+	ret = pm_runtime_get_if_in_use(&client->dev);
+	if (!ret || ret == -EAGAIN)
 		return 0;
 
 	switch (ctrl->id) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use()
  2023-04-25  9:47 [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use() Martin Kepplinger
@ 2023-05-16 13:22 ` Sakari Ailus
  2023-05-23 10:07   ` Martin Kepplinger
  0 siblings, 1 reply; 4+ messages in thread
From: Sakari Ailus @ 2023-05-16 13:22 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: laurent.pinchart, kernel, linux-kernel, linux-media, mchehab

Hi Martin,

On Tue, Apr 25, 2023 at 11:47:47AM +0200, Martin Kepplinger wrote:
> pm_runtime_get_if_in_use() does not only return nonzero values when
> the device is in use, it can return a negative errno too.
> 
> And especially during resuming from system suspend, when runtime pm
> is not yet up again, -EAGAIN is being returned, so the subsequent
> pm_runtime_put() call results in a refcount underflow.
> 
> Fix system-resume by handling -EAGAIN of pm_runtime_get_if_in_use().
> 
> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> ---
> 
> revision history
> ----------------
> v2 (thank you Sakari and Laurent):
> * drop the other patch (the streaming-state in suspend/resume needs to
>   be solved differently).
> * Sakari pointed out that many drivers are affected by this and that
>   runtime-pm might need changes instead. I think this patch doesn't hurt
>   and could serve as a reminder to do so.

I guess it's appropriate to add:

Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846 8M pixel camera")

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use()
  2023-05-16 13:22 ` Sakari Ailus
@ 2023-05-23 10:07   ` Martin Kepplinger
  2023-05-29 20:40     ` Sakari Ailus
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Kepplinger @ 2023-05-23 10:07 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: laurent.pinchart, kernel, linux-kernel, linux-media, mchehab

Am Dienstag, dem 16.05.2023 um 16:22 +0300 schrieb Sakari Ailus:
> Hi Martin,
> 
> On Tue, Apr 25, 2023 at 11:47:47AM +0200, Martin Kepplinger wrote:
> > pm_runtime_get_if_in_use() does not only return nonzero values when
> > the device is in use, it can return a negative errno too.
> > 
> > And especially during resuming from system suspend, when runtime pm
> > is not yet up again, -EAGAIN is being returned, so the subsequent
> > pm_runtime_put() call results in a refcount underflow.
> > 
> > Fix system-resume by handling -EAGAIN of
> > pm_runtime_get_if_in_use().
> > 
> > Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> > ---
> > 
> > revision history
> > ----------------
> > v2 (thank you Sakari and Laurent):
> > * drop the other patch (the streaming-state in suspend/resume needs
> > to
> >   be solved differently).
> > * Sakari pointed out that many drivers are affected by this and
> > that
> >   runtime-pm might need changes instead. I think this patch doesn't
> > hurt
> >   and could serve as a reminder to do so.
> 
> I guess it's appropriate to add:
> 
> Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846
> 8M pixel camera")
> 

I agree. Feel free to do so when applying.

                            martin



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use()
  2023-05-23 10:07   ` Martin Kepplinger
@ 2023-05-29 20:40     ` Sakari Ailus
  0 siblings, 0 replies; 4+ messages in thread
From: Sakari Ailus @ 2023-05-29 20:40 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: laurent.pinchart, kernel, linux-kernel, linux-media, mchehab

On Tue, May 23, 2023 at 12:07:54PM +0200, Martin Kepplinger wrote:
> Am Dienstag, dem 16.05.2023 um 16:22 +0300 schrieb Sakari Ailus:
> > Hi Martin,
> > 
> > On Tue, Apr 25, 2023 at 11:47:47AM +0200, Martin Kepplinger wrote:
> > > pm_runtime_get_if_in_use() does not only return nonzero values when
> > > the device is in use, it can return a negative errno too.
> > > 
> > > And especially during resuming from system suspend, when runtime pm
> > > is not yet up again, -EAGAIN is being returned, so the subsequent
> > > pm_runtime_put() call results in a refcount underflow.
> > > 
> > > Fix system-resume by handling -EAGAIN of
> > > pm_runtime_get_if_in_use().
> > > 
> > > Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> > > ---
> > > 
> > > revision history
> > > ----------------
> > > v2 (thank you Sakari and Laurent):
> > > * drop the other patch (the streaming-state in suspend/resume needs
> > > to
> > >   be solved differently).
> > > * Sakari pointed out that many drivers are affected by this and
> > > that
> > >   runtime-pm might need changes instead. I think this patch doesn't
> > > hurt
> > >   and could serve as a reminder to do so.
> > 
> > I guess it's appropriate to add:
> > 
> > Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846
> > 8M pixel camera")
> > 
> 
> I agree. Feel free to do so when applying.

Done!

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-29 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-25  9:47 [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use() Martin Kepplinger
2023-05-16 13:22 ` Sakari Ailus
2023-05-23 10:07   ` Martin Kepplinger
2023-05-29 20:40     ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).