* [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-10 6:35 ` Subhajit Ghosh
2025-03-09 17:06 ` [PATCH 02/18] iio: light: gp2ap020a00f: " Jonathan Cameron
` (17 subsequent siblings)
18 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
---
drivers/iio/light/apds9306.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
index 69a0d609cffc..fca7e73a905c 100644
--- a/drivers/iio/light/apds9306.c
+++ b/drivers/iio/light/apds9306.c
@@ -831,11 +831,10 @@ static int apds9306_read_raw(struct iio_dev *indio_dev,
* Changing device parameters during adc operation, resets
* the ADC which has to avoided.
*/
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = apds9306_read_data(data, val, reg);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* Re: [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 ` [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-10 6:35 ` Subhajit Ghosh
2025-03-10 20:01 ` Jonathan Cameron
0 siblings, 1 reply; 31+ messages in thread
From: Subhajit Ghosh @ 2025-03-10 6:35 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Per-Daniel Olsson, Javier Carrasco
Cc: Nuno Sá, David Lechner, Jonathan Cameron
On 10/3/25 03:36, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> These new functions allow sparse to find failures to release
> direct mode reducing chances of bugs over the claim_direct_mode()
> functions that are deprecated.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
> ---
> drivers/iio/light/apds9306.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
> index 69a0d609cffc..fca7e73a905c 100644
> --- a/drivers/iio/light/apds9306.c
> +++ b/drivers/iio/light/apds9306.c
> @@ -831,11 +831,10 @@ static int apds9306_read_raw(struct iio_dev *indio_dev,
> * Changing device parameters during adc operation, resets
> * the ADC which has to avoided.
> */
> - ret = iio_device_claim_direct_mode(indio_dev);
> - if (ret)
> - return ret;
> + if (!iio_device_claim_direct(indio_dev))
> + return -EBUSY;
> ret = apds9306_read_data(data, val, reg);
> - iio_device_release_direct_mode(indio_dev);
> + iio_device_release_direct(indio_dev);
> if (ret)
> return ret;
>
Thank you Jonathan.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-10 6:35 ` Subhajit Ghosh
@ 2025-03-10 20:01 ` Jonathan Cameron
2025-03-15 16:18 ` Subhajit Ghosh
0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-10 20:01 UTC (permalink / raw)
To: Subhajit Ghosh
Cc: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Nuno Sá, David Lechner,
Jonathan Cameron
On Mon, 10 Mar 2025 17:05:50 +1030
Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote:
> On 10/3/25 03:36, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > These new functions allow sparse to find failures to release
> > direct mode reducing chances of bugs over the claim_direct_mode()
> > functions that are deprecated.
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
> > ---
> > drivers/iio/light/apds9306.c | 7 +++----
> > 1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
> > index 69a0d609cffc..fca7e73a905c 100644
> > --- a/drivers/iio/light/apds9306.c
> > +++ b/drivers/iio/light/apds9306.c
> > @@ -831,11 +831,10 @@ static int apds9306_read_raw(struct iio_dev *indio_dev,
> > * Changing device parameters during adc operation, resets
> > * the ADC which has to avoided.
> > */
> > - ret = iio_device_claim_direct_mode(indio_dev);
> > - if (ret)
> > - return ret;
> > + if (!iio_device_claim_direct(indio_dev))
> > + return -EBUSY;
> > ret = apds9306_read_data(data, val, reg);
> > - iio_device_release_direct_mode(indio_dev);
> > + iio_device_release_direct(indio_dev);
> > if (ret)
> > return ret;
> >
> Thank you Jonathan.
Maybe a tag if it looks fine to you? Reviewed-by or Acked-by
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-10 20:01 ` Jonathan Cameron
@ 2025-03-15 16:18 ` Subhajit Ghosh
0 siblings, 0 replies; 31+ messages in thread
From: Subhajit Ghosh @ 2025-03-15 16:18 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Nuno Sá, David Lechner,
Jonathan Cameron
On 11/3/25 06:31, Jonathan Cameron wrote:
> On Mon, 10 Mar 2025 17:05:50 +1030
> Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote:
>
>> On 10/3/25 03:36, Jonathan Cameron wrote:
>>> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>>
>>> These new functions allow sparse to find failures to release
>>> direct mode reducing chances of bugs over the claim_direct_mode()
>>> functions that are deprecated.
>>>
>>> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>> Cc: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
>>> ---
>>> drivers/iio/light/apds9306.c | 7 +++----
>>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
>>> index 69a0d609cffc..fca7e73a905c 100644
>>> --- a/drivers/iio/light/apds9306.c
>>> +++ b/drivers/iio/light/apds9306.c
>>> @@ -831,11 +831,10 @@ static int apds9306_read_raw(struct iio_dev *indio_dev,
>>> * Changing device parameters during adc operation, resets
>>> * the ADC which has to avoided.
>>> */
>>> - ret = iio_device_claim_direct_mode(indio_dev);
>>> - if (ret)
>>> - return ret;
>>> + if (!iio_device_claim_direct(indio_dev))
>>> + return -EBUSY;
>>> ret = apds9306_read_data(data, val, reg);
>>> - iio_device_release_direct_mode(indio_dev);
>>> + iio_device_release_direct(indio_dev);
>>> if (ret)
>>> return ret;
>>>
>> Thank you Jonathan.
> Maybe a tag if it looks fine to you? Reviewed-by or Acked-by
>
> Thanks,
>
> Jonathan
Hi Jonathan,
Looks good. My bad. Totally missed it.
Acked-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
Regards,
Subhajit Ghosh
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH 02/18] iio: light: gp2ap020a00f: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
2025-03-09 17:06 ` [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 03/18] iio: light: isl29125: " Jonathan Cameron
` (16 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/gp2ap020a00f.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 1a352c88598e..c7df4b258e2c 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -1283,12 +1283,11 @@ static int gp2ap020a00f_read_raw(struct iio_dev *indio_dev,
int err = -EINVAL;
if (mask == IIO_CHAN_INFO_RAW) {
- err = iio_device_claim_direct_mode(indio_dev);
- if (err)
- return err;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
err = gp2ap020a00f_read_channel(data, chan, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
}
return err < 0 ? err : IIO_VAL_INT;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 03/18] iio: light: isl29125: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
2025-03-09 17:06 ` [PATCH 01/18] iio: light: apds9306: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-09 17:06 ` [PATCH 02/18] iio: light: gp2ap020a00f: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 04/18] iio: light: as73211: Use guard() and move mode switch into inner write_raw fucntion Jonathan Cameron
` (15 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/isl29125.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/light/isl29125.c b/drivers/iio/light/isl29125.c
index 326dc39e7929..6bc23b164cc5 100644
--- a/drivers/iio/light/isl29125.c
+++ b/drivers/iio/light/isl29125.c
@@ -131,11 +131,10 @@ static int isl29125_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = isl29125_read_data(data, chan->scan_index);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
*val = ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 04/18] iio: light: as73211: Use guard() and move mode switch into inner write_raw fucntion
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (2 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 03/18] iio: light: isl29125: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-11 18:55 ` David Lechner
2025-03-09 17:06 ` [PATCH 05/18] iio: light: as73211: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (14 subsequent siblings)
18 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
By using guard(mutex) and moving code that switches the device to config
mode into _as73211_write_raw() the error flow is simplified.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/iio/light/as73211.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
index 37fffce35dd1..4b73ce57a3d8 100644
--- a/drivers/iio/light/as73211.c
+++ b/drivers/iio/light/as73211.c
@@ -17,6 +17,7 @@
#include <linux/bitfield.h>
#include <linux/completion.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/iio/buffer.h>
@@ -517,6 +518,16 @@ static int _as73211_write_raw(struct iio_dev *indio_dev,
struct as73211_data *data = iio_priv(indio_dev);
int ret;
+ /* Need to switch to config mode ... */
+ if ((data->osr & AS73211_OSR_DOS_MASK) != AS73211_OSR_DOS_CONFIG) {
+ data->osr &= ~AS73211_OSR_DOS_MASK;
+ data->osr |= AS73211_OSR_DOS_CONFIG;
+
+ ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr);
+ if (ret < 0)
+ return ret;
+ }
+
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ: {
int reg_bits, freq_kHz = val / HZ_PER_KHZ; /* 1024, 2048, ... */
@@ -601,28 +612,15 @@ static int as73211_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec con
struct as73211_data *data = iio_priv(indio_dev);
int ret;
- mutex_lock(&data->mutex);
+ guard(mutex)(&data->mutex);
ret = iio_device_claim_direct_mode(indio_dev);
if (ret < 0)
- goto error_unlock;
-
- /* Need to switch to config mode ... */
- if ((data->osr & AS73211_OSR_DOS_MASK) != AS73211_OSR_DOS_CONFIG) {
- data->osr &= ~AS73211_OSR_DOS_MASK;
- data->osr |= AS73211_OSR_DOS_CONFIG;
-
- ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr);
- if (ret < 0)
- goto error_release;
- }
+ return ret;
ret = _as73211_write_raw(indio_dev, chan, val, val2, mask);
-
-error_release:
iio_device_release_direct_mode(indio_dev);
-error_unlock:
- mutex_unlock(&data->mutex);
+
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* Re: [PATCH 04/18] iio: light: as73211: Use guard() and move mode switch into inner write_raw fucntion
2025-03-09 17:06 ` [PATCH 04/18] iio: light: as73211: Use guard() and move mode switch into inner write_raw fucntion Jonathan Cameron
@ 2025-03-11 18:55 ` David Lechner
0 siblings, 0 replies; 31+ messages in thread
From: David Lechner @ 2025-03-11 18:55 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Per-Daniel Olsson, Javier Carrasco,
Subhajit Ghosh
Cc: Nuno Sá, Jonathan Cameron
On 3/9/25 12:06 PM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> By using guard(mutex) and moving code that switches the device to config
> mode into _as73211_write_raw() the error flow is simplified.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> drivers/iio/light/as73211.c | 30 ++++++++++++++----------------
> 1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
> index 37fffce35dd1..4b73ce57a3d8 100644
> --- a/drivers/iio/light/as73211.c
> +++ b/drivers/iio/light/as73211.c
> @@ -17,6 +17,7 @@
>
> #include <linux/bitfield.h>
> #include <linux/completion.h>
> +#include <linux/cleanup.h>
Alphabetical order?
> #include <linux/delay.h>
> #include <linux/i2c.h>
> #include <linux/iio/buffer.h>
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH 05/18] iio: light: as73211: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (3 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 04/18] iio: light: as73211: Use guard() and move mode switch into inner write_raw fucntion Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 06/18] iio: light: ltr501: Factor out IIO_INFO_RAW leg of read_raw() callback Jonathan Cameron
` (13 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/iio/light/as73211.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
index 4b73ce57a3d8..22422ca89e64 100644
--- a/drivers/iio/light/as73211.c
+++ b/drivers/iio/light/as73211.c
@@ -419,18 +419,17 @@ static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec cons
case IIO_CHAN_INFO_RAW: {
int ret;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret < 0)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = as73211_req_data(data);
if (ret < 0) {
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
ret = i2c_smbus_read_word_data(data->client, chan->address);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
@@ -614,12 +613,11 @@ static int as73211_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec con
guard(mutex)(&data->mutex);
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret < 0)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = _as73211_write_raw(indio_dev, chan, val, val2, mask);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 06/18] iio: light: ltr501: Factor out IIO_INFO_RAW leg of read_raw() callback.
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (4 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 05/18] iio: light: as73211: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 07/18] iio: light: ltr501: Factor out core of write_raw() where direct mode claim is held Jonathan Cameron
` (12 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Factoring this code out allows for direct returns, simplifying code flow.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/ltr501.c | 55 +++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 24 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 669da0840eba..b42df15b36e1 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -646,6 +646,36 @@ static const struct iio_chan_spec ltr301_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(2),
};
+static int ltr501_read_info_raw(struct ltr501_data *data,
+ struct iio_chan_spec const *chan,
+ int *val)
+{
+ __le16 buf[2];
+ int ret;
+
+ switch (chan->type) {
+ case IIO_INTENSITY:
+ mutex_lock(&data->lock_als);
+ ret = ltr501_read_als(data, buf);
+ mutex_unlock(&data->lock_als);
+ if (ret < 0)
+ return ret;
+ *val = le16_to_cpu(chan->address == LTR501_ALS_DATA1 ?
+ buf[0] : buf[1]);
+ return IIO_VAL_INT;
+ case IIO_PROXIMITY:
+ mutex_lock(&data->lock_ps);
+ ret = ltr501_read_ps(data);
+ mutex_unlock(&data->lock_ps);
+ if (ret < 0)
+ return ret;
+ *val = ret & LTR501_PS_DATA_MASK;
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+}
+
static int ltr501_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -679,30 +709,7 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
if (ret)
return ret;
- switch (chan->type) {
- case IIO_INTENSITY:
- mutex_lock(&data->lock_als);
- ret = ltr501_read_als(data, buf);
- mutex_unlock(&data->lock_als);
- if (ret < 0)
- break;
- *val = le16_to_cpu(chan->address == LTR501_ALS_DATA1 ?
- buf[0] : buf[1]);
- ret = IIO_VAL_INT;
- break;
- case IIO_PROXIMITY:
- mutex_lock(&data->lock_ps);
- ret = ltr501_read_ps(data);
- mutex_unlock(&data->lock_ps);
- if (ret < 0)
- break;
- *val = ret & LTR501_PS_DATA_MASK;
- ret = IIO_VAL_INT;
- break;
- default:
- ret = -EINVAL;
- break;
- }
+ ret = ltr501_read_info_raw(data, chan, val);
iio_device_release_direct_mode(indio_dev);
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 07/18] iio: light: ltr501: Factor out core of write_raw() where direct mode claim is held.
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (5 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 06/18] iio: light: ltr501: Factor out IIO_INFO_RAW leg of read_raw() callback Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 08/18] iio: light: ltr501: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (11 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Factoring this code out allows for direct returns on error simplifying code
flow.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/ltr501.c | 94 +++++++++++++++++++-------------------
1 file changed, 46 insertions(+), 48 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index b42df15b36e1..c44c852a7d76 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -763,18 +763,14 @@ static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size,
return -1;
}
-static int ltr501_write_raw(struct iio_dev *indio_dev,
- struct iio_chan_spec const *chan,
- int val, int val2, long mask)
+static int __ltr501_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
{
struct ltr501_data *data = iio_priv(indio_dev);
int i, ret, freq_val, freq_val2;
const struct ltr501_chip_info *info = data->chip_info;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
-
switch (mask) {
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
@@ -782,53 +778,43 @@ static int ltr501_write_raw(struct iio_dev *indio_dev,
i = ltr501_get_gain_index(info->als_gain,
info->als_gain_tbl_size,
val, val2);
- if (i < 0) {
- ret = -EINVAL;
- break;
- }
+ if (i < 0)
+ return -EINVAL;
data->als_contr &= ~info->als_gain_mask;
data->als_contr |= i << info->als_gain_shift;
- ret = regmap_write(data->regmap, LTR501_ALS_CONTR,
- data->als_contr);
- break;
+ return regmap_write(data->regmap, LTR501_ALS_CONTR,
+ data->als_contr);
case IIO_PROXIMITY:
i = ltr501_get_gain_index(info->ps_gain,
info->ps_gain_tbl_size,
val, val2);
- if (i < 0) {
- ret = -EINVAL;
- break;
- }
+ if (i < 0)
+ return -EINVAL;
+
data->ps_contr &= ~LTR501_CONTR_PS_GAIN_MASK;
data->ps_contr |= i << LTR501_CONTR_PS_GAIN_SHIFT;
- ret = regmap_write(data->regmap, LTR501_PS_CONTR,
- data->ps_contr);
- break;
+ return regmap_write(data->regmap, LTR501_PS_CONTR,
+ data->ps_contr);
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- break;
case IIO_CHAN_INFO_INT_TIME:
switch (chan->type) {
case IIO_INTENSITY:
- if (val != 0) {
- ret = -EINVAL;
- break;
- }
+ if (val != 0)
+ return -EINVAL;
+
mutex_lock(&data->lock_als);
ret = ltr501_set_it_time(data, val2);
mutex_unlock(&data->lock_als);
- break;
+ return ret;
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- break;
case IIO_CHAN_INFO_SAMP_FREQ:
switch (chan->type) {
@@ -836,50 +822,62 @@ static int ltr501_write_raw(struct iio_dev *indio_dev,
ret = ltr501_als_read_samp_freq(data, &freq_val,
&freq_val2);
if (ret < 0)
- break;
+ return ret;
ret = ltr501_als_write_samp_freq(data, val, val2);
if (ret < 0)
- break;
+ return ret;
/* update persistence count when changing frequency */
ret = ltr501_write_intr_prst(data, chan->type,
0, data->als_period);
if (ret < 0)
- ret = ltr501_als_write_samp_freq(data, freq_val,
- freq_val2);
- break;
+ /* Do not ovewrite error */
+ ltr501_als_write_samp_freq(data, freq_val,
+ freq_val2);
+ return ret;
case IIO_PROXIMITY:
ret = ltr501_ps_read_samp_freq(data, &freq_val,
&freq_val2);
if (ret < 0)
- break;
+ return ret;
ret = ltr501_ps_write_samp_freq(data, val, val2);
if (ret < 0)
- break;
+ return ret;
/* update persistence count when changing frequency */
ret = ltr501_write_intr_prst(data, chan->type,
0, data->ps_period);
if (ret < 0)
- ret = ltr501_ps_write_samp_freq(data, freq_val,
- freq_val2);
- break;
+ /* Do not overwrite error */
+ ltr501_ps_write_samp_freq(data, freq_val,
+ freq_val2);
+ return ret;
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- break;
-
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
+}
+
+static int ltr501_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ int ret;
+
+ ret = iio_device_claim_direct_mode(indio_dev);
+ if (ret)
+ return ret;
+
+ ret = __ltr501_write_raw(indio_dev, chan, val, val2, mask);
iio_device_release_direct_mode(indio_dev);
+
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 08/18] iio: light: ltr501: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (6 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 07/18] iio: light: ltr501: Factor out core of write_raw() where direct mode claim is held Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 09/18] iio: light: opt4060: " Jonathan Cameron
` (10 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/ltr501.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index c44c852a7d76..23fd0713c64b 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -688,14 +688,13 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_PROCESSED:
switch (chan->type) {
case IIO_LIGHT:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&data->lock_als);
ret = ltr501_read_als(data, buf);
mutex_unlock(&data->lock_als);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
*val = ltr501_calculate_lux(le16_to_cpu(buf[1]),
@@ -705,13 +704,12 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
return -EINVAL;
}
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = ltr501_read_info_raw(data, chan, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE:
@@ -870,13 +868,12 @@ static int ltr501_write_raw(struct iio_dev *indio_dev,
{
int ret;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = __ltr501_write_raw(indio_dev, chan, val, val2, mask);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 09/18] iio: light: opt4060: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (7 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 08/18] iio: light: ltr501: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-18 8:10 ` Per-Daniel Olsson
2025-03-09 17:06 ` [PATCH 10/18] iio: light: rohm-bu27034: " Jonathan Cameron
` (9 subsequent siblings)
18 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated. This is a case where the code
is pinning down the mode so also has a claim on buffered mode.
A follow up set may move those calls over to a sparse friendly
form as well.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Per-Daniel Olsson <perdaniel.olsson@axis.com>
---
drivers/iio/light/opt4060.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
index ab55f8d2ea0c..f4085020e03e 100644
--- a/drivers/iio/light/opt4060.c
+++ b/drivers/iio/light/opt4060.c
@@ -311,7 +311,7 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,
* concurrently change. And we just keep trying until we get one
* of the modes...
*/
- if (iio_device_claim_direct_mode(indio_dev))
+ if (!iio_device_claim_direct(indio_dev))
goto any_mode_retry;
/*
* This path means that we managed to claim direct mode. In
@@ -320,7 +320,8 @@ static int opt4060_set_driver_state(struct iio_dev *indio_dev,
*/
ret = opt4060_set_state_common(chip, continuous_sampling,
continuous_irq);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
+ return ret;
} else {
/*
* This path means that we managed to claim buffer mode. In
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* Re: [PATCH 09/18] iio: light: opt4060: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 ` [PATCH 09/18] iio: light: opt4060: " Jonathan Cameron
@ 2025-03-18 8:10 ` Per-Daniel Olsson
2025-03-18 17:07 ` Per-Daniel Olsson
0 siblings, 1 reply; 31+ messages in thread
From: Per-Daniel Olsson @ 2025-03-18 8:10 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
On 3/9/25 18:06, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> These new functions allow sparse to find failures to release
> direct mode reducing chances of bugs over the claim_direct_mode()
> functions that are deprecated. This is a case where the code
> is pinning down the mode so also has a claim on buffered mode.
> A follow up set may move those calls over to a sparse friendly
> form as well.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Per-Daniel Olsson <perdaniel.olsson@axis.com>
Acked-by: Per-Daniel Olsson <perdaniel.olsson@axis.com>
Best regards / P-D
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 09/18] iio: light: opt4060: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-18 8:10 ` Per-Daniel Olsson
@ 2025-03-18 17:07 ` Per-Daniel Olsson
0 siblings, 0 replies; 31+ messages in thread
From: Per-Daniel Olsson @ 2025-03-18 17:07 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
On 3/18/25 09:10, Per-Daniel Olsson wrote:
> On 3/9/25 18:06, Jonathan Cameron wrote:
>> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>
>> These new functions allow sparse to find failures to release
>> direct mode reducing chances of bugs over the claim_direct_mode()
>> functions that are deprecated. This is a case where the code
>> is pinning down the mode so also has a claim on buffered mode.
>> A follow up set may move those calls over to a sparse friendly
>> form as well.
>>
>> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>> Cc: Per-Daniel Olsson <perdaniel.olsson@axis.com>
>
> Acked-by: Per-Daniel Olsson <perdaniel.olsson@axis.com>
>
> Best regards / P-D
I have tested the patch and reviewed it, maybe these tags are more accurate
than just Acked-by.
Tested-by: Per-Daniel Olsson <perdaniel.olsson@axis.com>
Reviewed-by: Per-Daniel Olsson <perdaniel.olsson@axis.com>
Best regards / P-D
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH 10/18] iio: light: rohm-bu27034: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (8 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 09/18] iio: light: opt4060: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-10 5:21 ` Matti Vaittinen
2025-03-09 17:06 ` [PATCH 11/18] iio: light: rpr0521: Factor out handling of IIO_INFO_RAW and use guard() Jonathan Cameron
` (8 subsequent siblings)
18 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.com>
---
drivers/iio/light/rohm-bu27034.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
index cc25596cb248..7cec5e943373 100644
--- a/drivers/iio/light/rohm-bu27034.c
+++ b/drivers/iio/light/rohm-bu27034.c
@@ -998,9 +998,8 @@ static int bu27034_read_raw(struct iio_dev *idev,
return -EINVAL;
/* Don't mess with measurement enabling while buffering */
- ret = iio_device_claim_direct_mode(idev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(idev))
+ return -EBUSY;
mutex_lock(&data->mutex);
/*
@@ -1011,7 +1010,7 @@ static int bu27034_read_raw(struct iio_dev *idev,
ret = result_get(data, chan->channel, val);
mutex_unlock(&data->mutex);
- iio_device_release_direct_mode(idev);
+ iio_device_release_direct(idev);
if (ret)
return ret;
@@ -1050,9 +1049,8 @@ static int bu27034_write_raw(struct iio_dev *idev,
struct bu27034_data *data = iio_priv(idev);
int ret;
- ret = iio_device_claim_direct_mode(idev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(idev))
+ return -EBUSY;
switch (mask) {
case IIO_CHAN_INFO_SCALE:
@@ -1069,7 +1067,7 @@ static int bu27034_write_raw(struct iio_dev *idev,
break;
}
- iio_device_release_direct_mode(idev);
+ iio_device_release_direct(idev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* Re: [PATCH 10/18] iio: light: rohm-bu27034: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 ` [PATCH 10/18] iio: light: rohm-bu27034: " Jonathan Cameron
@ 2025-03-10 5:21 ` Matti Vaittinen
0 siblings, 0 replies; 31+ messages in thread
From: Matti Vaittinen @ 2025-03-10 5:21 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
On 09/03/2025 19:06, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> These new functions allow sparse to find failures to release
> direct mode reducing chances of bugs over the claim_direct_mode()
> functions that are deprecated.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Matti Vaittinen <mazziesaccount@gmail.com>
Acked-by: Matti Vaittinen <mazziesaccount@gmail.com>
Yours,
--Matti
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH 11/18] iio: light: rpr0521: Factor out handling of IIO_INFO_RAW and use guard()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (9 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 10/18] iio: light: rohm-bu27034: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 12/18] iio: light: rpr0521: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (7 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Factor out the code which is only called with the direct mode claimed.
This and the use of guard(mutex) allows direct returns simplifying
code flow.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/rpr0521.c | 57 ++++++++++++++++++++++---------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
index 2ba917c5c138..65c60a1d2f0b 100644
--- a/drivers/iio/light/rpr0521.c
+++ b/drivers/iio/light/rpr0521.c
@@ -11,6 +11,7 @@
#include <linux/module.h>
#include <linux/mod_devicetable.h>
+#include <linux/cleanup.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
@@ -704,6 +705,38 @@ static int rpr0521_write_ps_offset(struct rpr0521_data *data, int offset)
return ret;
}
+static int rpr0521_read_info_raw(struct rpr0521_data *data,
+ struct iio_chan_spec const *chan,
+ int *val)
+{
+ u8 device_mask;
+ __le16 raw_data;
+ int ret;
+
+ device_mask = rpr0521_data_reg[chan->address].device_mask;
+
+ guard(mutex)(&data->lock);
+ ret = rpr0521_set_power_state(data, true, device_mask);
+ if (ret < 0)
+ return ret;
+
+ ret = regmap_bulk_read(data->regmap,
+ rpr0521_data_reg[chan->address].address,
+ &raw_data, sizeof(raw_data));
+ if (ret < 0) {
+ rpr0521_set_power_state(data, false, device_mask);
+ return ret;
+ }
+
+ ret = rpr0521_set_power_state(data, false, device_mask);
+ if (ret < 0)
+ return ret;
+
+ *val = le16_to_cpu(raw_data);
+
+ return 0;
+}
+
static int rpr0521_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
@@ -711,8 +744,6 @@ static int rpr0521_read_raw(struct iio_dev *indio_dev,
struct rpr0521_data *data = iio_priv(indio_dev);
int ret;
int busy;
- u8 device_mask;
- __le16 raw_data;
switch (mask) {
case IIO_CHAN_INFO_RAW:
@@ -723,31 +754,11 @@ static int rpr0521_read_raw(struct iio_dev *indio_dev,
if (busy)
return -EBUSY;
- device_mask = rpr0521_data_reg[chan->address].device_mask;
-
- mutex_lock(&data->lock);
- ret = rpr0521_set_power_state(data, true, device_mask);
- if (ret < 0)
- goto rpr0521_read_raw_out;
-
- ret = regmap_bulk_read(data->regmap,
- rpr0521_data_reg[chan->address].address,
- &raw_data, sizeof(raw_data));
- if (ret < 0) {
- rpr0521_set_power_state(data, false, device_mask);
- goto rpr0521_read_raw_out;
- }
-
- ret = rpr0521_set_power_state(data, false, device_mask);
-
-rpr0521_read_raw_out:
- mutex_unlock(&data->lock);
+ ret = rpr0521_read_info_raw(data, chan, val);
iio_device_release_direct_mode(indio_dev);
if (ret < 0)
return ret;
- *val = le16_to_cpu(raw_data);
-
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 12/18] iio: light: rpr0521: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (10 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 11/18] iio: light: rpr0521: Factor out handling of IIO_INFO_RAW and use guard() Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 13/18] iio: light: si1145: " Jonathan Cameron
` (6 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/rpr0521.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
index 65c60a1d2f0b..92e7552f3e39 100644
--- a/drivers/iio/light/rpr0521.c
+++ b/drivers/iio/light/rpr0521.c
@@ -743,19 +743,17 @@ static int rpr0521_read_raw(struct iio_dev *indio_dev,
{
struct rpr0521_data *data = iio_priv(indio_dev);
int ret;
- int busy;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (chan->type != IIO_INTENSITY && chan->type != IIO_PROXIMITY)
return -EINVAL;
- busy = iio_device_claim_direct_mode(indio_dev);
- if (busy)
+ if (!iio_device_claim_direct(indio_dev))
return -EBUSY;
ret = rpr0521_read_info_raw(data, chan, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 13/18] iio: light: si1145: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (11 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 12/18] iio: light: rpr0521: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 14/18] iio: light: st_uvis25: " Jonathan Cameron
` (5 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/si1145.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
index 66abda021696..4aa02afd853e 100644
--- a/drivers/iio/light/si1145.c
+++ b/drivers/iio/light/si1145.c
@@ -633,11 +633,10 @@ static int si1145_read_raw(struct iio_dev *indio_dev,
case IIO_VOLTAGE:
case IIO_TEMP:
case IIO_UVINDEX:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = si1145_measure(indio_dev, chan);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
@@ -750,18 +749,17 @@ static int si1145_write_raw(struct iio_dev *indio_dev,
return -EINVAL;
}
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = si1145_param_set(data, reg1, val);
if (ret < 0) {
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
/* Set recovery period to one's complement of gain */
ret = si1145_param_set(data, reg2, (~val & 0x07) << 4);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_RAW:
if (chan->type != IIO_CURRENT)
@@ -773,19 +771,18 @@ static int si1145_write_raw(struct iio_dev *indio_dev,
reg1 = SI1145_PS_LED_REG(chan->channel);
shift = SI1145_PS_LED_SHIFT(chan->channel);
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = i2c_smbus_read_byte_data(data->client, reg1);
if (ret < 0) {
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
ret = i2c_smbus_write_byte_data(data->client, reg1,
(ret & ~(0x0f << shift)) |
((val & 0x0f) << shift));
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return si1145_store_samp_freq(data, val);
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 14/18] iio: light: st_uvis25: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (12 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 13/18] iio: light: si1145: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 15/18] iio: light: tcs3414: " Jonathan Cameron
` (4 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/st_uvis25_core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/light/st_uvis25_core.c b/drivers/iio/light/st_uvis25_core.c
index 40a810000df0..124a8f9204a9 100644
--- a/drivers/iio/light/st_uvis25_core.c
+++ b/drivers/iio/light/st_uvis25_core.c
@@ -117,9 +117,8 @@ static int st_uvis25_read_raw(struct iio_dev *iio_dev,
{
int ret;
- ret = iio_device_claim_direct_mode(iio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(iio_dev))
+ return -EBUSY;
switch (mask) {
case IIO_CHAN_INFO_PROCESSED: {
@@ -144,7 +143,7 @@ static int st_uvis25_read_raw(struct iio_dev *iio_dev,
break;
}
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 15/18] iio: light: tcs3414: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (13 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 14/18] iio: light: st_uvis25: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 16/18] iio: light: tcs3472: " Jonathan Cameron
` (3 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/tcs3414.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
index 884e43e4cda4..39268f855c77 100644
--- a/drivers/iio/light/tcs3414.c
+++ b/drivers/iio/light/tcs3414.c
@@ -134,16 +134,15 @@ static int tcs3414_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = tcs3414_req_data(data);
if (ret < 0) {
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
ret = i2c_smbus_read_word_data(data->client, chan->address);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
*val = ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 16/18] iio: light: tcs3472: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (14 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 15/18] iio: light: tcs3414: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-09 17:06 ` [PATCH 17/18] iio: light: vcnl4000: " Jonathan Cameron
` (2 subsequent siblings)
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/tcs3472.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/light/tcs3472.c b/drivers/iio/light/tcs3472.c
index 2bd36a344ea5..0f8bf8503edd 100644
--- a/drivers/iio/light/tcs3472.c
+++ b/drivers/iio/light/tcs3472.c
@@ -148,16 +148,15 @@ static int tcs3472_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = tcs3472_req_data(data);
if (ret < 0) {
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
ret = i2c_smbus_read_word_data(data->client, chan->address);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
*val = ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* [PATCH 17/18] iio: light: vcnl4000: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (15 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 16/18] iio: light: tcs3472: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-11 19:11 ` David Lechner
2025-03-18 17:08 ` Per-Daniel Olsson
2025-03-09 17:06 ` [PATCH 18/18] iio: light: vcnl4035: " Jonathan Cameron
2025-03-11 19:16 ` [PATCH 00/18] iio: light: Sparse friendly claim of direct mode David Lechner
18 siblings, 2 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
Also split the enabling and disabling of thresholds into separate
functions given overlap is small.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Astrid Rost <astrid.rost@axis.com>
---
drivers/iio/light/vcnl4000.c | 78 +++++++++++++++++++-----------------
1 file changed, 41 insertions(+), 37 deletions(-)
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index e19199b17f2e..d7489bee2dff 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -1084,9 +1084,8 @@ static int vcnl4010_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
case IIO_CHAN_INFO_SCALE:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
/* Protect against event capture. */
if (vcnl4010_is_in_periodic_mode(data)) {
@@ -1096,7 +1095,7 @@ static int vcnl4010_read_raw(struct iio_dev *indio_dev,
mask);
}
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
switch (chan->type) {
@@ -1157,9 +1156,8 @@ static int vcnl4010_write_raw(struct iio_dev *indio_dev,
int ret;
struct vcnl4000_data *data = iio_priv(indio_dev);
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
/* Protect against event capture. */
if (vcnl4010_is_in_periodic_mode(data)) {
@@ -1183,7 +1181,7 @@ static int vcnl4010_write_raw(struct iio_dev *indio_dev,
}
end:
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
@@ -1410,46 +1408,52 @@ static int vcnl4010_read_event_config(struct iio_dev *indio_dev,
}
}
-static int vcnl4010_config_threshold(struct iio_dev *indio_dev, bool state)
+static int vcnl4010_config_threshold_enable(struct vcnl4000_data *data)
{
- struct vcnl4000_data *data = iio_priv(indio_dev);
int ret;
- int icr;
- int command;
- if (state) {
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ /* Enable periodic measurement of proximity data. */
+ ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND,
+ VCNL4000_SELF_TIMED_EN | VCNL4000_PROX_EN);
+ if (ret < 0)
+ return ret;
- /* Enable periodic measurement of proximity data. */
- command = VCNL4000_SELF_TIMED_EN | VCNL4000_PROX_EN;
+ /*
+ * Enable interrupts on threshold, for proximity data by
+ * default.
+ */
+ return i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL,
+ VCNL4010_INT_THR_EN);
+}
- /*
- * Enable interrupts on threshold, for proximity data by
- * default.
- */
- icr = VCNL4010_INT_THR_EN;
- } else {
- if (!vcnl4010_is_thr_enabled(data))
- return 0;
+static int vcnl4010_config_threshold_disable(struct vcnl4000_data *data)
+{
+ int ret;
- command = 0;
- icr = 0;
- }
+ if (!vcnl4010_is_thr_enabled(data))
+ return 0;
- ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND,
- command);
+ ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0);
if (ret < 0)
- goto end;
+ return ret;
- ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, icr);
+ return i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, 0);
+}
-end:
- if (state)
- iio_device_release_direct_mode(indio_dev);
+static int vcnl4010_config_threshold(struct iio_dev *indio_dev, bool state)
+{
+ struct vcnl4000_data *data = iio_priv(indio_dev);
+ int ret;
- return ret;
+ if (state) {
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
+ ret = vcnl4010_config_threshold_enable(data);
+ iio_device_release_direct(indio_dev);
+ return ret;
+ } else {
+ return vcnl4010_config_threshold_disable(data);
+ }
}
static int vcnl4010_write_event_config(struct iio_dev *indio_dev,
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* Re: [PATCH 17/18] iio: light: vcnl4000: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 ` [PATCH 17/18] iio: light: vcnl4000: " Jonathan Cameron
@ 2025-03-11 19:11 ` David Lechner
2025-03-31 11:44 ` Jonathan Cameron
2025-03-18 17:08 ` Per-Daniel Olsson
1 sibling, 1 reply; 31+ messages in thread
From: David Lechner @ 2025-03-11 19:11 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Per-Daniel Olsson, Javier Carrasco,
Subhajit Ghosh
Cc: Nuno Sá, Jonathan Cameron
On 3/9/25 12:06 PM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> These new functions allow sparse to find failures to release
> direct mode reducing chances of bugs over the claim_direct_mode()
> functions that are deprecated.
>
> Also split the enabling and disabling of thresholds into separate
> functions given overlap is small.
Should be 2 patches since doing 2 different things?
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Astrid Rost <astrid.rost@axis.com>
> ---
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 17/18] iio: light: vcnl4000: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-11 19:11 ` David Lechner
@ 2025-03-31 11:44 ` Jonathan Cameron
2025-04-02 7:28 ` Astrid Rost
0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-31 11:44 UTC (permalink / raw)
To: David Lechner
Cc: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh, Nuno Sá,
Jonathan Cameron
On Tue, 11 Mar 2025 14:11:16 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 3/9/25 12:06 PM, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > These new functions allow sparse to find failures to release
> > direct mode reducing chances of bugs over the claim_direct_mode()
> > functions that are deprecated.
> >
> > Also split the enabling and disabling of thresholds into separate
> > functions given overlap is small.
>
> Should be 2 patches since doing 2 different things?
They are messily overlapped because of the oddity that we only
take the direct mode state if enabling. It is in theory possible to
do the split of functions first but that will result in messier functions
that we then clean up. I'm not keen on that complexity so going to be
lazy this time and not do it.
I'll add something to the patch description to say that.
Jonathan
>
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Astrid Rost <astrid.rost@axis.com>
> > ---
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 17/18] iio: light: vcnl4000: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 11:44 ` Jonathan Cameron
@ 2025-04-02 7:28 ` Astrid Rost
0 siblings, 0 replies; 31+ messages in thread
From: Astrid Rost @ 2025-04-02 7:28 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner
Cc: linux-iio, Nuno Sá, Matti Vaittinen, Per-Daniel Olsson,
Javier Carrasco, Subhajit Ghosh, Nuno Sá, Jonathan Cameron
On 3/31/25 13:44, Jonathan Cameron wrote:
> On Tue, 11 Mar 2025 14:11:16 -0500
> David Lechner <dlechner@baylibre.com> wrote:
>
>> On 3/9/25 12:06 PM, Jonathan Cameron wrote:
>>> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>>
>>> These new functions allow sparse to find failures to release
>>> direct mode reducing chances of bugs over the claim_direct_mode()
>>> functions that are deprecated.
>>>
>>> Also split the enabling and disabling of thresholds into separate
>>> functions given overlap is small.
>>
>> Should be 2 patches since doing 2 different things?
>
> They are messily overlapped because of the oddity that we only
> take the direct mode state if enabling. It is in theory possible to
> do the split of functions first but that will result in messier functions
> that we then clean up. I'm not keen on that complexity so going to be
> lazy this time and not do it.
>
> I'll add something to the patch description to say that.
>
> Jonathan
>
>
>>
>>>
>>> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>> Cc: Astrid Rost <astrid.rost@axis.com>
>>> ---
>
Looks good to me also with one patch.
Reviewed-by: Astrid Rost <astrid.rost@axis.com>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH 17/18] iio: light: vcnl4000: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 ` [PATCH 17/18] iio: light: vcnl4000: " Jonathan Cameron
2025-03-11 19:11 ` David Lechner
@ 2025-03-18 17:08 ` Per-Daniel Olsson
1 sibling, 0 replies; 31+ messages in thread
From: Per-Daniel Olsson @ 2025-03-18 17:08 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
On 3/9/25 18:06, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> These new functions allow sparse to find failures to release
> direct mode reducing chances of bugs over the claim_direct_mode()
> functions that are deprecated.
>
> Also split the enabling and disabling of thresholds into separate
> functions given overlap is small.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Astrid Rost <astrid.rost@axis.com>
Tested-by: Per-Daniel Olsson <perdaniel.olsson@axis.com>
Reviewed-by: Per-Daniel Olsson <perdaniel.olsson@axis.com>
Best regards / P-D
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH 18/18] iio: light: vcnl4035: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (16 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 17/18] iio: light: vcnl4000: " Jonathan Cameron
@ 2025-03-09 17:06 ` Jonathan Cameron
2025-03-11 19:16 ` [PATCH 00/18] iio: light: Sparse friendly claim of direct mode David Lechner
18 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2025-03-09 17:06 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Astrid Rost, Matti Vaittinen,
Per-Daniel Olsson, Javier Carrasco, Subhajit Ghosh
Cc: Nuno Sá, David Lechner, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.
This case triggered a false positive from sparse, resolved by
factoring out the code that includes the claim and release of
direct mode.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/light/vcnl4035.c | 42 ++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/light/vcnl4035.c b/drivers/iio/light/vcnl4035.c
index 67c94be02018..b2bede9d3daa 100644
--- a/drivers/iio/light/vcnl4035.c
+++ b/drivers/iio/light/vcnl4035.c
@@ -156,6 +156,31 @@ static int vcnl4035_set_pm_runtime_state(struct vcnl4035_data *data, bool on)
return ret;
}
+static int vcnl4035_read_info_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, int *val)
+{
+ struct vcnl4035_data *data = iio_priv(indio_dev);
+ int ret;
+ int raw_data;
+ unsigned int reg;
+
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
+
+ if (chan->channel)
+ reg = VCNL4035_ALS_DATA;
+ else
+ reg = VCNL4035_WHITE_DATA;
+ ret = regmap_read(data->regmap, reg, &raw_data);
+ iio_device_release_direct(indio_dev);
+ if (ret)
+ return ret;
+
+ *val = raw_data;
+
+ return IIO_VAL_INT;
+}
+
/*
* Device IT INT Time (ms) Scale (lux/step)
* 000 50 0.064
@@ -175,28 +200,13 @@ static int vcnl4035_read_raw(struct iio_dev *indio_dev,
{
struct vcnl4035_data *data = iio_priv(indio_dev);
int ret;
- int raw_data;
- unsigned int reg;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = vcnl4035_set_pm_runtime_state(data, true);
if (ret < 0)
return ret;
-
- ret = iio_device_claim_direct_mode(indio_dev);
- if (!ret) {
- if (chan->channel)
- reg = VCNL4035_ALS_DATA;
- else
- reg = VCNL4035_WHITE_DATA;
- ret = regmap_read(data->regmap, reg, &raw_data);
- iio_device_release_direct_mode(indio_dev);
- if (!ret) {
- *val = raw_data;
- ret = IIO_VAL_INT;
- }
- }
+ ret = vcnl4035_read_info_raw(indio_dev, chan, val);
vcnl4035_set_pm_runtime_state(data, false);
return ret;
case IIO_CHAN_INFO_INT_TIME:
--
2.48.1
^ permalink raw reply related [flat|nested] 31+ messages in thread* Re: [PATCH 00/18] iio: light: Sparse friendly claim of direct mode
2025-03-09 17:06 [PATCH 00/18] iio: light: Sparse friendly claim of direct mode Jonathan Cameron
` (17 preceding siblings ...)
2025-03-09 17:06 ` [PATCH 18/18] iio: light: vcnl4035: " Jonathan Cameron
@ 2025-03-11 19:16 ` David Lechner
18 siblings, 0 replies; 31+ messages in thread
From: David Lechner @ 2025-03-11 19:16 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Nuno Sá, Astrid Rost,
Matti Vaittinen, Per-Daniel Olsson, Javier Carrasco,
Subhajit Ghosh
Cc: Nuno Sá, Jonathan Cameron
On 3/9/25 12:06 PM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Note that a number of the drivers touched in this series have no
> obvious active maintainer, so it would be much appreciated if anyone
> has time to take a look! It is a large series so feel free to review
> any you have time to look at rather than feeling you need to look
> at the whole thing!
>
> This is effectively part 4 of what will probably be around 7 series
> focused on moving from iio_device_claim/release_direct_mode() to
> iio_device_claim/release_direct(). The new form is more consistent
> with conditional locking semantics and sparse markings have been
> added that let us detect miss-balance between claim and release.
>
> More details can be found in the cover letter of the first series:
> https://lore.kernel.org/all/20250209180624.701140-1-jic23@kernel.org/
>
> This series focuses on the light sensor drivers.
>
Made a couple of minor comments, but overall looks OK.
Reviewed-by: David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 31+ messages in thread