IIO: Sparse friendly claim of direct mode (the rest)
Subsystems (14)
Jonathan Cameron
maintainercover IIO: Sparse friendly claim of direct mode (the rest)
From: Jonathan Cameron <[email protected]>
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/[email protected]/
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(-)
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 1/37 iio: addac: ad74115: Switch to sparse friendly iio_device_claim/release_direct()
From: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/addac/ad74115.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/addac/ad74115.c +3 -4
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 2/37 iio: chemical: ccs811: Factor out handling of read of IIO_INFO_RAW to simplify error paths.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Factor out the implementation of this part of read_raw() and use guard() to allow direct returns, simplifying both error and non error paths.
--- drivers/iio/chemical/ccs811.c | 72 ++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 35 deletions(-)
drivers/iio/chemical/ccs811.c +37 -35
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 3/37 iio: chemical: ccs811: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/chemical/ccs811.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/chemical/ccs811.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 4/37 iio: chemical: atlas-sensor: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/chemical/atlas-sensor.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/chemical/atlas-sensor.c +3 -4
@@ -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 ;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 5/37 iio: chemical: scd4x: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/chemical/scd4x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/chemical/scd4x.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 6/37 iio: common: scmi: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/common/scmi_sensors/scmi_iio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/common/scmi_sensors/scmi_iio.c +3 -4
@@ -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 ;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 7/37 iio: common: st_sensors: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/common/st_sensors/st_sensors_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/common/st_sensors/st_sensors_core.c +3 -4
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 8/37 iio: gyro: adxrs290: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/gyro/adxrs290.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/gyro/adxrs290.c +6 -8
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 9/37 iio: health: max30102: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/health/max30102.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/health/max30102.c +2 -2
@@ -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);
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 10/37 iio: humidity: hdc100x: Use guard(mutex) to simplify code flow
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
By using autoreleasing on the lock a number of paths can use direct returns allow earlier exit from functions.
--- drivers/iio/humidity/hdc100x.c | 69 +++++++++++++--------------------- 1 file changed, 27 insertions(+), 42 deletions(-)
drivers/iio/humidity/hdc100x.c +27 -42
@@ -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 = {
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 11/37 iio: humidity: hdc100x: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/humidity/hdc100x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/humidity/hdc100x.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 12/37 iio: humidity: hdc2010: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/humidity/hdc2010.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/humidity/hdc2010.c +6 -8
@@ -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 */
Signature · 1 line
2.48.1
Re: [PATCH 12/37] iio: humidity: hdc2010: Switch to sparse friendly iio_device_claim/release_direct()
Hi Jonathan,
Thanks for the patch. It looks good to me.
Quoted 50 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Eugene Zaikonnikov <[email protected]>--- drivers/iio/humidity/hdc2010.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/iio/humidity/hdc2010.c +6
-8@@ -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 */
Signature · 6 lines
Regards, Eugene Zaikonnikov Norphonic AS Tel: +47 98 23 97 73
Jonathan Cameron
maintainerPATCH 13/37 iio: humidity: hts211: Factor out everything under direct mode claim into helper functions.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/humidity/hts221_core.c | 89 +++++++++++++++--------------- 1 file changed, 45 insertions(+), 44 deletions(-)
drivers/iio/humidity/hts221_core.c +45 -44
@@ -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);
Signature · 1 line
2.48.1
Re: [PATCH 13/37] iio: humidity: hts211: Factor out everything under direct mode claim into helper functions.
Quoted 8 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Pulling out the functionality of
read_raw()andwrite_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 <[email protected]>
Quoted 151 lines
--- drivers/iio/humidity/hts221_core.c | 89 +++++++++++++++--------------- 1 file changed, 45 insertions(+), 44 deletions(-)drivers/iio/humidity/hts221_core.c +45
-44@@ -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);Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 14/37 iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/humidity/hts221_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/humidity/hts221_core.c +6 -8
@@ -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; }
Signature · 1 line
2.48.1
Re: [PATCH 14/37] iio: humidity: hts211: Switch to sparse friendly iio_device_claim/release_direct()
Quoted 7 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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 <[email protected]>
Quoted 45 lines
--- drivers/iio/humidity/hts221_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/iio/humidity/hts221_core.c +6
-8@@ -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; }Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 15/37 iio: imu: inv_icm42600: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- .../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(-)
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +9 -12
@@ -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 ;
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +9 -12
@@ -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 ;
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Re: [PATCH 15/37] iio: imu: inv_icm42600: Switch to sparse friendly iio_device_claim/release_direct()
Hello Jonathan,
looks good for me, thanks for the patch.
Thanks,
JB
________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Monday, March 31, 2025 14:12
To: [email protected] <[email protected]>
Cc: David Lechner <[email protected]>; Nuno Sá <[email protected]>; Cosmin Tanislav <[email protected]>; Roan van Dijk <[email protected]>; Jyoti Bhayana <[email protected]>; Nishant Malpani <[email protected]>; Eugene Zaikonnikov <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Shen Jianping <[email protected]>; Lorenzo Bianconi <[email protected]>; Matti Vaittinen <[email protected]>; Yasin Lee <[email protected]>; Andy Shevchenko <[email protected]>; Jonathan Cameron <[email protected]> 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 <[email protected]>
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.
--- .../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(-)
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +9 -12
@@ -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 ;
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +9 -12
@@ -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 ;
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 16/37 iio: imu: inv_mpu6050: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +6 -8
@@ -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; }
Signature · 1 line
2.48.1
Re: [PATCH 16/37] iio: imu: inv_mpu6050: Switch to sparse friendly iio_device_claim/release_direct()
Hello Jonathan,
looks good, thanks for the patch.
Thanks,
JB
________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Monday, March 31, 2025 14:12
To: [email protected] <[email protected]>
Cc: David Lechner <[email protected]>; Nuno Sá <[email protected]>; Cosmin Tanislav <[email protected]>; Roan van Dijk <[email protected]>; Jyoti Bhayana <[email protected]>; Nishant Malpani <[email protected]>; Eugene Zaikonnikov <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Shen Jianping <[email protected]>; Lorenzo Bianconi <[email protected]>; Matti Vaittinen <[email protected]>; Yasin Lee <[email protected]>; Andy Shevchenko <[email protected]>; Jonathan Cameron <[email protected]> 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 <[email protected]>
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.
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +6 -8
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 17/37 iio: imu: smi240: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/imu/smi240.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/imu/smi240.c +3 -4
@@ -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 ;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 18/37 iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +35 -30
@@ -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
Signature · 1 line
2.48.1
David Lechner
reviewerRe: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
Quoted 32 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Lorenzo Bianconi <[email protected]>--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +3
-5@@ -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)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor, · line 631
Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +4
-2-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.
Lorenzo Bianconi
maintainerRe: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
Quoted 31 lines · Jonathan Cameron
Quoted 30 lines
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Lorenzo Bianconi <[email protected]>--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +3
-3@@ -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;
Quoted 14 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor, · line 631
Quoted 12 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +4
-4- 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
errtoretso we don't have to introduce a newodrvariable.
I guess keeping odr variable makes the code more readable.
Regards,
Lorenzo
Jonathan Cameron
maintainerRe: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
Quoted 46 lines · On Tue, 1 Apr 2025 08:28:34 +0200 Lorenzo Bianconi <[email protected]> wrote:
Quoted 31 lines · Jonathan Cameron
Quoted 30 lines
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Lorenzo Bianconi <[email protected]>--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +3
-3@@ -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;Quoted 14 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor, · line 631
Quoted 12 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +4
-4- 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
errtoretso we don't have to introduce a newodrvariable.
Quoted 1 line
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
Quoted 4 lines
Regards,
Lorenzo
Re: [PATCH 18/37] iio: imu: st_lsm6dsx: Factor out parts of st_lsm6dsx_shub_write_raw() to allow direct returns
In reply to Jonathan CameronQuoted 8 lines
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Lorenzo Bianconi <[email protected]>
Quoted 100 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 65 +++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +35
-30@@ -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_tSignature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 19/37 iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
This driver caused a false positive with __cond_lock() style solution but is fine with the simple boolean return approach now used.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +7 -9
@@ -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; }
Signature · 1 line
2.48.1
Re: [PATCH 19/37] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct()
Quoted 7 lines
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Lorenzo Bianconi <[email protected]>
Quoted 51 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +7
-9@@ -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; }Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 20/37 iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +6 -8
@@ -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; }
Signature · 1 line
2.48.1
Re: [PATCH 20/37] iio: imu: st_lsm6dsx: Switch to sparse friendly iio_device_claim/release_direct()
Quoted 8 lines
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Cc Lorenzo Bianconi <[email protected]>
Quoted 44 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +6
-8@@ -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; }Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 21/37 iio: magnetometer: mag3110: Factor out core of read/write_raw() and use guard() to simplify code flow.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
The combination of guard(mutex) and factoring out sections of code that occur with the device held in direct mode simplifies code flow.
--- drivers/iio/magnetometer/mag3110.c | 153 ++++++++++++++--------------- 1 file changed, 75 insertions(+), 78 deletions(-)
drivers/iio/magnetometer/mag3110.c +75 -78
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 22/37 iio: magnetometer: mag3110: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/magnetometer/mag3110.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/magnetometer/mag3110.c +6 -8
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 23/37 iio: magnetometer: rm3100: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/magnetometer/rm3100-core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/magnetometer/rm3100-core.c +3 -4
@@ -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 :
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 24/37 iio: pressure: dlhl60d: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/dlhl60d.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/pressure/dlhl60d.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 25/37 iio: pressure: icp10100: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/icp10100.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/iio/pressure/icp10100.c +6 -9
@@ -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 ;
Signature · 1 line
2.48.1
Re: [PATCH 25/37] iio: pressure: icp10100: Switch to sparse friendly iio_device_claim/release_direct()
Hello Jonathan,
looks good, thanks for the patch.
Thanks,
JB
________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Monday, March 31, 2025 14:13
To: [email protected] <[email protected]>
Cc: David Lechner <[email protected]>; Nuno Sá <[email protected]>; Cosmin Tanislav <[email protected]>; Roan van Dijk <[email protected]>; Jyoti Bhayana <[email protected]>; Nishant Malpani <[email protected]>; Eugene Zaikonnikov <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Shen Jianping <[email protected]>; Lorenzo Bianconi <[email protected]>; Matti Vaittinen <[email protected]>; Yasin Lee <[email protected]>; Andy Shevchenko <[email protected]>; Jonathan Cameron <[email protected]> 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 <[email protected]>
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.
--- drivers/iio/pressure/icp10100.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/iio/pressure/icp10100.c +6 -9
@@ -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 ;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 26/37 iio: pressure: mpl3115: factor out core of IIO_INFO_RAW read to simplify code flow
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/mpl3115.c | 90 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 43 deletions(-)
drivers/iio/pressure/mpl3115.c +47 -43
@@ -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;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 27/37 iio: pressure: mpl3115: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/mpl3115.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/pressure/mpl3115.c +3 -4
@@ -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 :
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 28/37 iio: pressure: ms5611: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/ms5611_core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/pressure/ms5611_core.c +3 -5
@@ -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 ; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 29/37 iio: pressure: rohm-bm1390: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/rohm-bm1390.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/pressure/rohm-bm1390.c +3 -4
@@ -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;
Signature · 1 line
2.48.1
Re: [PATCH 29/37] iio: pressure: rohm-bm1390: Switch to sparse friendly iio_device_claim/release_direct()
Quoted 7 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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 <[email protected]>
Yours,
-- Matti
Jonathan Cameron
maintainerPATCH 30/37 iio: pressure: zpa2326: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/pressure/zpa2326.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/iio/pressure/zpa2326.c +6 -9
@@ -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 ; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 31/37 iio: proximity: hx9023s: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/proximity/hx9023s.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/proximity/hx9023s.c +3 -4
@@ -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);
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 32/37 iio: proximity: pulsed-light: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +2 -2
@@ -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 :
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 33/37 iio: proximity: sx9500: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/proximity/sx9500.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/proximity/sx9500.c +3 -4
@@ -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);
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 34/37 iio: temp: maxim_thermocouple: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/temperature/maxim_thermocouple.c | 29 ++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-)
drivers/iio/temperature/maxim_thermocouple.c +12 -17
@@ -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 = {
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 35/37 iio: temp: maxim_thermocouple: Drop unused mutex.h include.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
There are no mutex related calls in this driver.
--- drivers/iio/temperature/maxim_thermocouple.c | 1 - 1 file changed, 1 deletion(-)
drivers/iio/temperature/maxim_thermocouple.c +0 -1
@@ -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>
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 36/37 staging: iio: ad5933: Switch to sparse friendly iio_device_claim/release_direct()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- .../staging/iio/impedance-analyzer/ad5933.c | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-)
drivers/staging/iio/impedance-analyzer/ad5933.c +21 -17
@@ -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; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH 37/37 iio: Adjust internals of handling of direct mode claiming to suit new API.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/industrialio-core.c | 28 ++++++++++++++++------------ include/linux/iio/iio.h | 10 ++++------ 2 files changed, 20 insertions(+), 18 deletions(-)
drivers/iio/industrialio-core.c +16 -12
@@ -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
include/linux/iio/iio.h +4 -6
@@ -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); }
Signature · 1 line
2.48.1
Re: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
Quoted 6 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Now there are no remaining callers of
iio_device_claim_direct_mode()andiio_device_release_direct_mode()rename those functions to ensure they are no used in new drivers. Also make them now return booleans
not used
Quoted 1 line
in line with the sparse friendly static inline wrappers.
...
Quoted 6 lines
/**
- *iio_device_claim_direct_mode- Keep device in direct mode
+ *__iio_device_claim_direct- Keep device in direct mode
* @indio_dev: theiio_devassociated with the device *
* If the device is in direct mode it is guaranteed to stay
Quoted 8 lines
- * that way until
iio_device_release_direct_mode()is called.
+ * that way until__iio_device_release_direct()is called. *
- * Use withiio_device_release_direct_mode()
+ * Use with__iio_device_release_direct().
*
- * Returns: 0 on success,-EBUSYon failure.
+ * Drivers should only calliio_device_claim_direct()
Missed period.
Quoted 2 lines
+ * Returns: true on success, false on failure.
*/
...
drivers/iio/industrialio-core.c int iio_device_claim_direct_mode(struct iio_dev *indio_dev) · line 2184
Quoted 2 lines
drivers/iio/industrialio-core.c +1
-1-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?
...
Quoted 10 lines
/**
- *iio_device_release_direct_mode- releases claim on direct mode
+ *__iio_device_release_direct- releases claim on direct mode
* @indio_dev: theiio_devassociated with the device *
* Release the claim. Device is no longer guaranteed to stay
* in direct mode.
*
- * Use withiio_device_claim_direct_mode()
+ * Drivers should only calliio_device_release_direct()
Missed period.
Quoted 2 lines
+ * Use with
__iio_device_claim_direct()
*/
...
drivers/iio/industrialio-core.c int iio_device_claim_direct_mode(struct iio_dev *indio_dev) · line 2201
Quoted 2 lines
drivers/iio/industrialio-core.c +1
-1-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?
Signature · 2 lines
With Best Regards, Andy Shevchenko
David Lechner
reviewerRe: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
Quoted 3 lines · Andy Shevchenko
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/[email protected]/
Jonathan Cameron
maintainerRe: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
In reply to Andy ShevchenkoQuoted 34 lines · On Mon, 31 Mar 2025 16:41:42 +0300 Andy Shevchenko <[email protected]>…
Quoted 6 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Now there are no remaining callers of
iio_device_claim_direct_mode()andiio_device_release_direct_mode()rename those functions to ensure they are no used in new drivers. Also make them now return booleansnot used
Quoted 1 line
in line with the sparse friendly static inline wrappers.
...
Quoted 6 lines
/**
- *iio_device_claim_direct_mode- Keep device in direct mode
+ *__iio_device_claim_direct- Keep device in direct mode
* @indio_dev: theiio_devassociated with the device *
* If the device is in direct mode it is guaranteed to stayQuoted 8 lines
- * that way until
iio_device_release_direct_mode()is called.
+ * that way until__iio_device_release_direct()is called. *
- * Use withiio_device_release_direct_mode()
+ * Use with__iio_device_release_direct().
*
- * Returns: 0 on success,-EBUSYon failure.
+ * Drivers should only calliio_device_claim_direct()Missed period.
Quoted 2 lines
+ * Returns: true on success, false on failure.
*/
Quoted 6 lines
...
drivers/iio/industrialio-core.c int iio_device_claim_direct_mode(struct iio_dev *indio_dev) · line 2184
Quoted 2 lines
drivers/iio/industrialio-core.c +1
-1-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.
Quoted 21 lines
...
Quoted 10 lines
/**
- *iio_device_release_direct_mode- releases claim on direct mode
+ *__iio_device_release_direct- releases claim on direct mode
* @indio_dev: theiio_devassociated with the device *
* Release the claim. Device is no longer guaranteed to stay
* in direct mode.
*
- * Use withiio_device_claim_direct_mode()
+ * Drivers should only calliio_device_release_direct()Missed period.
Quoted 2 lines
+ * Use with
__iio_device_claim_direct()
*/...
Quoted 9 lines
drivers/iio/industrialio-core.c int iio_device_claim_direct_mode(struct iio_dev *indio_dev) · line 2201
Quoted 2 lines
drivers/iio/industrialio-core.c +1
-1-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 addMODULE_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
Quoted 1 line
Re: [PATCH 37/37] iio: Adjust internals of handling of direct mode claiming to suit new API.
Quoted 3 lines · Jonathan Cameron
Quoted 1 line · On Mon, 31 Mar 2025 16:41:42 +0300 Andy Shevchenko <[email protected]>…
On Mon, Mar 31, 2025 at 3:17 PM Jonathan Cameron <[email protected]> wrote:
...
Quoted 8 lines
Quoted 4 lines
drivers/iio/industrialio-core.c int iio_device_claim_direct_mode(struct iio_dev *indio_dev) · line 2184
Quoted 2 lines
drivers/iio/industrialio-core.c +1
-1-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.hdoes. 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.
Quoted 1 line
So I'd rather deal with that later.
...
Quoted 11 lines
Quoted 9 lines
drivers/iio/industrialio-core.c int iio_device_claim_direct_mode(struct iio_dev *indio_dev) · line 2201
Quoted 2 lines
drivers/iio/industrialio-core.c +1
-1-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 addMODULE_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.
Quoted 4 lines
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Firstly, sorry for the huge patch set!
Jonathan Cameron
maintainerQuoted 8 lines · On Tue, 1 Apr 2025 14:13:24 -0500 David Lechner <[email protected]> wrote:
Quoted 4 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Firstly, sorry for the huge patch set!
Reviewed-by David Lechner <[email protected]>
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
Hi Jonathan,
For the whole series
Really nice series IMHO.
Thanks,
Marcelo
Quoted 25 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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/[email protected]/This series focuses on all the remaining drivers.
The final patch removes the old infrastructure.