* [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest)
@ 2025-03-31 12:12 Jonathan Cameron
2025-03-31 12:12 ` [PATCH 01/37] iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (38 more replies)
0 siblings, 39 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Firstly, sorry for the huge patch set!
I've run out of signficiant groups to break the remaining patches up into.
Rather than have lots of small series of 5-10 patches, lets just have one
mega one. Feel free to review a subset! I'll nibble away at this as reviews
come in and post a v2 later in the cycle with whatever remains unreviewed
if that is necessary.
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!
This is effectively part 5 of what will probably be around 5 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 all the remaining drivers.
The final patch removes the old infrastructure.
Jonathan Cameron (37):
iio: addac: ad74115: Switch to sparse friendly
iio_device_claim/release_direct()
iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to
simplify error paths.
iio: chemical: ccs811: Switch to sparse friendly
iio_device_claim/release_direct()
iio: chemical: atlas-sensor: Switch to sparse friendly
iio_device_claim/release_direct()
iio: chemical: scd4x: Switch to sparse friendly
iio_device_claim/release_direct()
iio: common: scmi: Switch to sparse friendly
iio_device_claim/release_direct()
iio: common: st_sensors: Switch to sparse friendly
iio_device_claim/release_direct()
iio: gyro: adxrs290: Switch to sparse friendly
iio_device_claim/release_direct()
iio: health: max30102: Switch to sparse friendly
iio_device_claim/release_direct()
iio: humidity: hdc100x: Use guard(mutex) to simplify code flow
iio: humidity: hdc100x: Switch to sparse friendly
iio_device_claim/release_direct()
iio: humidity: hdc2010: Switch to sparse friendly
iio_device_claim/release_direct()
iio: humidity: hts211: Factor out everything under direct mode claim
into helper functions.
iio: humidity: hts211: Switch to sparse friendly
iio_device_claim/release_direct()
iio: imu: inv_icm42600: Switch to sparse friendly
iio_device_claim/release_direct()
iio: imu: inv_mpu6050: Switch to sparse friendly
iio_device_claim/release_direct()
iio: imu: smi240: Switch to sparse friendly
iio_device_claim/release_direct()
iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw()
to allow direct returns
iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct()
iio: imu: st_lsm6dsx: Switch to sparse friendly
iio_device_claim/release_direct()
iio: magnetometer: mag3110: Factor out core of read/write_raw() and
use guard() to simplify code flow.
iio: magnetometer: mag3110: Switch to sparse friendly
iio_device_claim/release_direct()
iio: magnetometer: rm3100: Switch to sparse friendly
iio_device_claim/release_direct()
iio: pressure: dlhl60d: Switch to sparse friendly
iio_device_claim/release_direct()
iio: pressure: icp10100: Switch to sparse friendly
iio_device_claim/release_direct()
iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to
simplify code flow
iio: pressure: mpl3115: Switch to sparse friendly
iio_device_claim/release_direct()
iio: pressure: ms5611: Switch to sparse friendly
iio_device_claim/release_direct()
iio: pressure: rohm-bm1390: Switch to sparse friendly
iio_device_claim/release_direct()
iio: pressure: zpa2326: Switch to sparse friendly
iio_device_claim/release_direct()
iio: proximity: hx9023s: Switch to sparse friendly
iio_device_claim/release_direct()
iio: proximity: pulsed-light: Switch to sparse friendly
iio_device_claim/release_direct()
iio: proximity: sx9500: Switch to sparse friendly
iio_device_claim/release_direct()
iio: temp: maxim_thermocouple: Switch to sparse friendly
iio_device_claim/release_direct()
iio: temp: maxim_thermocouple: Drop unused mutex.h include.
staging: iio: ad5933: Switch to sparse friendly
iio_device_claim/release_direct()
iio: Adjust internals of handling of direct mode claiming to suit new
API.
drivers/iio/addac/ad74115.c | 7 +-
drivers/iio/chemical/atlas-sensor.c | 7 +-
drivers/iio/chemical/ccs811.c | 79 ++++-----
drivers/iio/chemical/scd4x.c | 7 +-
drivers/iio/common/scmi_sensors/scmi_iio.c | 7 +-
.../iio/common/st_sensors/st_sensors_core.c | 7 +-
drivers/iio/gyro/adxrs290.c | 14 +-
drivers/iio/health/max30102.c | 4 +-
drivers/iio/humidity/hdc100x.c | 68 +++-----
drivers/iio/humidity/hdc2010.c | 14 +-
drivers/iio/humidity/hts221_core.c | 91 +++++-----
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 21 +--
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 21 +--
.../iio/imu/inv_icm42600/inv_icm42600_temp.c | 7 +-
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 +-
drivers/iio/imu/smi240.c | 7 +-
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 16 +-
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 73 ++++----
drivers/iio/industrialio-core.c | 28 +--
drivers/iio/magnetometer/mag3110.c | 161 +++++++++---------
drivers/iio/magnetometer/rm3100-core.c | 7 +-
drivers/iio/pressure/dlhl60d.c | 7 +-
drivers/iio/pressure/icp10100.c | 15 +-
drivers/iio/pressure/mpl3115.c | 97 ++++++-----
drivers/iio/pressure/ms5611_core.c | 8 +-
drivers/iio/pressure/rohm-bm1390.c | 7 +-
drivers/iio/pressure/zpa2326.c | 15 +-
drivers/iio/proximity/hx9023s.c | 7 +-
.../iio/proximity/pulsedlight-lidar-lite-v2.c | 4 +-
drivers/iio/proximity/sx9500.c | 7 +-
drivers/iio/temperature/maxim_thermocouple.c | 30 ++--
.../staging/iio/impedance-analyzer/ad5933.c | 38 +++--
include/linux/iio/iio.h | 10 +-
33 files changed, 428 insertions(+), 477 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH 01/37] iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 02/37] iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to simplify error paths Jonathan Cameron
` (37 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Cosmin Tanislav <demonsingur@gmail.com>
---
drivers/iio/addac/ad74115.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c
index a7e480f2472d..edccdc9cf34b 100644
--- a/drivers/iio/addac/ad74115.c
+++ b/drivers/iio/addac/ad74115.c
@@ -866,15 +866,14 @@ static int ad74115_get_adc_code(struct iio_dev *indio_dev,
struct ad74115_state *st = iio_priv(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;
mutex_lock(&st->lock);
ret = _ad74115_get_adc_code(st, channel, val);
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 02/37] iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to simplify error paths.
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
2025-03-31 12:12 ` [PATCH 01/37] iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 03/37] iio: chemical: ccs811: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (36 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Factor out the implementation of this part of read_raw() and use
guard() to allow direct returns, simplifying both error and non error
paths.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/chemical/ccs811.c | 72 ++++++++++++++++++-----------------
1 file changed, 37 insertions(+), 35 deletions(-)
diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
index 451fb65dbe60..75b0cb05dd86 100644
--- a/drivers/iio/chemical/ccs811.c
+++ b/drivers/iio/chemical/ccs811.c
@@ -15,6 +15,7 @@
* 4. Read error register and put the information in logs
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
@@ -214,6 +215,40 @@ static int ccs811_get_measurement(struct ccs811_data *data)
return ret;
}
+static int ccs811_read_info_raw(struct ccs811_data *data,
+ struct iio_chan_spec const *chan,
+ int *val, int mask)
+{
+ int ret;
+
+ guard(mutex)(&data->lock);
+ ret = ccs811_get_measurement(data);
+ if (ret < 0)
+ return ret;
+
+ switch (chan->type) {
+ case IIO_VOLTAGE:
+ *val = be16_to_cpu(data->buffer.raw_data) & CCS811_VOLTAGE_MASK;
+ return IIO_VAL_INT;
+ case IIO_CURRENT:
+ *val = be16_to_cpu(data->buffer.raw_data) >> 10;
+ return IIO_VAL_INT;
+ case IIO_CONCENTRATION:
+ switch (chan->channel2) {
+ case IIO_MOD_CO2:
+ *val = be16_to_cpu(data->buffer.co2);
+ return IIO_VAL_INT;
+ case IIO_MOD_VOC:
+ *val = be16_to_cpu(data->buffer.voc);
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+ default:
+ return -EINVAL;
+ }
+}
+
static int ccs811_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -226,42 +261,9 @@ static int ccs811_read_raw(struct iio_dev *indio_dev,
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;
- mutex_lock(&data->lock);
- ret = ccs811_get_measurement(data);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- iio_device_release_direct_mode(indio_dev);
- return ret;
- }
- switch (chan->type) {
- case IIO_VOLTAGE:
- *val = be16_to_cpu(data->buffer.raw_data) &
- CCS811_VOLTAGE_MASK;
- ret = IIO_VAL_INT;
- break;
- case IIO_CURRENT:
- *val = be16_to_cpu(data->buffer.raw_data) >> 10;
- ret = IIO_VAL_INT;
- break;
- case IIO_CONCENTRATION:
- switch (chan->channel2) {
- case IIO_MOD_CO2:
- *val = be16_to_cpu(data->buffer.co2);
- ret = IIO_VAL_INT;
- break;
- case IIO_MOD_VOC:
- *val = be16_to_cpu(data->buffer.voc);
- ret = IIO_VAL_INT;
- break;
- default:
- ret = -EINVAL;
- }
- break;
- default:
- ret = -EINVAL;
- }
- mutex_unlock(&data->lock);
+ ret = ccs811_read_info_raw(data, chan, val, mask);
+
iio_device_release_direct_mode(indio_dev);
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 03/37] iio: chemical: ccs811: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
2025-03-31 12:12 ` [PATCH 01/37] iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:12 ` [PATCH 02/37] iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to simplify error paths Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 04/37] iio: chemical: atlas-sensor: " Jonathan Cameron
` (35 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/chemical/ccs811.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
index 75b0cb05dd86..1eab256a1e00 100644
--- a/drivers/iio/chemical/ccs811.c
+++ b/drivers/iio/chemical/ccs811.c
@@ -258,13 +258,12 @@ static int ccs811_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 = ccs811_read_info_raw(data, chan, val, 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] 58+ messages in thread
* [PATCH 04/37] iio: chemical: atlas-sensor: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (2 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 03/37] iio: chemical: ccs811: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 05/37] iio: chemical: scd4x: " Jonathan Cameron
` (34 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/chemical/atlas-sensor.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c
index baf93e5e3ca7..593b73ccbeb7 100644
--- a/drivers/iio/chemical/atlas-sensor.c
+++ b/drivers/iio/chemical/atlas-sensor.c
@@ -518,13 +518,12 @@ static int atlas_read_raw(struct iio_dev *indio_dev,
case IIO_CONCENTRATION:
case IIO_ELECTRICALCONDUCTIVITY:
case IIO_VOLTAGE:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = atlas_read_measurement(data, chan->address, ®);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
break;
default:
ret = -EINVAL;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 05/37] iio: chemical: scd4x: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (3 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 04/37] iio: chemical: atlas-sensor: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 06/37] iio: common: scmi: " Jonathan Cameron
` (33 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Roan van Dijk <roan@protonic.nl>
---
drivers/iio/chemical/scd4x.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c
index 50e3ac44422b..4877bd3e907b 100644
--- a/drivers/iio/chemical/scd4x.c
+++ b/drivers/iio/chemical/scd4x.c
@@ -358,15 +358,14 @@ static int scd4x_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
}
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&state->lock);
ret = scd4x_read_channel(state, chan->address);
mutex_unlock(&state->lock);
- 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] 58+ messages in thread
* [PATCH 06/37] iio: common: scmi: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (4 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 05/37] iio: chemical: scd4x: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 07/37] iio: common: st_sensors: " Jonathan Cameron
` (32 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Jyoti Bhayana <jbhayana@google.com>
---
drivers/iio/common/scmi_sensors/scmi_iio.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c
index ed15dcbf4cf6..1a62dd902f05 100644
--- a/drivers/iio/common/scmi_sensors/scmi_iio.c
+++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
@@ -351,12 +351,11 @@ static int scmi_iio_read_raw(struct iio_dev *iio_dev,
ret = scmi_iio_get_odr_val(iio_dev, val, val2);
return ret ? ret : IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(iio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(iio_dev))
+ return -EBUSY;
ret = scmi_iio_read_channel_data(iio_dev, ch, val, val2);
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
return ret;
default:
return -EINVAL;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 07/37] iio: common: st_sensors: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (5 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 06/37] iio: common: scmi: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 08/37] iio: gyro: adxrs290: " Jonathan Cameron
` (31 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/common/st_sensors/st_sensors_core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index e4f5a7ff7e74..8ce1dccfea4f 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -530,9 +530,8 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
int err;
struct st_sensor_data *sdata = iio_priv(indio_dev);
- err = iio_device_claim_direct_mode(indio_dev);
- if (err)
- return err;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&sdata->odr_lock);
@@ -551,7 +550,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
out:
mutex_unlock(&sdata->odr_lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return err;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 08/37] iio: gyro: adxrs290: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (6 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 07/37] iio: common: st_sensors: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 09/37] iio: health: max30102: " Jonathan Cameron
` (30 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Nishant Malpani <nish.malpani25@gmail.com>
---
drivers/iio/gyro/adxrs290.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
index 223fc181109c..8fcb41f45baa 100644
--- a/drivers/iio/gyro/adxrs290.c
+++ b/drivers/iio/gyro/adxrs290.c
@@ -290,9 +290,8 @@ static int adxrs290_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;
switch (chan->type) {
case IIO_ANGL_VEL:
@@ -316,7 +315,7 @@ static int adxrs290_read_raw(struct iio_dev *indio_dev,
break;
}
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
@@ -366,9 +365,8 @@ static int adxrs290_write_raw(struct iio_dev *indio_dev,
struct adxrs290_state *st = iio_priv(indio_dev);
int ret, lpf_idx, hpf_idx;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
switch (mask) {
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
@@ -408,7 +406,7 @@ static int adxrs290_write_raw(struct iio_dev *indio_dev,
break;
}
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 09/37] iio: health: max30102: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (7 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 08/37] iio: gyro: adxrs290: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 10/37] iio: humidity: hdc100x: Use guard(mutex) to simplify code flow Jonathan Cameron
` (29 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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 particular case is about ensuring
the mode does not change rather than ensuring we are in direct mode.
A follow up may cleanup the buffer mode claim.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/health/max30102.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c
index 1d074eb6a8c5..dacc489f7293 100644
--- a/drivers/iio/health/max30102.c
+++ b/drivers/iio/health/max30102.c
@@ -484,11 +484,11 @@ static int max30102_read_raw(struct iio_dev *indio_dev,
* things cannot 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;
ret = max30102_get_temp(data, val, true);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
} else {
ret = max30102_get_temp(data, val, false);
iio_device_release_buffer_mode(indio_dev);
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 10/37] iio: humidity: hdc100x: Use guard(mutex) to simplify code flow
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (8 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 09/37] iio: health: max30102: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 11/37] iio: humidity: hdc100x: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (28 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
By using autoreleasing on the lock a number of paths can use
direct returns allow earlier exit from functions.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/humidity/hdc100x.c | 69 +++++++++++++---------------------
1 file changed, 27 insertions(+), 42 deletions(-)
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index a303f704b7ed..fb8584423ad8 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -13,6 +13,7 @@
* https://www.ti.com/product/HDC1080/datasheet
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
@@ -206,26 +207,21 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_RAW: {
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
if (chan->type == IIO_CURRENT) {
*val = hdc100x_get_heater_status(data);
- ret = IIO_VAL_INT;
- } else {
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret) {
- mutex_unlock(&data->lock);
- return ret;
- }
-
- ret = hdc100x_get_measurement(data, chan);
- iio_device_release_direct_mode(indio_dev);
- if (ret >= 0) {
- *val = ret;
- ret = IIO_VAL_INT;
- }
+ return IIO_VAL_INT;
}
- mutex_unlock(&data->lock);
- return ret;
+ ret = iio_device_claim_direct_mode(indio_dev);
+ if (ret)
+ return ret;
+
+ ret = hdc100x_get_measurement(data, chan);
+ iio_device_release_direct_mode(indio_dev);
+ if (ret < 0)
+ return ret;
+ *val = ret;
+ return IIO_VAL_INT;
}
case IIO_CHAN_INFO_INT_TIME:
*val = 0;
@@ -256,26 +252,23 @@ static int hdc100x_write_raw(struct iio_dev *indio_dev,
int val, int val2, long mask)
{
struct hdc100x_data *data = iio_priv(indio_dev);
- int ret = -EINVAL;
switch (mask) {
- case IIO_CHAN_INFO_INT_TIME:
+ case IIO_CHAN_INFO_INT_TIME: {
if (val != 0)
return -EINVAL;
- mutex_lock(&data->lock);
- ret = hdc100x_set_it_time(data, chan->address, val2);
- mutex_unlock(&data->lock);
- return ret;
- case IIO_CHAN_INFO_RAW:
+ guard(mutex)(&data->lock);
+ return hdc100x_set_it_time(data, chan->address, val2);
+ }
+ case IIO_CHAN_INFO_RAW: {
if (chan->type != IIO_CURRENT || val2 != 0)
return -EINVAL;
- mutex_lock(&data->lock);
- ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN,
- val ? HDC100X_REG_CONFIG_HEATER_EN : 0);
- mutex_unlock(&data->lock);
- return ret;
+ guard(mutex)(&data->lock);
+ return hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN,
+ val ? HDC100X_REG_CONFIG_HEATER_EN : 0);
+ }
default:
return -EINVAL;
}
@@ -284,27 +277,19 @@ static int hdc100x_write_raw(struct iio_dev *indio_dev,
static int hdc100x_buffer_postenable(struct iio_dev *indio_dev)
{
struct hdc100x_data *data = iio_priv(indio_dev);
- int ret;
/* Buffer is enabled. First set ACQ Mode, then attach poll func */
- mutex_lock(&data->lock);
- ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE,
- HDC100X_REG_CONFIG_ACQ_MODE);
- mutex_unlock(&data->lock);
-
- return ret;
+ guard(mutex)(&data->lock);
+ return hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE,
+ HDC100X_REG_CONFIG_ACQ_MODE);
}
static int hdc100x_buffer_predisable(struct iio_dev *indio_dev)
{
struct hdc100x_data *data = iio_priv(indio_dev);
- int ret;
- mutex_lock(&data->lock);
- ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0);
- mutex_unlock(&data->lock);
-
- return ret;
+ guard(mutex)(&data->lock);
+ return hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0);
}
static const struct iio_buffer_setup_ops hdc_buffer_setup_ops = {
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 11/37] iio: humidity: hdc100x: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (9 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 10/37] iio: humidity: hdc100x: Use guard(mutex) to simplify code flow Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 12/37] iio: humidity: hdc2010: " Jonathan Cameron
` (27 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/humidity/hdc100x.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index fb8584423ad8..c2b36e682e06 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -212,12 +212,11 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
*val = hdc100x_get_heater_status(data);
return IIO_VAL_INT;
}
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = hdc100x_get_measurement(data, chan);
- 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] 58+ messages in thread
* [PATCH 12/37] iio: humidity: hdc2010: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (10 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 11/37] iio: humidity: hdc100x: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-04-01 6:59 ` Eugene Zaikonnikov
2025-03-31 12:12 ` [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions Jonathan Cameron
` (26 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Eugene Zaikonnikov <ez@norphonic.com>
---
drivers/iio/humidity/hdc2010.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/humidity/hdc2010.c b/drivers/iio/humidity/hdc2010.c
index f5867659e00f..894a8b4ab193 100644
--- a/drivers/iio/humidity/hdc2010.c
+++ b/drivers/iio/humidity/hdc2010.c
@@ -169,13 +169,12 @@ static int hdc2010_read_raw(struct iio_dev *indio_dev,
*val = hdc2010_get_heater_status(data);
return IIO_VAL_INT;
}
- 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);
ret = hdc2010_get_prim_measurement_word(data, chan);
mutex_unlock(&data->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
*val = ret;
@@ -184,13 +183,12 @@ static int hdc2010_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_PEAK: {
int ret;
- 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);
ret = hdc2010_get_peak_measurement_byte(data, chan);
mutex_unlock(&data->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
/* Scaling up the value so we can use same offset as RAW */
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions.
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (11 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 12/37] iio: humidity: hdc2010: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-04-01 6:33 ` Lorenzo Bianconi
2025-03-31 12:12 ` [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (25 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Pulling out the functionality of read_raw() and write_raw() callbacks
so that only the mode claim is done in the initial call allows for
direct returns and simpler error handling in the new __hts211_write_raw()
/ __hts211_read_raw() functions.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/humidity/hts221_core.c | 89 +++++++++++++++---------------
1 file changed, 45 insertions(+), 44 deletions(-)
diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
index 0be11470730c..ca4746f2ecba 100644
--- a/drivers/iio/humidity/hts221_core.c
+++ b/drivers/iio/humidity/hts221_core.c
@@ -418,31 +418,22 @@ static int hts221_read_oneshot(struct hts221_hw *hw, u8 addr, int *val)
return IIO_VAL_INT;
}
-static int hts221_read_raw(struct iio_dev *iio_dev,
- struct iio_chan_spec const *ch,
- int *val, int *val2, long mask)
+static int __hts221_read_raw(struct iio_dev *iio_dev,
+ struct iio_chan_spec const *ch,
+ int *val, int *val2, long mask)
{
struct hts221_hw *hw = iio_priv(iio_dev);
- int ret;
-
- ret = iio_device_claim_direct_mode(iio_dev);
- if (ret)
- return ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = hts221_read_oneshot(hw, ch->address, val);
- break;
+ return hts221_read_oneshot(hw, ch->address, val);
case IIO_CHAN_INFO_SCALE:
- ret = hts221_get_sensor_scale(hw, ch->type, val, val2);
- break;
+ return hts221_get_sensor_scale(hw, ch->type, val, val2);
case IIO_CHAN_INFO_OFFSET:
- ret = hts221_get_sensor_offset(hw, ch->type, val, val2);
- break;
+ return hts221_get_sensor_offset(hw, ch->type, val, val2);
case IIO_CHAN_INFO_SAMP_FREQ:
*val = hw->odr;
- ret = IIO_VAL_INT;
- break;
+ return IIO_VAL_INT;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO: {
u8 idx;
const struct hts221_avg *avg;
@@ -452,62 +443,72 @@ static int hts221_read_raw(struct iio_dev *iio_dev,
avg = &hts221_avg_list[HTS221_SENSOR_H];
idx = hw->sensors[HTS221_SENSOR_H].cur_avg_idx;
*val = avg->avg_avl[idx];
- ret = IIO_VAL_INT;
- break;
+ return IIO_VAL_INT;
case IIO_TEMP:
avg = &hts221_avg_list[HTS221_SENSOR_T];
idx = hw->sensors[HTS221_SENSOR_T].cur_avg_idx;
*val = avg->avg_avl[idx];
- ret = IIO_VAL_INT;
- break;
+ return IIO_VAL_INT;
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- break;
}
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
-
- iio_device_release_direct_mode(iio_dev);
-
- return ret;
}
-static int hts221_write_raw(struct iio_dev *iio_dev,
- struct iio_chan_spec const *chan,
- int val, int val2, long mask)
+static int hts221_read_raw(struct iio_dev *iio_dev,
+ struct iio_chan_spec const *ch,
+ int *val, int *val2, long mask)
{
- struct hts221_hw *hw = iio_priv(iio_dev);
int ret;
ret = iio_device_claim_direct_mode(iio_dev);
if (ret)
return ret;
+ ret = __hts221_read_raw(iio_dev, ch, val, val2, mask);
+
+ iio_device_release_direct_mode(iio_dev);
+
+ return ret;
+}
+
+static int __hts221_write_raw(struct iio_dev *iio_dev,
+ struct iio_chan_spec const *chan,
+ int val, long mask)
+{
+ struct hts221_hw *hw = iio_priv(iio_dev);
+
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
- ret = hts221_update_odr(hw, val);
- break;
+ return hts221_update_odr(hw, val);
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
switch (chan->type) {
case IIO_HUMIDITYRELATIVE:
- ret = hts221_update_avg(hw, HTS221_SENSOR_H, val);
- break;
+ return hts221_update_avg(hw, HTS221_SENSOR_H, val);
case IIO_TEMP:
- ret = hts221_update_avg(hw, HTS221_SENSOR_T, val);
- break;
+ return hts221_update_avg(hw, HTS221_SENSOR_T, val);
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- break;
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
+}
+
+static int hts221_write_raw(struct iio_dev *iio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ int ret;
+
+ ret = iio_device_claim_direct_mode(iio_dev);
+ if (ret)
+ return ret;
+
+ ret = __hts221_write_raw(iio_dev, chan, val, mask);
iio_device_release_direct_mode(iio_dev);
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (12 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-04-01 6:34 ` Lorenzo Bianconi
2025-03-31 12:12 ` [PATCH 15/37] iio: imu: inv_icm42600: " Jonathan Cameron
` (24 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/humidity/hts221_core.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
index ca4746f2ecba..bfeb0a60d3af 100644
--- a/drivers/iio/humidity/hts221_core.c
+++ b/drivers/iio/humidity/hts221_core.c
@@ -464,13 +464,12 @@ static int hts221_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;
ret = __hts221_read_raw(iio_dev, ch, val, val2, mask);
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
return ret;
}
@@ -504,13 +503,12 @@ static int hts221_write_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;
ret = __hts221_write_raw(iio_dev, chan, val, mask);
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 15/37] iio: imu: inv_icm42600: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (13 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 14:27 ` Jean-Baptiste Maneyrol
2025-03-31 12:12 ` [PATCH 16/37] iio: imu: inv_mpu6050: " Jonathan Cameron
` (23 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 21 ++++++++-----------
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 21 ++++++++-----------
.../iio/imu/inv_icm42600/inv_icm42600_temp.c | 7 +++----
3 files changed, 21 insertions(+), 28 deletions(-)
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
index 388520ec60b5..1a67f5ce1800 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
@@ -685,11 +685,10 @@ static int inv_icm42600_accel_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 = inv_icm42600_accel_read_sensor(indio_dev, chan, &data);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
*val = data;
@@ -747,20 +746,18 @@ static int inv_icm42600_accel_write_raw(struct iio_dev *indio_dev,
switch (mask) {
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;
ret = inv_icm42600_accel_write_scale(indio_dev, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return inv_icm42600_accel_write_odr(indio_dev, val, val2);
case IIO_CHAN_INFO_CALIBBIAS:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = inv_icm42600_accel_write_offset(st, chan, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
default:
return -EINVAL;
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
index 591ed78a55bb..70bac8ca28fa 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
@@ -591,11 +591,10 @@ static int inv_icm42600_gyro_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 = inv_icm42600_gyro_read_sensor(st, chan, &data);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
*val = data;
@@ -653,20 +652,18 @@ static int inv_icm42600_gyro_write_raw(struct iio_dev *indio_dev,
switch (mask) {
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;
ret = inv_icm42600_gyro_write_scale(indio_dev, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return inv_icm42600_gyro_write_odr(indio_dev, val, val2);
case IIO_CHAN_INFO_CALIBBIAS:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = inv_icm42600_gyro_write_offset(st, chan, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
default:
return -EINVAL;
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
index 213cce1c3111..f77645d92efd 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
@@ -56,11 +56,10 @@ int inv_icm42600_temp_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 = inv_icm42600_temp_read(st, &temp);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
*val = temp;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 16/37] iio: imu: inv_mpu6050: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (14 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 15/37] iio: imu: inv_icm42600: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 13:57 ` Jean-Baptiste Maneyrol
2025-03-31 12:12 ` [PATCH 17/37] iio: imu: smi240: " Jonathan Cameron
` (22 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5bcd5e797046..b8656c02354a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -755,13 +755,12 @@ inv_mpu6050_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;
mutex_lock(&st->lock);
ret = inv_mpu6050_read_channel_data(indio_dev, chan, val);
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
@@ -895,9 +894,8 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
* we should only update scale when the chip is disabled, i.e.
* not running
*/
- result = iio_device_claim_direct_mode(indio_dev);
- if (result)
- return result;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&st->lock);
result = pm_runtime_resume_and_get(pdev);
@@ -944,7 +942,7 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
pm_runtime_put_autosuspend(pdev);
error_write_raw_unlock:
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return result;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 17/37] iio: imu: smi240: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (15 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 16/37] iio: imu: inv_mpu6050: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 12:12 ` [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns Jonathan Cameron
` (21 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Shen Jianping <Jianping.Shen@de.bosch.com>
---
drivers/iio/imu/smi240.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/imu/smi240.c b/drivers/iio/imu/smi240.c
index 4492c4d013bd..d159ee59acdd 100644
--- a/drivers/iio/imu/smi240.c
+++ b/drivers/iio/imu/smi240.c
@@ -414,11 +414,10 @@ static int smi240_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 = smi240_get_data(data, chan->type, chan->channel2, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
return IIO_VAL_INT;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (16 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 17/37] iio: imu: smi240: " Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-03-31 14:31 ` David Lechner
2025-04-01 6:27 ` Lorenzo Bianconi
2025-03-31 12:12 ` [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct() Jonathan Cameron
` (20 subsequent siblings)
38 siblings, 2 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
By factoring out all the code that occurs with direct mode claimed
to a helper function, that helper function can directly return simplifying
code flow.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++---------
1 file changed, 35 insertions(+), 30 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index c1b444520d2a..17a74f5adfc0 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -614,53 +614,58 @@ st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
}
static int
-st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
- struct iio_chan_spec const *chan,
- int val, int val2, long mask)
+__st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
{
struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
int err;
- err = iio_device_claim_direct_mode(iio_dev);
- if (err)
- return err;
-
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ: {
+ struct st_lsm6dsx_hw *hw = sensor->hw;
+ struct st_lsm6dsx_sensor *ref_sensor;
+ u8 odr_val;
u16 data;
+ int odr;
val = val * 1000 + val2 / 1000;
err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
- if (!err) {
- struct st_lsm6dsx_hw *hw = sensor->hw;
- struct st_lsm6dsx_sensor *ref_sensor;
- u8 odr_val;
- int odr;
-
- ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
- odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val);
- if (odr < 0) {
- err = odr;
- goto release;
- }
-
- sensor->ext_info.slv_odr = val;
- sensor->odr = odr;
- }
- break;
+ if (err)
+ return err;
+
+ ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
+ odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val);
+ if (odr < 0)
+ return odr;
+
+ sensor->ext_info.slv_odr = val;
+ sensor->odr = odr;
+ return 0;
}
case IIO_CHAN_INFO_SCALE:
- err = st_lsm6dsx_shub_set_full_scale(sensor, val2);
- break;
+ return st_lsm6dsx_shub_set_full_scale(sensor, val2);
default:
- err = -EINVAL;
- break;
+ return -EINVAL;
}
+}
+
+static int
+st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ int ret;
+
+ ret = iio_device_claim_direct_mode(iio_dev);
+ if (ret)
+ return ret;
+
+ ret = __st_lsm6dsx_shub_write_raw(iio_dev, chan, val, val2, mask);
-release:
iio_device_release_direct_mode(iio_dev);
- return err;
+ return ret;
}
static ssize_t
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (17 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns Jonathan Cameron
@ 2025-03-31 12:12 ` Jonathan Cameron
2025-04-01 6:31 ` Lorenzo Bianconi
2025-03-31 12:13 ` [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (19 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:12 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This driver caused a false positive with __cond_lock() style solution
but is fine with the simple boolean return approach now used.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 4fdcc2acc94e..670cd217eb50 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1804,12 +1804,11 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(iio_dev);
- if (ret)
- break;
+ if (!iio_device_claim_direct(iio_dev))
+ return -EBUSY;
ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val);
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
break;
case IIO_CHAN_INFO_SAMP_FREQ:
*val = sensor->odr / 1000;
@@ -1834,11 +1833,10 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
int val, int val2, long mask)
{
struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
- int err;
+ int err = 0;
- err = iio_device_claim_direct_mode(iio_dev);
- if (err)
- return err;
+ if (!iio_device_claim_direct(iio_dev))
+ return -EBUSY;
switch (mask) {
case IIO_CHAN_INFO_SCALE:
@@ -1860,7 +1858,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
break;
}
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
return err;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (18 preceding siblings ...)
2025-03-31 12:12 ` [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-04-01 6:29 ` Lorenzo Bianconi
2025-03-31 12:13 ` [PATCH 21/37] iio: magnetometer: mag3110: Factor out core of read/write_raw() and use guard() to simplify code flow Jonathan Cameron
` (18 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Lorenzo Bianconi <lorenzo@kernel.org>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index 17a74f5adfc0..3c5e65dc0f97 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -558,12 +558,11 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(iio_dev);
- if (ret)
- break;
+ if (!iio_device_claim_direct(iio_dev))
+ return -EBUSY;
ret = st_lsm6dsx_shub_read_oneshot(sensor, ch, val);
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
break;
case IIO_CHAN_INFO_SAMP_FREQ:
*val = sensor->ext_info.slv_odr / 1000;
@@ -657,13 +656,12 @@ st_lsm6dsx_shub_write_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;
ret = __st_lsm6dsx_shub_write_raw(iio_dev, chan, val, val2, mask);
- iio_device_release_direct_mode(iio_dev);
+ iio_device_release_direct(iio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 21/37] iio: magnetometer: mag3110: Factor out core of read/write_raw() and use guard() to simplify code flow.
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (19 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 22/37] iio: magnetometer: mag3110: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (17 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
The combination of guard(mutex) and factoring out sections of code
that occur with the device held in direct mode simplifies code flow.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/magnetometer/mag3110.c | 153 ++++++++++++++---------------
1 file changed, 75 insertions(+), 78 deletions(-)
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
index 2fe8e97f2cf8..b633bdf793ed 100644
--- a/drivers/iio/magnetometer/mag3110.c
+++ b/drivers/iio/magnetometer/mag3110.c
@@ -9,6 +9,7 @@
* TODO: irq, user offset, oversampling, continuous mode
*/
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
@@ -102,17 +103,12 @@ static int mag3110_read(struct mag3110_data *data, __be16 buf[3])
{
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
ret = mag3110_request(data);
- if (ret < 0) {
- mutex_unlock(&data->lock);
+ if (ret < 0)
return ret;
- }
- ret = i2c_smbus_read_i2c_block_data(data->client,
- MAG3110_OUT_X, 3 * sizeof(__be16), (u8 *) buf);
- mutex_unlock(&data->lock);
-
- return ret;
+ return i2c_smbus_read_i2c_block_data(data->client, MAG3110_OUT_X,
+ 3 * sizeof(__be16), (u8 *) buf);
}
static ssize_t mag3110_show_int_plus_micros(char *buf,
@@ -231,19 +227,17 @@ static int mag3110_change_config(struct mag3110_data *data, u8 reg, u8 val)
int ret;
int is_active;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
is_active = mag3110_is_active(data);
- if (is_active < 0) {
- ret = is_active;
- goto fail;
- }
+ if (is_active < 0)
+ return is_active;
/* config can only be changed when in standby */
if (is_active > 0) {
ret = mag3110_standby(data);
if (ret < 0)
- goto fail;
+ return ret;
}
/*
@@ -252,23 +246,52 @@ static int mag3110_change_config(struct mag3110_data *data, u8 reg, u8 val)
*/
ret = mag3110_wait_standby(data);
if (ret < 0)
- goto fail;
+ return ret;
ret = i2c_smbus_write_byte_data(data->client, reg, val);
if (ret < 0)
- goto fail;
+ return ret;
if (is_active > 0) {
ret = mag3110_active(data);
if (ret < 0)
- goto fail;
+ return ret;
}
- ret = 0;
-fail:
- mutex_unlock(&data->lock);
+ return 0;
+}
- return ret;
+static int __mag3110_read_info_raw(struct mag3110_data *data,
+ struct iio_chan_spec const *chan,
+ int *val)
+{
+ __be16 buffer[3];
+ int ret;
+
+ switch (chan->type) {
+ case IIO_MAGN: /* in 0.1 uT / LSB */
+ ret = mag3110_read(data, buffer);
+ if (ret < 0)
+ return ret;
+ *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]),
+ chan->scan_type.realbits - 1);
+ return IIO_VAL_INT;
+
+ case IIO_TEMP: { /* in 1 C / LSB */
+ guard(mutex)(&data->lock);
+ ret = mag3110_request(data);
+ if (ret < 0)
+ return ret;
+ ret = i2c_smbus_read_byte_data(data->client,
+ MAG3110_DIE_TEMP);
+ if (ret < 0)
+ return ret;
+ *val = sign_extend32(ret, chan->scan_type.realbits - 1);
+ return IIO_VAL_INT;
+ }
+ default:
+ return -EINVAL;
+ }
}
static int mag3110_read_raw(struct iio_dev *indio_dev,
@@ -276,7 +299,6 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct mag3110_data *data = iio_priv(indio_dev);
- __be16 buffer[3];
int i, ret;
switch (mask) {
@@ -284,37 +306,7 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;
-
- switch (chan->type) {
- case IIO_MAGN: /* in 0.1 uT / LSB */
- ret = mag3110_read(data, buffer);
- if (ret < 0)
- goto release;
- *val = sign_extend32(
- be16_to_cpu(buffer[chan->scan_index]),
- chan->scan_type.realbits - 1);
- ret = IIO_VAL_INT;
- break;
- case IIO_TEMP: /* in 1 C / LSB */
- mutex_lock(&data->lock);
- ret = mag3110_request(data);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- goto release;
- }
- ret = i2c_smbus_read_byte_data(data->client,
- MAG3110_DIE_TEMP);
- mutex_unlock(&data->lock);
- if (ret < 0)
- goto release;
- *val = sign_extend32(ret,
- chan->scan_type.realbits - 1);
- ret = IIO_VAL_INT;
- break;
- default:
- ret = -EINVAL;
- }
-release:
+ ret = __mag3110_read_info_raw(data, chan, val);
iio_device_release_direct_mode(indio_dev);
return ret;
@@ -346,24 +338,18 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
return -EINVAL;
}
-static int mag3110_write_raw(struct iio_dev *indio_dev,
- struct iio_chan_spec const *chan,
- int val, int val2, long mask)
+static int __mag3110_write_raw(struct mag3110_data *data,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
{
- struct mag3110_data *data = iio_priv(indio_dev);
- int rate, ret;
-
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ int rate;
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
rate = mag3110_get_samp_freq_index(data, val, val2);
- if (rate < 0) {
- ret = -EINVAL;
- break;
- }
+ if (rate < 0)
+ return -EINVAL;
+
data->ctrl_reg1 &= 0xff & ~MAG3110_CTRL_DR_MASK
& ~MAG3110_CTRL_AC;
data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT;
@@ -371,22 +357,33 @@ static int mag3110_write_raw(struct iio_dev *indio_dev,
if (data->sleep_val < 40)
data->ctrl_reg1 |= MAG3110_CTRL_AC;
- ret = mag3110_change_config(data, MAG3110_CTRL_REG1,
- data->ctrl_reg1);
- break;
+ return mag3110_change_config(data, MAG3110_CTRL_REG1,
+ data->ctrl_reg1);
+
case IIO_CHAN_INFO_CALIBBIAS:
- if (val < -10000 || val > 10000) {
- ret = -EINVAL;
- break;
- }
- ret = i2c_smbus_write_word_swapped(data->client,
+ if (val < -10000 || val > 10000)
+ return -EINVAL;
+
+ return i2c_smbus_write_word_swapped(data->client,
MAG3110_OFF_X + 2 * chan->scan_index, val << 1);
- break;
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
+}
+
+static int mag3110_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ struct mag3110_data *data = iio_priv(indio_dev);
+ int ret;
+
+ ret = iio_device_claim_direct_mode(indio_dev);
+ if (ret)
+ return ret;
+ ret = __mag3110_write_raw(data, chan, val, val2, mask);
iio_device_release_direct_mode(indio_dev);
+
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 22/37] iio: magnetometer: mag3110: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (20 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 21/37] iio: magnetometer: mag3110: Factor out core of read/write_raw() and use guard() to simplify code flow Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 23/37] iio: magnetometer: rm3100: " Jonathan Cameron
` (16 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/magnetometer/mag3110.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
index b633bdf793ed..92d4511ed372 100644
--- a/drivers/iio/magnetometer/mag3110.c
+++ b/drivers/iio/magnetometer/mag3110.c
@@ -303,11 +303,10 @@ static int mag3110_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 = __mag3110_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:
@@ -378,11 +377,10 @@ static int mag3110_write_raw(struct iio_dev *indio_dev,
struct mag3110_data *data = iio_priv(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 = __mag3110_write_raw(data, 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] 58+ messages in thread
* [PATCH 23/37] iio: magnetometer: rm3100: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (21 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 22/37] iio: magnetometer: mag3110: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 24/37] iio: pressure: dlhl60d: " Jonathan Cameron
` (15 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/magnetometer/rm3100-core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
index c99694a77a14..e5162ee64e01 100644
--- a/drivers/iio/magnetometer/rm3100-core.c
+++ b/drivers/iio/magnetometer/rm3100-core.c
@@ -399,12 +399,11 @@ static int rm3100_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret < 0)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = rm3100_read_mag(data, chan->scan_index, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE:
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 24/37] iio: pressure: dlhl60d: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (22 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 23/37] iio: magnetometer: rm3100: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 25/37] iio: pressure: icp10100: " Jonathan Cameron
` (14 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/pressure/dlhl60d.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/dlhl60d.c b/drivers/iio/pressure/dlhl60d.c
index e99e97ea6300..e0aa12949cde 100644
--- a/drivers/iio/pressure/dlhl60d.c
+++ b/drivers/iio/pressure/dlhl60d.c
@@ -147,12 +147,11 @@ static int dlh_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 = dlh_read_direct(st, &pressure, &temperature);
- 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] 58+ messages in thread
* [PATCH 25/37] iio: pressure: icp10100: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (23 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 24/37] iio: pressure: dlhl60d: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 14:03 ` Jean-Baptiste Maneyrol
2025-03-31 12:13 ` [PATCH 26/37] iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to simplify code flow Jonathan Cameron
` (13 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/pressure/icp10100.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/pressure/icp10100.c b/drivers/iio/pressure/icp10100.c
index 3e0bf5d31ad7..1951c1cc84cf 100644
--- a/drivers/iio/pressure/icp10100.c
+++ b/drivers/iio/pressure/icp10100.c
@@ -343,9 +343,8 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev,
uint32_t pressure_mPa;
int ret;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = icp10100_get_measures(st, &raw_pressure, &raw_temp);
if (ret)
@@ -370,7 +369,7 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev,
}
error_release:
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
@@ -439,7 +438,6 @@ static int icp10100_write_raw(struct iio_dev *indio_dev,
{
struct icp10100_state *st = iio_priv(indio_dev);
unsigned int mode;
- int ret;
switch (mask) {
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
@@ -449,13 +447,12 @@ static int icp10100_write_raw(struct iio_dev *indio_dev,
mode = ilog2(val);
if (mode >= ICP10100_MODE_NB)
return -EINVAL;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&st->lock);
st->mode = mode;
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return 0;
default:
return -EINVAL;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 26/37] iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to simplify code flow
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (24 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 25/37] iio: pressure: icp10100: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 27/37] iio: pressure: mpl3115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (12 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Apply guard(mutex) to remove the need for manual release of the lock.
Factor out the code that occurs under the direct claim.
These two changes allow for direct returns simplifying code flow.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/pressure/mpl3115.c | 90 ++++++++++++++++++----------------
1 file changed, 47 insertions(+), 43 deletions(-)
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index 71ded2eee060..207031b5ff72 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -69,6 +69,52 @@ static int mpl3115_request(struct mpl3115_data *data)
return 0;
}
+static int mpl3115_read_info_raw(struct mpl3115_data *data,
+ struct iio_chan_spec const *chan, int *val)
+{
+ int ret;
+
+ switch (chan->type) {
+ case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
+ __be32 tmp = 0;
+
+ guard(mutex)(&data->lock);
+ ret = mpl3115_request(data);
+ if (ret < 0)
+ return ret;
+
+ ret = i2c_smbus_read_i2c_block_data(data->client,
+ MPL3115_OUT_PRESS,
+ 3, (u8 *) &tmp);
+ if (ret < 0)
+ return ret;
+
+ *val = be32_to_cpu(tmp) >> chan->scan_type.shift;
+ return IIO_VAL_INT;
+ }
+ case IIO_TEMP: { /* in 0.0625 celsius / LSB */
+ __be16 tmp;
+
+ guard(mutex)(&data->lock);
+ ret = mpl3115_request(data);
+ if (ret < 0)
+ return ret;
+
+ ret = i2c_smbus_read_i2c_block_data(data->client,
+ MPL3115_OUT_TEMP,
+ 2, (u8 *) &tmp);
+ if (ret < 0)
+ return ret;
+
+ *val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift,
+ chan->scan_type.realbits - 1);
+ return IIO_VAL_INT;
+ }
+ default:
+ return -EINVAL;
+ }
+}
+
static int mpl3115_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -82,49 +128,7 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
if (ret)
return ret;
- switch (chan->type) {
- case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
- __be32 tmp = 0;
-
- mutex_lock(&data->lock);
- ret = mpl3115_request(data);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- break;
- }
- ret = i2c_smbus_read_i2c_block_data(data->client,
- MPL3115_OUT_PRESS, 3, (u8 *) &tmp);
- mutex_unlock(&data->lock);
- if (ret < 0)
- break;
- *val = be32_to_cpu(tmp) >> chan->scan_type.shift;
- ret = IIO_VAL_INT;
- break;
- }
- case IIO_TEMP: { /* in 0.0625 celsius / LSB */
- __be16 tmp;
-
- mutex_lock(&data->lock);
- ret = mpl3115_request(data);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- break;
- }
- ret = i2c_smbus_read_i2c_block_data(data->client,
- MPL3115_OUT_TEMP, 2, (u8 *) &tmp);
- mutex_unlock(&data->lock);
- if (ret < 0)
- break;
- *val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift,
- chan->scan_type.realbits - 1);
- ret = IIO_VAL_INT;
- break;
- }
- default:
- ret = -EINVAL;
- break;
- }
-
+ ret = mpl3115_read_info_raw(data, chan, val);
iio_device_release_direct_mode(indio_dev);
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 27/37] iio: pressure: mpl3115: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (25 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 26/37] iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to simplify code flow Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 28/37] iio: pressure: ms5611: " Jonathan Cameron
` (11 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/pressure/mpl3115.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index 207031b5ff72..8397155555bd 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -124,12 +124,11 @@ static int mpl3115_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 = mpl3115_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:
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 28/37] iio: pressure: ms5611: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (26 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 27/37] iio: pressure: mpl3115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 29/37] iio: pressure: rohm-bm1390: " Jonathan Cameron
` (10 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/pressure/ms5611_core.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index 00c077b2a2a4..bdac27bd5a5d 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -308,7 +308,6 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
{
struct ms5611_state *st = iio_priv(indio_dev);
const struct ms5611_osr *osr = NULL;
- int ret;
if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO)
return -EINVAL;
@@ -322,9 +321,8 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
if (!osr)
return -EINVAL;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&st->lock);
@@ -334,7 +332,7 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
st->pressure_osr = osr;
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 29/37] iio: pressure: rohm-bm1390: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (27 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 28/37] iio: pressure: ms5611: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-04-01 13:14 ` Matti Vaittinen
2025-03-31 12:13 ` [PATCH 30/37] iio: pressure: zpa2326: " Jonathan Cameron
` (9 subsequent siblings)
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/pressure/rohm-bm1390.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
index 9c1197f0e742..c48231739f48 100644
--- a/drivers/iio/pressure/rohm-bm1390.c
+++ b/drivers/iio/pressure/rohm-bm1390.c
@@ -319,12 +319,11 @@ static int bm1390_read_raw(struct iio_dev *idev,
return -EINVAL;
case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(idev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(idev))
+ return -EBUSY;
ret = bm1390_read_data(data, chan, val, val2);
- iio_device_release_direct_mode(idev);
+ iio_device_release_direct(idev);
if (ret)
return ret;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 30/37] iio: pressure: zpa2326: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (28 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 29/37] iio: pressure: rohm-bm1390: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 31/37] iio: proximity: hx9023s: " Jonathan Cameron
` (8 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/pressure/zpa2326.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index 9db1c94dfc18..0a510d5fc1d4 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -1062,9 +1062,8 @@ static int zpa2326_sample_oneshot(struct iio_dev *indio_dev,
int ret;
struct zpa2326_private *priv;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = zpa2326_resume(indio_dev);
if (ret < 0)
@@ -1120,7 +1119,7 @@ static int zpa2326_sample_oneshot(struct iio_dev *indio_dev,
suspend:
zpa2326_suspend(indio_dev);
release:
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
@@ -1438,7 +1437,6 @@ static int zpa2326_set_frequency(struct iio_dev *indio_dev, int hz)
{
struct zpa2326_private *priv = iio_priv(indio_dev);
int freq;
- int err;
/* Check if requested frequency is supported. */
for (freq = 0; freq < ARRAY_SIZE(zpa2326_sampling_frequencies); freq++)
@@ -1448,13 +1446,12 @@ static int zpa2326_set_frequency(struct iio_dev *indio_dev, int hz)
return -EINVAL;
/* Don't allow changing frequency if buffered sampling is ongoing. */
- err = iio_device_claim_direct_mode(indio_dev);
- if (err)
- return err;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
priv->frequency = &zpa2326_sampling_frequencies[freq];
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 31/37] iio: proximity: hx9023s: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (29 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 30/37] iio: pressure: zpa2326: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 32/37] iio: proximity: pulsed-light: " Jonathan Cameron
` (7 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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: Yasin Lee <yasin.lee.x@gmail.com>
---
drivers/iio/proximity/hx9023s.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index 5aa8e5a22f32..5be5f4986347 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -701,12 +701,11 @@ static int hx9023s_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 = hx9023s_get_proximity(data, chan, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return hx9023s_get_samp_freq(data, val, val2);
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 32/37] iio: proximity: pulsed-light: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (30 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 31/37] iio: proximity: hx9023s: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 33/37] iio: proximity: sx9500: " Jonathan Cameron
` (6 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/proximity/pulsedlight-lidar-lite-v2.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
index f3d054b06b4c..fbf9f8513055 100644
--- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
+++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -208,7 +208,7 @@ static int lidar_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_RAW: {
u16 reg;
- if (iio_device_claim_direct_mode(indio_dev))
+ if (!iio_device_claim_direct(indio_dev))
return -EBUSY;
ret = lidar_get_measurement(data, ®);
@@ -216,7 +216,7 @@ static int lidar_read_raw(struct iio_dev *indio_dev,
*val = reg;
ret = IIO_VAL_INT;
}
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
break;
}
case IIO_CHAN_INFO_SCALE:
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 33/37] iio: proximity: sx9500: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (31 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 32/37] iio: proximity: pulsed-light: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 34/37] iio: temp: maxim_thermocouple: " Jonathan Cameron
` (5 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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/proximity/sx9500.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
index c4e94d0fb163..b5e2855975ee 100644
--- a/drivers/iio/proximity/sx9500.c
+++ b/drivers/iio/proximity/sx9500.c
@@ -387,11 +387,10 @@ static int sx9500_read_raw(struct iio_dev *indio_dev,
case IIO_PROXIMITY:
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 = sx9500_read_proximity(data, chan, val);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return sx9500_read_samp_freq(data, val, val2);
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 34/37] iio: temp: maxim_thermocouple: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (32 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 33/37] iio: proximity: sx9500: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 35/37] iio: temp: maxim_thermocouple: Drop unused mutex.h include Jonathan Cameron
` (4 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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.
Tidy up a few direct returns whilst here.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/temperature/maxim_thermocouple.c | 29 ++++++++------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index c28a7a6dea5f..a1c213d5c469 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -183,40 +183,35 @@ static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct maxim_thermocouple_data *data = iio_priv(indio_dev);
- int ret = -EINVAL;
+ int ret;
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 = maxim_thermocouple_read(data, chan, val);
- iio_device_release_direct_mode(indio_dev);
-
- if (!ret)
- return IIO_VAL_INT;
+ iio_device_release_direct(indio_dev);
+ if (ret)
+ return ret;
- break;
+ return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
switch (chan->channel2) {
case IIO_MOD_TEMP_AMBIENT:
*val = 62;
*val2 = 500000; /* 1000 * 0.0625 */
- ret = IIO_VAL_INT_PLUS_MICRO;
- break;
+ return IIO_VAL_INT_PLUS_MICRO;
default:
*val = 250; /* 1000 * 0.25 */
- ret = IIO_VAL_INT;
+ return IIO_VAL_INT;
}
- break;
case IIO_CHAN_INFO_THERMOCOUPLE_TYPE:
*val = data->tc_type;
- ret = IIO_VAL_CHAR;
- break;
+ return IIO_VAL_CHAR;
+ default:
+ return -EINVAL;
}
-
- return ret;
}
static const struct iio_info maxim_thermocouple_info = {
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 35/37] iio: temp: maxim_thermocouple: Drop unused mutex.h include.
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (33 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 34/37] iio: temp: maxim_thermocouple: " Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 36/37] staging: iio: ad5933: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
` (3 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
There are no mutex related calls in this driver.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/temperature/maxim_thermocouple.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index a1c213d5c469..a13efde76397 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -9,7 +9,6 @@
#include <linux/init.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
-#include <linux/mutex.h>
#include <linux/err.h>
#include <linux/spi/spi.h>
#include <linux/iio/iio.h>
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 36/37] staging: iio: ad5933: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (34 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 35/37] iio: temp: maxim_thermocouple: Drop unused mutex.h include Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 12:13 ` [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API Jonathan Cameron
` (2 subsequent siblings)
38 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, 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>
---
.../staging/iio/impedance-analyzer/ad5933.c | 38 ++++++++++---------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index d5544fc2fe98..5aaa43e94c52 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -271,11 +271,12 @@ static ssize_t ad5933_show_frequency(struct device *dev,
u8 d8[4];
} dat;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
+
ret = ad5933_i2c_read(st->client, this_attr->address, 3, &dat.d8[1]);
- iio_device_release_direct_mode(indio_dev);
+
+ iio_device_release_direct(indio_dev);
if (ret < 0)
return ret;
@@ -305,11 +306,12 @@ static ssize_t ad5933_store_frequency(struct device *dev,
if (val > AD5933_MAX_OUTPUT_FREQ_Hz)
return -EINVAL;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
+
ret = ad5933_set_freq(st, this_attr->address, val);
- iio_device_release_direct_mode(indio_dev);
+
+ iio_device_release_direct(indio_dev);
return ret ? ret : len;
}
@@ -384,9 +386,9 @@ static ssize_t ad5933_store(struct device *dev,
return ret;
}
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
+
mutex_lock(&st->lock);
switch ((u32)this_attr->address) {
case AD5933_OUT_RANGE:
@@ -438,7 +440,8 @@ static ssize_t ad5933_store(struct device *dev,
}
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+
+ iio_device_release_direct(indio_dev);
return ret ? ret : len;
}
@@ -506,9 +509,9 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
switch (m) {
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 = ad5933_cmd(st, AD5933_CTRL_MEASURE_TEMP);
if (ret < 0)
goto out;
@@ -521,7 +524,8 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
2, (u8 *)&dat);
if (ret < 0)
goto out;
- iio_device_release_direct_mode(indio_dev);
+
+ iio_device_release_direct(indio_dev);
*val = sign_extend32(be16_to_cpu(dat), 13);
return IIO_VAL_INT;
@@ -533,7 +537,7 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
return -EINVAL;
out:
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (35 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 36/37] staging: iio: ad5933: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-03-31 12:13 ` Jonathan Cameron
2025-03-31 13:41 ` Andy Shevchenko
2025-04-01 19:13 ` [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) David Lechner
2025-04-12 18:54 ` Marcelo Schmitt
38 siblings, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-03-31 12:13 UTC (permalink / raw)
To: linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Now there are no remaining callers of iio_device_claim_direct_mode()
and iio_device_release_direct_mode() rename those functions to ensure
they are no used in new drivers. Also make them now return booleans
in line with the sparse friendly static inline wrappers.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/industrialio-core.c | 28 ++++++++++++++++------------
include/linux/iio/iio.h | 10 ++++------
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index c9955a1c1090..c1921b55cfc5 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -2157,17 +2157,19 @@ int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
EXPORT_SYMBOL_GPL(__devm_iio_device_register);
/**
- * iio_device_claim_direct_mode - Keep device in direct mode
+ * __iio_device_claim_direct - Keep device in direct mode
* @indio_dev: the iio_dev associated with the device
*
* If the device is in direct mode it is guaranteed to stay
- * that way until iio_device_release_direct_mode() is called.
+ * that way until __iio_device_release_direct() is called.
*
- * Use with iio_device_release_direct_mode()
+ * Use with __iio_device_release_direct().
*
- * Returns: 0 on success, -EBUSY on failure.
+ * Drivers should only call iio_device_claim_direct()
+ *
+ * Returns: true on success, false on failure.
*/
-int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
+bool __iio_device_claim_direct(struct iio_dev *indio_dev)
{
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
@@ -2175,26 +2177,28 @@ int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
if (iio_buffer_enabled(indio_dev)) {
mutex_unlock(&iio_dev_opaque->mlock);
- return -EBUSY;
+ return false;
}
- return 0;
+ return true;
}
-EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
+EXPORT_SYMBOL_GPL(__iio_device_claim_direct);
/**
- * iio_device_release_direct_mode - releases claim on direct mode
+ * __iio_device_release_direct - releases claim on direct mode
* @indio_dev: the iio_dev associated with the device
*
* Release the claim. Device is no longer guaranteed to stay
* in direct mode.
*
- * Use with iio_device_claim_direct_mode()
+ * Drivers should only call iio_device_release_direct()
+ *
+ * Use with __iio_device_claim_direct()
*/
-void iio_device_release_direct_mode(struct iio_dev *indio_dev)
+void __iio_device_release_direct(struct iio_dev *indio_dev)
{
mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock);
}
-EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
+EXPORT_SYMBOL_GPL(__iio_device_release_direct);
/**
* iio_device_claim_buffer_mode - Keep device in buffer mode
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 07a0e8132e88..638cf2420fbd 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -659,8 +659,8 @@ void iio_device_unregister(struct iio_dev *indio_dev);
int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
struct module *this_mod);
int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
-int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
-void iio_device_release_direct_mode(struct iio_dev *indio_dev);
+bool __iio_device_claim_direct(struct iio_dev *indio_dev);
+void __iio_device_release_direct(struct iio_dev *indio_dev);
/*
* Helper functions that allow claim and release of direct mode
@@ -671,9 +671,7 @@ void iio_device_release_direct_mode(struct iio_dev *indio_dev);
*/
static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
{
- int ret = iio_device_claim_direct_mode(indio_dev);
-
- if (ret)
+ if (!__iio_device_claim_direct(indio_dev))
return false;
__acquire(iio_dev);
@@ -683,7 +681,7 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)
static inline void iio_device_release_direct(struct iio_dev *indio_dev)
{
- iio_device_release_direct_mode(indio_dev);
+ __iio_device_release_direct(indio_dev);
__release(indio_dev);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
2025-03-31 12:13 ` [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API Jonathan Cameron
@ 2025-03-31 13:41 ` Andy Shevchenko
2025-03-31 14:07 ` David Lechner
2025-04-05 16:34 ` Jonathan Cameron
0 siblings, 2 replies; 58+ messages in thread
From: Andy Shevchenko @ 2025-03-31 13:41 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Jonathan Cameron
On Mon, Mar 31, 2025 at 3:17 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Now there are no remaining callers of iio_device_claim_direct_mode()
> and iio_device_release_direct_mode() rename those functions to ensure
> they are no used in new drivers. Also make them now return booleans
not used
> in line with the sparse friendly static inline wrappers.
...
> /**
> - * iio_device_claim_direct_mode - Keep device in direct mode
> + * __iio_device_claim_direct - Keep device in direct mode
> * @indio_dev: the iio_dev associated with the device
> *
> * If the device is in direct mode it is guaranteed to stay
> - * that way until iio_device_release_direct_mode() is called.
> + * that way until __iio_device_release_direct() is called.
> *
> - * Use with iio_device_release_direct_mode()
> + * Use with __iio_device_release_direct().
> *
> - * Returns: 0 on success, -EBUSY on failure.
> + * Drivers should only call iio_device_claim_direct()
Missed period.
> + * Returns: true on success, false on failure.
> */
...
> -EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
> +EXPORT_SYMBOL_GPL(__iio_device_claim_direct);
Can we move it to the namespace while at it?
...
> /**
> - * iio_device_release_direct_mode - releases claim on direct mode
> + * __iio_device_release_direct - releases claim on direct mode
> * @indio_dev: the iio_dev associated with the device
> *
> * Release the claim. Device is no longer guaranteed to stay
> * in direct mode.
> *
> - * Use with iio_device_claim_direct_mode()
> + * Drivers should only call iio_device_release_direct()
Missed period.
> + * Use with __iio_device_claim_direct()
> */
...
> -EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
> +EXPORT_SYMBOL_GPL(__iio_device_release_direct);
Namespace?
Note, the good outcome of the namespace is that we can easily see who
(ab)uses these... OTOH, there are static inline functions in the
header, which provokes this to add MODULE_IMPORT_NS() into the header
as well. That said, perhaps also get rid of static inliners and have
them to be real functions?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 16/37] iio: imu: inv_mpu6050: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 ` [PATCH 16/37] iio: imu: inv_mpu6050: " Jonathan Cameron
@ 2025-03-31 13:57 ` Jean-Baptiste Maneyrol
0 siblings, 0 replies; 58+ messages in thread
From: Jean-Baptiste Maneyrol @ 2025-03-31 13:57 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio@vger.kernel.org
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov, Shen Jianping,
Lorenzo Bianconi, Matti Vaittinen, Yasin Lee, Andy Shevchenko,
Jonathan Cameron
Hello Jonathan,
looks good, thanks for the patch.
Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Thanks,
JB
________________________________________
From: Jonathan Cameron <jic23@kernel.org>
Sent: Monday, March 31, 2025 14:12
To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
Cc: David Lechner <dlechner@baylibre.com>; Nuno Sá <nuno.sa@analog.com>; Cosmin Tanislav <demonsingur@gmail.com>; Roan van Dijk <roan@protonic.nl>; Jyoti Bhayana <jbhayana@google.com>; Nishant Malpani <nish.malpani25@gmail.com>; Eugene Zaikonnikov <ez@norphonic.com>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Shen Jianping <Jianping.Shen@de.bosch.com>; Lorenzo Bianconi <lorenzo@kernel.org>; Matti Vaittinen <mazziesaccount@gmail.com>; Yasin Lee <yasin.lee.x@gmail.com>; Andy Shevchenko <andy.shevchenko@gmail.com>; Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 16/37] iio: imu: inv_mpu6050: Switch to sparse friendly iio_device_claim/release_direct()
This Message Is From an External Sender
This message came from outside your organization.
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: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 5bcd5e797046..b8656c02354a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -755,13 +755,12 @@ inv_mpu6050_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;
mutex_lock(&st->lock);
ret = inv_mpu6050_read_channel_data(indio_dev, chan, val);
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
@@ -895,9 +894,8 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
* we should only update scale when the chip is disabled, i.e.
* not running
*/
- result = iio_device_claim_direct_mode(indio_dev);
- if (result)
- return result;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&st->lock);
result = pm_runtime_resume_and_get(pdev);
@@ -944,7 +942,7 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
pm_runtime_put_autosuspend(pdev);
error_write_raw_unlock:
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return result;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH 25/37] iio: pressure: icp10100: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:13 ` [PATCH 25/37] iio: pressure: icp10100: " Jonathan Cameron
@ 2025-03-31 14:03 ` Jean-Baptiste Maneyrol
0 siblings, 0 replies; 58+ messages in thread
From: Jean-Baptiste Maneyrol @ 2025-03-31 14:03 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio@vger.kernel.org
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov, Shen Jianping,
Lorenzo Bianconi, Matti Vaittinen, Yasin Lee, Andy Shevchenko,
Jonathan Cameron
Hello Jonathan,
looks good, thanks for the patch.
Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Thanks,
JB
________________________________________
From: Jonathan Cameron <jic23@kernel.org>
Sent: Monday, March 31, 2025 14:13
To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
Cc: David Lechner <dlechner@baylibre.com>; Nuno Sá <nuno.sa@analog.com>; Cosmin Tanislav <demonsingur@gmail.com>; Roan van Dijk <roan@protonic.nl>; Jyoti Bhayana <jbhayana@google.com>; Nishant Malpani <nish.malpani25@gmail.com>; Eugene Zaikonnikov <ez@norphonic.com>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Shen Jianping <Jianping.Shen@de.bosch.com>; Lorenzo Bianconi <lorenzo@kernel.org>; Matti Vaittinen <mazziesaccount@gmail.com>; Yasin Lee <yasin.lee.x@gmail.com>; Andy Shevchenko <andy.shevchenko@gmail.com>; Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 25/37] iio: pressure: icp10100: Switch to sparse friendly iio_device_claim/release_direct()
This Message Is From an External Sender
This message came from outside your organization.
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/pressure/icp10100.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/pressure/icp10100.c b/drivers/iio/pressure/icp10100.c
index 3e0bf5d31ad7..1951c1cc84cf 100644
--- a/drivers/iio/pressure/icp10100.c
+++ b/drivers/iio/pressure/icp10100.c
@@ -343,9 +343,8 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev,
uint32_t pressure_mPa;
int ret;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = icp10100_get_measures(st, &raw_pressure, &raw_temp);
if (ret)
@@ -370,7 +369,7 @@ static int icp10100_read_raw_measures(struct iio_dev *indio_dev,
}
error_release:
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
}
@@ -439,7 +438,6 @@ static int icp10100_write_raw(struct iio_dev *indio_dev,
{
struct icp10100_state *st = iio_priv(indio_dev);
unsigned int mode;
- int ret;
switch (mask) {
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
@@ -449,13 +447,12 @@ static int icp10100_write_raw(struct iio_dev *indio_dev,
mode = ilog2(val);
if (mode >= ICP10100_MODE_NB)
return -EINVAL;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
mutex_lock(&st->lock);
st->mode = mode;
mutex_unlock(&st->lock);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return 0;
default:
return -EINVAL;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
2025-03-31 13:41 ` Andy Shevchenko
@ 2025-03-31 14:07 ` David Lechner
2025-04-05 16:34 ` Jonathan Cameron
1 sibling, 0 replies; 58+ messages in thread
From: David Lechner @ 2025-03-31 14:07 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Cameron
Cc: linux-iio, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Jonathan Cameron
On 3/31/25 8:41 AM, Andy Shevchenko wrote:
> That said, perhaps also get rid of static inliners and have
> them to be real functions?
>
That requires fixing sparse first. It doesn't currently support __cond_acquires().
So we are suck with static inline until then.
longer explanation: https://lore.kernel.org/linux-iio/20250209180624.701140-1-jic23@kernel.org/
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 15/37] iio: imu: inv_icm42600: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 ` [PATCH 15/37] iio: imu: inv_icm42600: " Jonathan Cameron
@ 2025-03-31 14:27 ` Jean-Baptiste Maneyrol
0 siblings, 0 replies; 58+ messages in thread
From: Jean-Baptiste Maneyrol @ 2025-03-31 14:27 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio@vger.kernel.org
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov, Shen Jianping,
Lorenzo Bianconi, Matti Vaittinen, Yasin Lee, Andy Shevchenko,
Jonathan Cameron
Hello Jonathan,
looks good for me, thanks for the patch.
Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Thanks,
JB
________________________________________
From: Jonathan Cameron <jic23@kernel.org>
Sent: Monday, March 31, 2025 14:12
To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
Cc: David Lechner <dlechner@baylibre.com>; Nuno Sá <nuno.sa@analog.com>; Cosmin Tanislav <demonsingur@gmail.com>; Roan van Dijk <roan@protonic.nl>; Jyoti Bhayana <jbhayana@google.com>; Nishant Malpani <nish.malpani25@gmail.com>; Eugene Zaikonnikov <ez@norphonic.com>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Shen Jianping <Jianping.Shen@de.bosch.com>; Lorenzo Bianconi <lorenzo@kernel.org>; Matti Vaittinen <mazziesaccount@gmail.com>; Yasin Lee <yasin.lee.x@gmail.com>; Andy Shevchenko <andy.shevchenko@gmail.com>; Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 15/37] iio: imu: inv_icm42600: Switch to sparse friendly iio_device_claim/release_direct()
This Message Is From an External Sender
This message came from outside your organization.
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: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 21 ++++++++-----------
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 21 ++++++++-----------
.../iio/imu/inv_icm42600/inv_icm42600_temp.c | 7 +++----
3 files changed, 21 insertions(+), 28 deletions(-)
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
index 388520ec60b5..1a67f5ce1800 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
@@ -685,11 +685,10 @@ static int inv_icm42600_accel_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 = inv_icm42600_accel_read_sensor(indio_dev, chan, &data);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
*val = data;
@@ -747,20 +746,18 @@ static int inv_icm42600_accel_write_raw(struct iio_dev *indio_dev,
switch (mask) {
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;
ret = inv_icm42600_accel_write_scale(indio_dev, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return inv_icm42600_accel_write_odr(indio_dev, val, val2);
case IIO_CHAN_INFO_CALIBBIAS:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = inv_icm42600_accel_write_offset(st, chan, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
default:
return -EINVAL;
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
index 591ed78a55bb..70bac8ca28fa 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
@@ -591,11 +591,10 @@ static int inv_icm42600_gyro_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 = inv_icm42600_gyro_read_sensor(st, chan, &data);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
*val = data;
@@ -653,20 +652,18 @@ static int inv_icm42600_gyro_write_raw(struct iio_dev *indio_dev,
switch (mask) {
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;
ret = inv_icm42600_gyro_write_scale(indio_dev, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
return inv_icm42600_gyro_write_odr(indio_dev, val, val2);
case IIO_CHAN_INFO_CALIBBIAS:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
+ if (!iio_device_claim_direct(indio_dev))
+ return -EBUSY;
ret = inv_icm42600_gyro_write_offset(st, chan, val, val2);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
return ret;
default:
return -EINVAL;
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
index 213cce1c3111..f77645d92efd 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
@@ -56,11 +56,10 @@ int inv_icm42600_temp_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 = inv_icm42600_temp_read(st, &temp);
- iio_device_release_direct_mode(indio_dev);
+ iio_device_release_direct(indio_dev);
if (ret)
return ret;
*val = temp;
--
2.48.1
^ permalink raw reply related [flat|nested] 58+ messages in thread
* Re: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
2025-03-31 12:12 ` [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns Jonathan Cameron
@ 2025-03-31 14:31 ` David Lechner
2025-04-01 6:28 ` Lorenzo Bianconi
2025-04-01 6:27 ` Lorenzo Bianconi
1 sibling, 1 reply; 58+ messages in thread
From: David Lechner @ 2025-03-31 14:31 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio
Cc: Nuno Sá, Cosmin Tanislav, Roan van Dijk, Jyoti Bhayana,
Nishant Malpani, Eugene Zaikonnikov, Jean-Baptiste Maneyrol,
Shen Jianping, Lorenzo Bianconi, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
On 3/31/25 7:12 AM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> By factoring out all the code that occurs with direct mode claimed
> to a helper function, that helper function can directly return simplifying
> code flow.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++---------
> 1 file changed, 35 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> index c1b444520d2a..17a74f5adfc0 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> @@ -614,53 +614,58 @@ st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
> }
>
> static int
> -st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> - struct iio_chan_spec const *chan,
> - int val, int val2, long mask)
> +__st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> {
> struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> int err;
>
> - err = iio_device_claim_direct_mode(iio_dev);
> - if (err)
> - return err;
> -
> switch (mask) {
> case IIO_CHAN_INFO_SAMP_FREQ: {
> + struct st_lsm6dsx_hw *hw = sensor->hw;
> + struct st_lsm6dsx_sensor *ref_sensor;
> + u8 odr_val;
> u16 data;
> + int odr;
>
I would be tempted to rename `err` to `ret` so we don't have to introduce
a new `odr` variable.
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
2025-03-31 12:12 ` [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns Jonathan Cameron
2025-03-31 14:31 ` David Lechner
@ 2025-04-01 6:27 ` Lorenzo Bianconi
1 sibling, 0 replies; 58+ messages in thread
From: Lorenzo Bianconi @ 2025-04-01 6:27 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
[-- Attachment #1: Type: text/plain, Size: 3122 bytes --]
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> By factoring out all the code that occurs with direct mode claimed
> to a helper function, that helper function can directly return simplifying
> code flow.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++---------
> 1 file changed, 35 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> index c1b444520d2a..17a74f5adfc0 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> @@ -614,53 +614,58 @@ st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
> }
>
> static int
> -st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> - struct iio_chan_spec const *chan,
> - int val, int val2, long mask)
> +__st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> {
> struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> int err;
>
> - err = iio_device_claim_direct_mode(iio_dev);
> - if (err)
> - return err;
> -
> switch (mask) {
> case IIO_CHAN_INFO_SAMP_FREQ: {
> + struct st_lsm6dsx_hw *hw = sensor->hw;
> + struct st_lsm6dsx_sensor *ref_sensor;
> + u8 odr_val;
> u16 data;
> + int odr;
>
> val = val * 1000 + val2 / 1000;
> err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
> - if (!err) {
> - struct st_lsm6dsx_hw *hw = sensor->hw;
> - struct st_lsm6dsx_sensor *ref_sensor;
> - u8 odr_val;
> - int odr;
> -
> - ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> - odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val);
> - if (odr < 0) {
> - err = odr;
> - goto release;
> - }
> -
> - sensor->ext_info.slv_odr = val;
> - sensor->odr = odr;
> - }
> - break;
> + if (err)
> + return err;
> +
> + ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> + odr = st_lsm6dsx_check_odr(ref_sensor, val, &odr_val);
> + if (odr < 0)
> + return odr;
> +
> + sensor->ext_info.slv_odr = val;
> + sensor->odr = odr;
> + return 0;
> }
> case IIO_CHAN_INFO_SCALE:
> - err = st_lsm6dsx_shub_set_full_scale(sensor, val2);
> - break;
> + return st_lsm6dsx_shub_set_full_scale(sensor, val2);
> default:
> - err = -EINVAL;
> - break;
> + return -EINVAL;
> }
> +}
> +
> +static int
> +st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + int ret;
> +
> + ret = iio_device_claim_direct_mode(iio_dev);
> + if (ret)
> + return ret;
> +
> + ret = __st_lsm6dsx_shub_write_raw(iio_dev, chan, val, val2, mask);
>
> -release:
> iio_device_release_direct_mode(iio_dev);
>
> - return err;
> + return ret;
> }
>
> static ssize_t
> --
> 2.48.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
2025-03-31 14:31 ` David Lechner
@ 2025-04-01 6:28 ` Lorenzo Bianconi
2025-04-06 13:15 ` Jonathan Cameron
0 siblings, 1 reply; 58+ messages in thread
From: Lorenzo Bianconi @ 2025-04-01 6:28 UTC (permalink / raw)
To: David Lechner
Cc: Jonathan Cameron, linux-iio, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
[-- Attachment #1: Type: text/plain, Size: 1821 bytes --]
> On 3/31/25 7:12 AM, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > By factoring out all the code that occurs with direct mode claimed
> > to a helper function, that helper function can directly return simplifying
> > code flow.
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++---------
> > 1 file changed, 35 insertions(+), 30 deletions(-)
> >
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > index c1b444520d2a..17a74f5adfc0 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > @@ -614,53 +614,58 @@ st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
> > }
> >
> > static int
> > -st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> > - struct iio_chan_spec const *chan,
> > - int val, int val2, long mask)
> > +__st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> > + struct iio_chan_spec const *chan,
> > + int val, int val2, long mask)
> > {
> > struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> > int err;
> >
> > - err = iio_device_claim_direct_mode(iio_dev);
> > - if (err)
> > - return err;
> > -
> > switch (mask) {
> > case IIO_CHAN_INFO_SAMP_FREQ: {
> > + struct st_lsm6dsx_hw *hw = sensor->hw;
> > + struct st_lsm6dsx_sensor *ref_sensor;
> > + u8 odr_val;
> > u16 data;
> > + int odr;
> >
> I would be tempted to rename `err` to `ret` so we don't have to introduce
> a new `odr` variable.
I guess keeping odr variable makes the code more readable.
Regards,
Lorenzo
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:13 ` [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-04-01 6:29 ` Lorenzo Bianconi
0 siblings, 0 replies; 58+ messages in thread
From: Lorenzo Bianconi @ 2025-04-01 6:29 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
[-- Attachment #1: Type: text/plain, Size: 1775 bytes --]
> 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: Lorenzo Bianconi <lorenzo@kernel.org>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> index 17a74f5adfc0..3c5e65dc0f97 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> @@ -558,12 +558,11 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - ret = iio_device_claim_direct_mode(iio_dev);
> - if (ret)
> - break;
> + if (!iio_device_claim_direct(iio_dev))
> + return -EBUSY;
>
> ret = st_lsm6dsx_shub_read_oneshot(sensor, ch, val);
> - iio_device_release_direct_mode(iio_dev);
> + iio_device_release_direct(iio_dev);
> break;
> case IIO_CHAN_INFO_SAMP_FREQ:
> *val = sensor->ext_info.slv_odr / 1000;
> @@ -657,13 +656,12 @@ st_lsm6dsx_shub_write_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;
>
> ret = __st_lsm6dsx_shub_write_raw(iio_dev, chan, val, val2, mask);
>
> - iio_device_release_direct_mode(iio_dev);
> + iio_device_release_direct(iio_dev);
>
> return ret;
> }
> --
> 2.48.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct()
2025-03-31 12:12 ` [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct() Jonathan Cameron
@ 2025-04-01 6:31 ` Lorenzo Bianconi
0 siblings, 0 replies; 58+ messages in thread
From: Lorenzo Bianconi @ 2025-04-01 6:31 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
[-- Attachment #1: Type: text/plain, Size: 1952 bytes --]
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> This driver caused a false positive with __cond_lock() style solution
> but is fine with the simple boolean return approach now used.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 4fdcc2acc94e..670cd217eb50 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1804,12 +1804,11 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - ret = iio_device_claim_direct_mode(iio_dev);
> - if (ret)
> - break;
> + if (!iio_device_claim_direct(iio_dev))
> + return -EBUSY;
>
> ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val);
> - iio_device_release_direct_mode(iio_dev);
> + iio_device_release_direct(iio_dev);
> break;
> case IIO_CHAN_INFO_SAMP_FREQ:
> *val = sensor->odr / 1000;
> @@ -1834,11 +1833,10 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
> int val, int val2, long mask)
> {
> struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> - int err;
> + int err = 0;
>
> - err = iio_device_claim_direct_mode(iio_dev);
> - if (err)
> - return err;
> + if (!iio_device_claim_direct(iio_dev))
> + return -EBUSY;
>
> switch (mask) {
> case IIO_CHAN_INFO_SCALE:
> @@ -1860,7 +1858,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
> break;
> }
>
> - iio_device_release_direct_mode(iio_dev);
> + iio_device_release_direct(iio_dev);
>
> return err;
> }
> --
> 2.48.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions.
2025-03-31 12:12 ` [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions Jonathan Cameron
@ 2025-04-01 6:33 ` Lorenzo Bianconi
0 siblings, 0 replies; 58+ messages in thread
From: Lorenzo Bianconi @ 2025-04-01 6:33 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
[-- Attachment #1: Type: text/plain, Size: 4803 bytes --]
On Mar 31, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Pulling out the functionality of read_raw() and write_raw() callbacks
> so that only the mode claim is done in the initial call allows for
> direct returns and simpler error handling in the new __hts211_write_raw()
> / __hts211_read_raw() functions.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/humidity/hts221_core.c | 89 +++++++++++++++---------------
> 1 file changed, 45 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
> index 0be11470730c..ca4746f2ecba 100644
> --- a/drivers/iio/humidity/hts221_core.c
> +++ b/drivers/iio/humidity/hts221_core.c
> @@ -418,31 +418,22 @@ static int hts221_read_oneshot(struct hts221_hw *hw, u8 addr, int *val)
> return IIO_VAL_INT;
> }
>
> -static int hts221_read_raw(struct iio_dev *iio_dev,
> - struct iio_chan_spec const *ch,
> - int *val, int *val2, long mask)
> +static int __hts221_read_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *ch,
> + int *val, int *val2, long mask)
> {
> struct hts221_hw *hw = iio_priv(iio_dev);
> - int ret;
> -
> - ret = iio_device_claim_direct_mode(iio_dev);
> - if (ret)
> - return ret;
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - ret = hts221_read_oneshot(hw, ch->address, val);
> - break;
> + return hts221_read_oneshot(hw, ch->address, val);
> case IIO_CHAN_INFO_SCALE:
> - ret = hts221_get_sensor_scale(hw, ch->type, val, val2);
> - break;
> + return hts221_get_sensor_scale(hw, ch->type, val, val2);
> case IIO_CHAN_INFO_OFFSET:
> - ret = hts221_get_sensor_offset(hw, ch->type, val, val2);
> - break;
> + return hts221_get_sensor_offset(hw, ch->type, val, val2);
> case IIO_CHAN_INFO_SAMP_FREQ:
> *val = hw->odr;
> - ret = IIO_VAL_INT;
> - break;
> + return IIO_VAL_INT;
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO: {
> u8 idx;
> const struct hts221_avg *avg;
> @@ -452,62 +443,72 @@ static int hts221_read_raw(struct iio_dev *iio_dev,
> avg = &hts221_avg_list[HTS221_SENSOR_H];
> idx = hw->sensors[HTS221_SENSOR_H].cur_avg_idx;
> *val = avg->avg_avl[idx];
> - ret = IIO_VAL_INT;
> - break;
> + return IIO_VAL_INT;
> case IIO_TEMP:
> avg = &hts221_avg_list[HTS221_SENSOR_T];
> idx = hw->sensors[HTS221_SENSOR_T].cur_avg_idx;
> *val = avg->avg_avl[idx];
> - ret = IIO_VAL_INT;
> - break;
> + return IIO_VAL_INT;
> default:
> - ret = -EINVAL;
> - break;
> + return -EINVAL;
> }
> - break;
> }
> default:
> - ret = -EINVAL;
> - break;
> + return -EINVAL;
> }
> -
> - iio_device_release_direct_mode(iio_dev);
> -
> - return ret;
> }
>
> -static int hts221_write_raw(struct iio_dev *iio_dev,
> - struct iio_chan_spec const *chan,
> - int val, int val2, long mask)
> +static int hts221_read_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *ch,
> + int *val, int *val2, long mask)
> {
> - struct hts221_hw *hw = iio_priv(iio_dev);
> int ret;
>
> ret = iio_device_claim_direct_mode(iio_dev);
> if (ret)
> return ret;
>
> + ret = __hts221_read_raw(iio_dev, ch, val, val2, mask);
> +
> + iio_device_release_direct_mode(iio_dev);
> +
> + return ret;
> +}
> +
> +static int __hts221_write_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *chan,
> + int val, long mask)
> +{
> + struct hts221_hw *hw = iio_priv(iio_dev);
> +
> switch (mask) {
> case IIO_CHAN_INFO_SAMP_FREQ:
> - ret = hts221_update_odr(hw, val);
> - break;
> + return hts221_update_odr(hw, val);
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> switch (chan->type) {
> case IIO_HUMIDITYRELATIVE:
> - ret = hts221_update_avg(hw, HTS221_SENSOR_H, val);
> - break;
> + return hts221_update_avg(hw, HTS221_SENSOR_H, val);
> case IIO_TEMP:
> - ret = hts221_update_avg(hw, HTS221_SENSOR_T, val);
> - break;
> + return hts221_update_avg(hw, HTS221_SENSOR_T, val);
> default:
> - ret = -EINVAL;
> - break;
> + return -EINVAL;
> }
> - break;
> default:
> - ret = -EINVAL;
> - break;
> + return -EINVAL;
> }
> +}
> +
> +static int hts221_write_raw(struct iio_dev *iio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + int ret;
> +
> + ret = iio_device_claim_direct_mode(iio_dev);
> + if (ret)
> + return ret;
> +
> + ret = __hts221_write_raw(iio_dev, chan, val, mask);
>
> iio_device_release_direct_mode(iio_dev);
>
> --
> 2.48.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 ` [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
@ 2025-04-01 6:34 ` Lorenzo Bianconi
0 siblings, 0 replies; 58+ messages in thread
From: Lorenzo Bianconi @ 2025-04-01 6:34 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
[-- Attachment #1: Type: text/plain, Size: 1613 bytes --]
On Mar 31, 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>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/iio/humidity/hts221_core.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
> index ca4746f2ecba..bfeb0a60d3af 100644
> --- a/drivers/iio/humidity/hts221_core.c
> +++ b/drivers/iio/humidity/hts221_core.c
> @@ -464,13 +464,12 @@ static int hts221_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;
>
> ret = __hts221_read_raw(iio_dev, ch, val, val2, mask);
>
> - iio_device_release_direct_mode(iio_dev);
> + iio_device_release_direct(iio_dev);
>
> return ret;
> }
> @@ -504,13 +503,12 @@ static int hts221_write_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;
>
> ret = __hts221_write_raw(iio_dev, chan, val, mask);
>
> - iio_device_release_direct_mode(iio_dev);
> + iio_device_release_direct(iio_dev);
>
> return ret;
> }
> --
> 2.48.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 12/37] iio: humidity: hdc2010: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:12 ` [PATCH 12/37] iio: humidity: hdc2010: " Jonathan Cameron
@ 2025-04-01 6:59 ` Eugene Zaikonnikov
0 siblings, 0 replies; 58+ messages in thread
From: Eugene Zaikonnikov @ 2025-04-01 6:59 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio
Hi Jonathan,
Thanks for the patch. It looks good to me.
Acked-by: Eugene Zaikonnikov <ez@norphonic.com>
Jonathan Cameron <jic23@kernel.org> writes:
> 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: Eugene Zaikonnikov <ez@norphonic.com>
> ---
> drivers/iio/humidity/hdc2010.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/humidity/hdc2010.c b/drivers/iio/humidity/hdc2010.c
> index f5867659e00f..894a8b4ab193 100644
> --- a/drivers/iio/humidity/hdc2010.c
> +++ b/drivers/iio/humidity/hdc2010.c
> @@ -169,13 +169,12 @@ static int hdc2010_read_raw(struct iio_dev *indio_dev,
> *val = hdc2010_get_heater_status(data);
> return IIO_VAL_INT;
> }
> - 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);
> ret = hdc2010_get_prim_measurement_word(data, chan);
> mutex_unlock(&data->lock);
> - iio_device_release_direct_mode(indio_dev);
> + iio_device_release_direct(indio_dev);
> if (ret < 0)
> return ret;
> *val = ret;
> @@ -184,13 +183,12 @@ static int hdc2010_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_PEAK: {
> int ret;
>
> - 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);
> ret = hdc2010_get_peak_measurement_byte(data, chan);
> mutex_unlock(&data->lock);
> - iio_device_release_direct_mode(indio_dev);
> + iio_device_release_direct(indio_dev);
> if (ret < 0)
> return ret;
> /* Scaling up the value so we can use same offset as RAW */
--
Regards,
Eugene Zaikonnikov
Norphonic AS
Tel: +47 98 23 97 73
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 29/37] iio: pressure: rohm-bm1390: Switch to sparse friendly iio_device_claim/release_direct()
2025-03-31 12:13 ` [PATCH 29/37] iio: pressure: rohm-bm1390: " Jonathan Cameron
@ 2025-04-01 13:14 ` Matti Vaittinen
0 siblings, 0 replies; 58+ messages in thread
From: Matti Vaittinen @ 2025-04-01 13:14 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio
Cc: David Lechner, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Yasin Lee, Andy Shevchenko, Jonathan Cameron
On 31/03/2025 15:13, 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>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Yours,
-- Matti
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest)
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (36 preceding siblings ...)
2025-03-31 12:13 ` [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API Jonathan Cameron
@ 2025-04-01 19:13 ` David Lechner
2025-04-06 13:20 ` Jonathan Cameron
2025-04-12 18:54 ` Marcelo Schmitt
38 siblings, 1 reply; 58+ messages in thread
From: David Lechner @ 2025-04-01 19:13 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio
Cc: Nuno Sá, Cosmin Tanislav, Roan van Dijk, Jyoti Bhayana,
Nishant Malpani, Eugene Zaikonnikov, Jean-Baptiste Maneyrol,
Shen Jianping, Lorenzo Bianconi, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
On 3/31/25 7:12 AM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Firstly, sorry for the huge patch set!
>
Reviewed-by: David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
2025-03-31 13:41 ` Andy Shevchenko
2025-03-31 14:07 ` David Lechner
@ 2025-04-05 16:34 ` Jonathan Cameron
2025-04-05 16:46 ` Andy Shevchenko
1 sibling, 1 reply; 58+ messages in thread
From: Jonathan Cameron @ 2025-04-05 16:34 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Jonathan Cameron
On Mon, 31 Mar 2025 16:41:42 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Mon, Mar 31, 2025 at 3:17 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Now there are no remaining callers of iio_device_claim_direct_mode()
> > and iio_device_release_direct_mode() rename those functions to ensure
> > they are no used in new drivers. Also make them now return booleans
>
> not used
>
> > in line with the sparse friendly static inline wrappers.
>
> ...
>
> > /**
> > - * iio_device_claim_direct_mode - Keep device in direct mode
> > + * __iio_device_claim_direct - Keep device in direct mode
> > * @indio_dev: the iio_dev associated with the device
> > *
> > * If the device is in direct mode it is guaranteed to stay
> > - * that way until iio_device_release_direct_mode() is called.
> > + * that way until __iio_device_release_direct() is called.
> > *
> > - * Use with iio_device_release_direct_mode()
> > + * Use with __iio_device_release_direct().
> > *
> > - * Returns: 0 on success, -EBUSY on failure.
> > + * Drivers should only call iio_device_claim_direct()
>
> Missed period.
>
> > + * Returns: true on success, false on failure.
> > */
>
> ...
>
> > -EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
> > +EXPORT_SYMBOL_GPL(__iio_device_claim_direct);
>
> Can we move it to the namespace while at it?
I'm personally not convinced by the namespace defaults in headers
thing pwm.h does. So to namespace these is a massive patch
adding the import to most drivers.
So I'd rather deal with that later.
>
> ...
>
> > /**
> > - * iio_device_release_direct_mode - releases claim on direct mode
> > + * __iio_device_release_direct - releases claim on direct mode
> > * @indio_dev: the iio_dev associated with the device
> > *
> > * Release the claim. Device is no longer guaranteed to stay
> > * in direct mode.
> > *
> > - * Use with iio_device_claim_direct_mode()
> > + * Drivers should only call iio_device_release_direct()
>
> Missed period.
>
> > + * Use with __iio_device_claim_direct()
> > */
>
> ...
>
> > -EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
> > +EXPORT_SYMBOL_GPL(__iio_device_release_direct);
>
> Namespace?
> Note, the good outcome of the namespace is that we can easily see who
> (ab)uses these... OTOH, there are static inline functions in the
> header, which provokes this to add MODULE_IMPORT_NS() into the header
> as well. That said, perhaps also get rid of static inliners and have
> them to be real functions?
As David said. Unfortunately not :(
Though static inlines using these is fine as any driver that
doesn't import will still fail in the correct way. It will just
be a bit 'weird' to fail like that. The missing namespace
warnings are pretty obvious though so that should be fine.
Jonathan
>
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
2025-04-05 16:34 ` Jonathan Cameron
@ 2025-04-05 16:46 ` Andy Shevchenko
0 siblings, 0 replies; 58+ messages in thread
From: Andy Shevchenko @ 2025-04-05 16:46 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Jonathan Cameron
On Sat, Apr 5, 2025 at 7:34 PM Jonathan Cameron <jic23@kernel.org> wrote:
> On Mon, 31 Mar 2025 16:41:42 +0300
> Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> > On Mon, Mar 31, 2025 at 3:17 PM Jonathan Cameron <jic23@kernel.org> wrote:
...
> > > -EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
> > > +EXPORT_SYMBOL_GPL(__iio_device_claim_direct);
> >
> > Can we move it to the namespace while at it?
>
> I'm personally not convinced by the namespace defaults in headers
> thing pwm.h does. So to namespace these is a massive patch
> adding the import to most drivers.
We are on the same page here! I even mentioned this disadvantage in
the comment below.
> So I'd rather deal with that later.
...
> > > -EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
> > > +EXPORT_SYMBOL_GPL(__iio_device_release_direct);
> >
> > Namespace?
> > Note, the good outcome of the namespace is that we can easily see who
> > (ab)uses these... OTOH, there are static inline functions in the
> > header, which provokes this to add MODULE_IMPORT_NS() into the header
> > as well. That said, perhaps also get rid of static inliners and have
> > them to be real functions?
> As David said. Unfortunately not :(
Yeah, that's a pity.
> Though static inlines using these is fine as any driver that
> doesn't import will still fail in the correct way. It will just
> be a bit 'weird' to fail like that. The missing namespace
> warnings are pretty obvious though so that should be fine.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
2025-04-01 6:28 ` Lorenzo Bianconi
@ 2025-04-06 13:15 ` Jonathan Cameron
0 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-04-06 13:15 UTC (permalink / raw)
To: Lorenzo Bianconi
Cc: David Lechner, linux-iio, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Matti Vaittinen, Yasin Lee,
Andy Shevchenko, Jonathan Cameron
On Tue, 1 Apr 2025 08:28:34 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> > On 3/31/25 7:12 AM, Jonathan Cameron wrote:
> > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > >
> > > By factoring out all the code that occurs with direct mode claimed
> > > to a helper function, that helper function can directly return simplifying
> > > code flow.
> > >
> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > Cc: Lorenzo Bianconi <lorenzo@kernel.org>
> > > ---
> > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++---------
> > > 1 file changed, 35 insertions(+), 30 deletions(-)
> > >
> > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > index c1b444520d2a..17a74f5adfc0 100644
> > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > > @@ -614,53 +614,58 @@ st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
> > > }
> > >
> > > static int
> > > -st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> > > - struct iio_chan_spec const *chan,
> > > - int val, int val2, long mask)
> > > +__st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
> > > + struct iio_chan_spec const *chan,
> > > + int val, int val2, long mask)
> > > {
> > > struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
> > > int err;
> > >
> > > - err = iio_device_claim_direct_mode(iio_dev);
> > > - if (err)
> > > - return err;
> > > -
> > > switch (mask) {
> > > case IIO_CHAN_INFO_SAMP_FREQ: {
> > > + struct st_lsm6dsx_hw *hw = sensor->hw;
> > > + struct st_lsm6dsx_sensor *ref_sensor;
> > > + u8 odr_val;
> > > u16 data;
> > > + int odr;
> > >
> > I would be tempted to rename `err` to `ret` so we don't have to introduce
> > a new `odr` variable.
>
> I guess keeping odr variable makes the code more readable.
Hmm. I'm not sure either way. Will keep this as a potential follow up.
Jonathan
>
> Regards,
> Lorenzo
>
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest)
2025-04-01 19:13 ` [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) David Lechner
@ 2025-04-06 13:20 ` Jonathan Cameron
0 siblings, 0 replies; 58+ messages in thread
From: Jonathan Cameron @ 2025-04-06 13:20 UTC (permalink / raw)
To: David Lechner
Cc: linux-iio, Nuno Sá, Cosmin Tanislav, Roan van Dijk,
Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
On Tue, 1 Apr 2025 14:13:24 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 3/31/25 7:12 AM, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Firstly, sorry for the huge patch set!
> >
>
>
> Reviewed-by: David Lechner <dlechner@baylibre.com>
I've applied all these to the testing branch of iio.git.
Only changes were the typos and punctuation that Andy pointed out in
the final patch. They didn't feel like the justified a v2.
Note that I'm not planning to push this out as non rebasing
until next weekend, so there is still time for additional review.
The namespace question can wait for another time.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 58+ messages in thread
* Re: [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest)
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
` (37 preceding siblings ...)
2025-04-01 19:13 ` [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) David Lechner
@ 2025-04-12 18:54 ` Marcelo Schmitt
38 siblings, 0 replies; 58+ messages in thread
From: Marcelo Schmitt @ 2025-04-12 18:54 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá, Cosmin Tanislav,
Roan van Dijk, Jyoti Bhayana, Nishant Malpani, Eugene Zaikonnikov,
Jean-Baptiste Maneyrol, Shen Jianping, Lorenzo Bianconi,
Matti Vaittinen, Yasin Lee, Andy Shevchenko, Jonathan Cameron
Hi Jonathan,
For the whole series
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Really nice series IMHO.
Thanks,
Marcelo
On 03/31, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Firstly, sorry for the huge patch set!
>
> I've run out of signficiant groups to break the remaining patches up into.
> Rather than have lots of small series of 5-10 patches, lets just have one
> mega one. Feel free to review a subset! I'll nibble away at this as reviews
> come in and post a v2 later in the cycle with whatever remains unreviewed
> if that is necessary.
>
> 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!
>
> This is effectively part 5 of what will probably be around 5 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 all the remaining drivers.
> The final patch removes the old infrastructure.
^ permalink raw reply [flat|nested] 58+ messages in thread
end of thread, other threads:[~2025-04-12 18:53 UTC | newest]
Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 12:12 [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) Jonathan Cameron
2025-03-31 12:12 ` [PATCH 01/37] iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:12 ` [PATCH 02/37] iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to simplify error paths Jonathan Cameron
2025-03-31 12:12 ` [PATCH 03/37] iio: chemical: ccs811: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:12 ` [PATCH 04/37] iio: chemical: atlas-sensor: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 05/37] iio: chemical: scd4x: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 06/37] iio: common: scmi: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 07/37] iio: common: st_sensors: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 08/37] iio: gyro: adxrs290: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 09/37] iio: health: max30102: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 10/37] iio: humidity: hdc100x: Use guard(mutex) to simplify code flow Jonathan Cameron
2025-03-31 12:12 ` [PATCH 11/37] iio: humidity: hdc100x: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:12 ` [PATCH 12/37] iio: humidity: hdc2010: " Jonathan Cameron
2025-04-01 6:59 ` Eugene Zaikonnikov
2025-03-31 12:12 ` [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions Jonathan Cameron
2025-04-01 6:33 ` Lorenzo Bianconi
2025-03-31 12:12 ` [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-04-01 6:34 ` Lorenzo Bianconi
2025-03-31 12:12 ` [PATCH 15/37] iio: imu: inv_icm42600: " Jonathan Cameron
2025-03-31 14:27 ` Jean-Baptiste Maneyrol
2025-03-31 12:12 ` [PATCH 16/37] iio: imu: inv_mpu6050: " Jonathan Cameron
2025-03-31 13:57 ` Jean-Baptiste Maneyrol
2025-03-31 12:12 ` [PATCH 17/37] iio: imu: smi240: " Jonathan Cameron
2025-03-31 12:12 ` [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns Jonathan Cameron
2025-03-31 14:31 ` David Lechner
2025-04-01 6:28 ` Lorenzo Bianconi
2025-04-06 13:15 ` Jonathan Cameron
2025-04-01 6:27 ` Lorenzo Bianconi
2025-03-31 12:12 ` [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct() Jonathan Cameron
2025-04-01 6:31 ` Lorenzo Bianconi
2025-03-31 12:13 ` [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-04-01 6:29 ` Lorenzo Bianconi
2025-03-31 12:13 ` [PATCH 21/37] iio: magnetometer: mag3110: Factor out core of read/write_raw() and use guard() to simplify code flow Jonathan Cameron
2025-03-31 12:13 ` [PATCH 22/37] iio: magnetometer: mag3110: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:13 ` [PATCH 23/37] iio: magnetometer: rm3100: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 24/37] iio: pressure: dlhl60d: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 25/37] iio: pressure: icp10100: " Jonathan Cameron
2025-03-31 14:03 ` Jean-Baptiste Maneyrol
2025-03-31 12:13 ` [PATCH 26/37] iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to simplify code flow Jonathan Cameron
2025-03-31 12:13 ` [PATCH 27/37] iio: pressure: mpl3115: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:13 ` [PATCH 28/37] iio: pressure: ms5611: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 29/37] iio: pressure: rohm-bm1390: " Jonathan Cameron
2025-04-01 13:14 ` Matti Vaittinen
2025-03-31 12:13 ` [PATCH 30/37] iio: pressure: zpa2326: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 31/37] iio: proximity: hx9023s: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 32/37] iio: proximity: pulsed-light: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 33/37] iio: proximity: sx9500: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 34/37] iio: temp: maxim_thermocouple: " Jonathan Cameron
2025-03-31 12:13 ` [PATCH 35/37] iio: temp: maxim_thermocouple: Drop unused mutex.h include Jonathan Cameron
2025-03-31 12:13 ` [PATCH 36/37] staging: iio: ad5933: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-31 12:13 ` [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API Jonathan Cameron
2025-03-31 13:41 ` Andy Shevchenko
2025-03-31 14:07 ` David Lechner
2025-04-05 16:34 ` Jonathan Cameron
2025-04-05 16:46 ` Andy Shevchenko
2025-04-01 19:13 ` [PATCH 00/37] IIO: Sparse friendly claim of direct mode (the rest) David Lechner
2025-04-06 13:20 ` Jonathan Cameron
2025-04-12 18:54 ` Marcelo Schmitt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox