mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Martin Kepplinger <martin.kepplinger@puri.sm>,
	mchehab@kernel.org, kernel@puri.sm, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/2] media: hi846: fix usage of pm_runtime_get_if_in_use()
Date: Thu, 6 Apr 2023 04:33:38 +0300	[thread overview]
Message-ID: <20230406013338.GK9915@pendragon.ideasonboard.com> (raw)
In-Reply-To: <ZC1vJNIGeEu+xi+i@valkosipuli.retiisi.eu>

Hi Sakari,

On Wed, Apr 05, 2023 at 03:52:52PM +0300, Sakari Ailus wrote:
> On Wed, Apr 05, 2023 at 11:29:03AM +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, this can very well happen. And in such a case
> > the subsequent pm_runtime_put() call would result in a refcount underflow!
> 
> I think this issue should have a more generic solution, it's very difficult
> to address this in drivers only with the current APIs.
> 
> pm_runtime_get_if_in_use() will also return an error if runtime PM is
> disabled, so this patch will break the driver for that configuration.

I'm increasingly inclined to depend on CONFIG_PM for all camera sensor
drivers.

> > Fix it by correctly using pm_runtime_get_if_in_use().
> > 
> > Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> > ---
> >  drivers/media/i2c/hi846.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
> > index 5b5ea5425e984..0b0eda2e223cd 100644
> > --- a/drivers/media/i2c/hi846.c
> > +++ b/drivers/media/i2c/hi846.c
> > @@ -1544,7 +1544,7 @@ static int hi846_set_ctrl(struct v4l2_ctrl *ctrl)
> >  					 exposure_max);
> >  	}
> >  
> > -	if (!pm_runtime_get_if_in_use(&client->dev))
> > +	if (pm_runtime_get_if_in_use(&client->dev) <= 0)
> >  		return 0;
> >  
> >  	switch (ctrl->id) {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2023-04-06  1:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-05  9:29 [PATCH v1 0/2] media: hi846: support system suspend while streaming Martin Kepplinger
2023-04-05  9:29 ` [PATCH v1 1/2] media: hi846: fix usage of pm_runtime_get_if_in_use() Martin Kepplinger
2023-04-05 12:52   ` Sakari Ailus
2023-04-06  1:33     ` Laurent Pinchart [this message]
2023-04-06 13:36       ` Sakari Ailus
2023-04-07  4:32         ` Laurent Pinchart
2023-04-07 13:31     ` Martin Kepplinger
2023-04-07 18:37       ` Sakari Ailus
2023-04-06  1:32   ` Laurent Pinchart
2023-04-05  9:29 ` [PATCH v1 2/2] media: hi846: preserve the streaming state during system suspend Martin Kepplinger
2023-04-06  1:35   ` Laurent Pinchart
2023-04-11  9:39     ` Martin Kepplinger
2023-04-11 11:15       ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230406013338.GK9915@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=kernel@puri.sm \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=martin.kepplinger@puri.sm \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®