lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250806161801.000061c0@huawei.com>
Date: Wed, 6 Aug 2025 16:18:01 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Andy Shevchenko <andy.shevchenko@...il.com>
CC: Akshay Jindal <akshayaj.lkd@...il.com>, <anshulusr@...il.com>,
	<jic23@...nel.org>, <dlechner@...libre.com>, <nuno.sa@...log.com>,
	<andy@...nel.org>, <shuah@...nel.org>, <linux-iio@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] iio: light: ltr390: Add remove callback with needed
 support in device registration

On Tue, 5 Aug 2025 14:47:32 +0200
Andy Shevchenko <andy.shevchenko@...il.com> wrote:

> On Tue, Aug 5, 2025 at 6:05 AM Akshay Jindal <akshayaj.lkd@...il.com> wrote:
> >
> > On Tue, Aug 5, 2025 at 2:36 AM Andy Shevchenko
> > <andy.shevchenko@...il.com> wrote:  
> > >
> > > Doesn't sound right to me. HAve you investigated PM runtime paths?  
> > Yes I did investigate and found that PM runtime->suspend() callback
> > co-exists with remove callback.
> >  
> > > Looking at what the code you added there it sounds to me like a part
> > > of PM runtime ->suspend() callback.  
> > Yes, part of functionality will always be common, because both the
> > callback implementations put
> > the device into powered down or low power state which is what has been done here
> > Both _suspend() and remove are called at different times in the lifecycle of the
> > driver, but with respect to register setting, they put the device into
> > power down state.  
> 
> Are you sure about the remove stage and how it interacts with runtime
> PM? Please, check how the device driver core manages PM on the remove
> stage.
> 
> > Additionally .remove() can have code for:
> > 1. disable runtime power management (if enabled while device registration).  
> 
> If the device core enables it for you, it will disable it
> symmetrically. I don't see the issue here, it should be done
> automatically. If you do that explicitly, use the respective
> devm_pm_runtime_*() call.
> 
> > 2. device cleanup (disabling interrupt and cleaning up other configs done).  
> 
> Wrap them into devm if required.
> 
> > 2. unregister the device.  
> 
> Already done in the original code which your patch reverts, why?
> 
> > For eg: another light sensor bh1750
> > static void bh1750_remove(struct i2c_client *client)
> > {
> >     iio_device_unregister(indio_dev);
> >     mutex_lock(&data->lock);
> >     i2c_smbus_write_byte(client, BH1750_POWER_DOWN);
> >     mutex_unlock(&data->lock);
> > }
> >
> > static int bh1750_suspend(struct device *dev)
> > {
> >     mutex_lock(&data->lock);
> >     ret = i2c_smbus_write_byte(data->client, BH1750_POWER_DOWN);
> >     mutex_unlock(&data->lock);
> >     return ret;
> > }  
> 
> Correct and where do you see the problem here? Perhaps the problem is
> in the cleanup aordering and some other bugs vs. devm calls?
> 
> > In drivers/iio/light, you can find similar examples in pa12203001,
> > rpr0521, apds9960,
> > vcnl4000, isl29028, vcnl4035. You can find many more examples in
> > sensors other than light sensors.  
> 
> Good, should all they need to be fixed?

The complex corners that occur with devm + runtime pm are around
things that we must not run if we are already in runtime suspend.
Typically disabling power supplies (as we can underflow counters
and getting warning prints).  Seeing as this driver is not
doing that it should be simple to use a devm_add_action_or_reset()

Key thing to consider is that runtime pm may not be built.
So the flow should work with those calls doing nothing.  That means that
if you turn the device on in probe we should make sure to explicitly turn
it off in the remove flow. That's where devm_add_action_or_reset()
comes in handy.

ret = regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SENSOR_ENABLE);
Is the paired operation with the second disable you add in remove.
Wrap that in a devm callback.

More complex is the interrupt enable as that doesn't pair with
anything in particular in probe. I'm curious though, do we need
to disable it given the next operation turns off the sensor and on
probe we reset the sensor.

Is just clearing the enable bit enough? 

Jonathan



> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ