Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Vidhu Sarwal <vidhu.linux@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	shreeya.patel@collabora.com, dlechner@baylibre.com,
	nuno.sa@analog.com, andy@kernel.org, skhan@linuxfoundation.org,
	linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path
Date: Sun, 19 Jul 2026 23:33:23 +0100	[thread overview]
Message-ID: <20260719233244.0a3fd246@jic23-huawei> (raw)
In-Reply-To: <alTb4-sg0ukY1aYI@ashevche-desk.local>

On Mon, 13 Jul 2026 15:36:51 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, Jul 13, 2026 at 07:58:29AM +0530, Vidhu Sarwal wrote:
> > ltrf216a_get_lux() acquires a runtime PM reference by calling
> > ltrf216a_set_power_state(data, true). However, if
> > ltrf216a_read_data() fails, the function returns immediately without
> > dropping the reference.
> > 
> > This leaves the runtime PM usage count unbalanced, preventing the device
> > from autosuspending after a failed read.
> > 
> > Fix this by releasing the runtime PM reference before returning from the
> > error path.  
> 
> ...
> 
> > static int ltrf216a_get_lux(struct ltrf216a_data *data)  
> 
> >  	greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
> > -	if (greendata < 0)
> > +	if (greendata < 0) {
> > +		ltrf216a_set_power_state(data, false);
> >  		return greendata;
> > +	}
> >  
> >  	ltrf216a_set_power_state(data, false);  
> 
> Wouldn't be simpler to do
> 
> 	greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
> 
> 	ltrf216a_set_power_state(data, false);
> 
> 	if (greendata < 0)
> 		return greendata;
> 
> ?
> 
> Not insisting on this. Up to Jonathan and others to decide.
I merged a slight variant on what Andy has here to keep the greendata
assignment and check closer together.

diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c
index aad96fc91565..dd8f3260b1d8 100644
--- a/drivers/iio/light/ltrf216a.c
+++ b/drivers/iio/light/ltrf216a.c
@@ -248,11 +248,10 @@ static int ltrf216a_get_lux(struct ltrf216a_data *data)
                return ret;
 
        greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
+       ltrf216a_set_power_state(data, false);
        if (greendata < 0)
                return greendata;
 
-       ltrf216a_set_power_state(data, false);
-
        lux = greendata * data->info->lux_multiplier * LTRF216A_WIN_FAC;
 
        return lux;




> 
> 


      reply	other threads:[~2026-07-19 22:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13  2:28 [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path Vidhu Sarwal
2026-07-13 12:28 ` Joshua Crofts
2026-07-13 12:36 ` Andy Shevchenko
2026-07-19 22:33   ` Jonathan Cameron [this message]

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=20260719233244.0a3fd246@jic23-huawei \
    --to=jonathan.cameron@oss.qualcomm.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=shreeya.patel@collabora.com \
    --cc=skhan@linuxfoundation.org \
    --cc=vidhu.linux@gmail.com \
    /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