mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Joshua Crofts <joshua.crofts1@gmail.com>
Cc: "Cong Nguyen" <congnt264@gmail.com>,
	"Matt Ranostay" <mranostay@gmail.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: proximity: pulsedlight: fix iio_device left registered on PM setup failure
Date: Sun, 30 Aug 2026 00:48:32 +0100	[thread overview]
Message-ID: <20260830004832.357df308@jic23-huawei> (raw)
In-Reply-To: <20260829183443.3b5ac19f@systembl0wer>

On Sat, 29 Aug 2026 18:34:43 +0200
Joshua Crofts <joshua.crofts1@gmail.com> wrote:

> On Fri, 28 Aug 2026 17:59:09 +0700
> Cong Nguyen <congnt264@gmail.com> wrote:
> 
> > pm_runtime_set_active() failing in probe() jumps to error_unreg_buffer,
> > which only calls iio_triggered_buffer_cleanup() -- it does not undo the
> > iio_device_register() that already succeeded a few lines above. probe()
> > then returns the error, the devm-managed indio_dev is freed, but the
> > iio core still has it registered: the sysfs/chardev nodes stay live and
> > point at freed memory.
> > 
> > Add an error_unreg_dev label that unregisters the iio device before
> > falling through to the existing buffer cleanup, mirroring the teardown
> > order already used in lidar_remove().
> > 
> > Fixes: 4ac4e086fd8c ("iio: pulsedlight-lidar-lite: add runtime PM")
> > Assisted-by: Claude:claude-opus-4
> > Signed-off-by: Cong Nguyen <congnt264@gmail.com>
> > ---
> >  drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > index 400477b4c740..8a9ee21f2bf6 100644
> > --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > @@ -294,12 +294,14 @@ static int lidar_probe(struct i2c_client *client)
> >  
> >  	ret = pm_runtime_set_active(&client->dev);
> >  	if (ret)
> > -		goto error_unreg_buffer;
> > +		goto error_unreg_dev;
> >  	pm_runtime_enable(&client->dev);
> >  	pm_runtime_idle(&client->dev);
> >  
> >  	return 0;  
> 
> Hmm, you should just return iio_device_register() here instead of 0,
> as that should always be the last function called in any *_probe()
> function.
> 
> No need to add a new label then.
Lets keep this fix minimal.  Agreed that it gets interesting
if runtime pm is enabled only after the userspace interfaces
are exposed, but we'd need to find if there is actual bug to
'fix' it as opposed to moving to a easier to understand flow.

So applied this one to the fixes-togreg branch of iio.git

Thanks,

Jonathan

> 
> > +error_unreg_dev:
> > +	iio_device_unregister(indio_dev);
> >  error_unreg_buffer:
> >  	iio_triggered_buffer_cleanup(indio_dev);
> >    
> 


      reply	other threads:[~2026-08-29 23:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 10:59 Cong Nguyen
2026-08-29 16:34 ` Joshua Crofts
2026-08-29 23:48   ` 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=20260830004832.357df308@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=congnt264@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=joshua.crofts1@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®