IIO: ADCs: Sparse friendly claim of direct mode
Subsystems (5)
Jonathan Cameron
maintainerv2 cover IIO: ADCs: Sparse friendly claim of direct mode
From: Jonathan Cameron <[email protected]>
Resend of remaining unreviewed updates in drivers/iio/adc/*
I will eventually just apply these, but I'd much rather someone else took a quick look to check I haven't done anything stupid!
Note that a number of the drivers touched in this series have no obvious active maintainer, so it would be much appreciated if anyone has time to take a look! It is a large series so feel free to review any you have time to look at rather than feeling you need to look at the whole thing!
This is effectively part 3 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 the ADC drivers.
Jonathan Cameron (8):
iio: adc: vf610: Move claim of direct mode to caller of
vf610_read_sample and use guard(mutex)
iio: adc: vf610: Switch to sparse friendly
iio_device_claim/release_direct()
iio: adc: ti-ads1100: Use guard(mutex) to allow direct returns
iio: adc: ti-ads1100: Switch to sparse friendly
iio_device_claim/release_direct()
iio: adc: ti-ads1015: Use guard(mutex) and factor out code for
INFO_RAW
iio: adc: ti-ads1015: Switch to sparse friendly
iio_device_claim/release_direct()
iio: adc: mxs-lradc: Switch to sparse friendly
iio_device_claim/release_direct()
iio: adc: rcar: Switch to sparse friendly
iio_device_claim/release_direct()
drivers/iio/adc/mxs-lradc-adc.c | 14 ++- drivers/iio/adc/rcar-gyroadc.c | 9 +- drivers/iio/adc/ti-ads1015.c | 168 +++++++++++++------------------- drivers/iio/adc/ti-ads1100.c | 44 +++------ drivers/iio/adc/vf610_adc.c | 36 +++---- 5 files changed, 105 insertions(+), 166 deletions(-)
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH v2 1/8 iio: adc: vf610: Move claim of direct mode to caller of vf610_read_sample and use guard(mutex)
From: Jonathan Cameron <[email protected]>
These two changes allow direct returns in all paths, improving code readablity.
--- drivers/iio/adc/vf610_adc.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)
drivers/iio/adc/vf610_adc.c +14 -23
@@ -11,6 +11,7 @@#include <linux/property.h> #include <linux/platform_device.h> #include <linux/interrupt.h> +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/kernel.h> #include <linux/slab.h>
@@ -630,36 +631,29 @@ static const struct attribute_group vf610_attribute_group = { .attrs = vf610_attributes, }; -static int vf610_read_sample (struct iio_dev *indio_dev, +static int vf610_read_sample (struct vf610_adc *info,struct iio_chan_spec const *chan,int *val) { -struct vf610_adc *info =iio_priv (indio_dev);unsigned int hc_cfg;int ret; - ret =iio_device_claim_direct_mode (indio_dev); -if (ret) -return ret; - -mutex_lock (&info->lock); +guard (mutex)(&info->lock);reinit_completion (&info->completion); hc_cfg =VF610_ADC_ADCHC (chan->channel); hc_cfg |=VF610_ADC_AIEN ;writel (hc_cfg, info->regs +VF610_REG_ADC_HC0 ); ret =wait_for_completion_interruptible_timeout (&info->completion,VF610_ADC_TIMEOUT ); -if (ret ==0 ) { - ret = -ETIMEDOUT ; - goto out_unlock; - } +if (ret ==0 ) +return -ETIMEDOUT ;if (ret <0 ) - goto out_unlock; +return ret;switch (chan->type) {case IIO_VOLTAGE : *val = info->value; -break ; +return 0 ;case IIO_TEMP :/* * Calculate in degree Celsius times 1000
@@ -669,17 +663,10 @@ static int vf610_read_sample(struct iio_dev *indio_dev, *val =25000 - ((int )info->value -VF610_VTEMP25_3V3 ) *1000000 /VF610_TEMP_SLOPE_COEFF ; -break ; +return 0 ;default : - ret = -EINVAL ; -break ; +return -EINVAL ; } - -out_unlock: -mutex_unlock (&info->lock); -iio_device_release_direct_mode (indio_dev); - -return ret; } static int vf610_read_raw(struct iio_dev *indio_dev,
@@ -694,7 +681,11 @@ static int vf610_read_raw(struct iio_dev *indio_dev,switch (mask) {case IIO_CHAN_INFO_RAW :case IIO_CHAN_INFO_PROCESSED : - ret =vf610_read_sample (indio_dev, chan, val); + ret =iio_device_claim_direct_mode (indio_dev); +if (ret) +return ret; + ret =vf610_read_sample (info, chan, val); +iio_device_release_direct_mode (indio_dev);if (ret <0 )return ret;
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH v2 2/8 iio: adc: vf610: 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/adc/vf610_adc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/adc/vf610_adc.c +3 -4
@@ -681,11 +681,10 @@ static int vf610_read_raw(struct iio_dev *indio_dev,switch (mask) {case IIO_CHAN_INFO_RAW :case IIO_CHAN_INFO_PROCESSED : - ret =iio_device_claim_direct_mode (indio_dev); -if (ret) -return ret; +if (!iio_device_claim_direct (indio_dev)) +return -EBUSY ; ret =vf610_read_sample (info, chan, val); -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 v2 3/8 iio: adc: ti-ads1100: Use guard(mutex) to allow direct returns
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Use of automated lock release simplifies the code.
--- drivers/iio/adc/ti-ads1100.c | 39 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 25 deletions(-)
drivers/iio/adc/ti-ads1100.c +14 -25
@@ -10,6 +10,7 @@#include <linux/bitfield.h> #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/init.h>
@@ -219,36 +220,31 @@ static int ads1100_read_raw(struct iio_dev *indio_dev,int ret;struct ads1100_data *data =iio_priv (indio_dev); -mutex_lock (&data->lock); +guard (mutex)(&data->lock);switch (mask) {case IIO_CHAN_INFO_RAW : ret =iio_device_claim_direct_mode (indio_dev);if (ret) -break ; +return ret; ret =ads1100_get_adc_result (data, chan->address, val); -if (ret >=0 ) - ret =IIO_VAL_INT ;iio_device_release_direct_mode (indio_dev); -break ; +if (ret <0 ) +return ret; + +return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE :/* full-scale is the supply voltage in millivolts */ *val =ads1100_get_vdd_millivolts (data); *val2 =15 +FIELD_GET (ADS1100_PGA_MASK , data->config); - ret =IIO_VAL_FRACTIONAL_LOG2 ; -break ; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_SAMP_FREQ : *val = ads1100_data_rate[FIELD_GET (ADS1100_DR_MASK , data->config)]; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ;default : - ret = -EINVAL ; -break ; +return -EINVAL ; } -mutex_unlock (&data->lock); - -return ret; } static int ads1100_write_raw(struct iio_dev *indio_dev,
@@ -256,23 +252,16 @@ static int ads1100_write_raw(struct iio_dev *indio_dev, int val2, long mask) {struct ads1100_data *data =iio_priv (indio_dev); -int ret; -mutex_lock (&data->lock); +guard (mutex)(&data->lock);switch (mask) {case IIO_CHAN_INFO_SCALE : - ret =ads1100_set_scale (data, val, val2); -break ; +return ads1100_set_scale (data, val, val2);case IIO_CHAN_INFO_SAMP_FREQ : - ret =ads1100_set_data_rate (data, chan->address, val); -break ; +return ads1100_set_data_rate (data, chan->address, val);default : - ret = -EINVAL ; -break ; +return -EINVAL ; } -mutex_unlock (&data->lock); - -return ret; }static const struct iio_info ads1100_info = {
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH v2 4/8 iio: adc: ti-ads1100: 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/adc/ti-ads1100.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/adc/ti-ads1100.c +3 -4
@@ -223,12 +223,11 @@ static int ads1100_read_raw(struct iio_dev *indio_dev,guard (mutex)(&data->lock);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 =ads1100_get_adc_result (data, chan->address, val); -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 v2 5/8 iio: adc: ti-ads1015: Use guard(mutex) and factor out code for INFO_RAW
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
By use of automatic lock release and introducing a new utility function to handle the core activity of reading the ADC channel, many more complex code flows can be replaced by direct returns.
--- drivers/iio/adc/ti-ads1015.c | 162 ++++++++++++++--------------------- 1 file changed, 64 insertions(+), 98 deletions(-)
drivers/iio/adc/ti-ads1015.c +64 -98
@@ -12,6 +12,7 @@*/ #include <linux/module.h> +#include <linux/cleanup.h> #include <linux/init.h> #include <linux/irq.h> #include <linux/i2c.h>
@@ -533,6 +534,31 @@ static int ads1015_read_avail(struct iio_dev *indio_dev, } } +static int __ads1015_read_info_raw (struct ads1015_data *data, +struct iio_chan_spec const *chan,int *val) +{ +int ret; + +if (ads1015_event_channel_enabled (data) && + data->event_channel != chan->address) +return -EBUSY ; + + ret =ads1015_set_power_state (data, true); +if (ret <0 ) +return ret; + + ret =ads1015_get_adc_result (data, chan->address, val); +if (ret <0 ) { +ads1015_set_power_state (data, false); +return ret; + } + + *val =sign_extend32 (*val >> chan->scan_type.shift, + chan->scan_type.realbits -1 ); + +return ads1015_set_power_state (data, false); +} +static int ads1015_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)
@@ -540,58 +566,30 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,int ret, idx;struct ads1015_data *data =iio_priv (indio_dev); -mutex_lock (&data->lock); +guard (mutex)(&data->lock);switch (mask) {case IIO_CHAN_INFO_RAW : ret =iio_device_claim_direct_mode (indio_dev);if (ret) -break ; - -if (ads1015_event_channel_enabled (data) && - data->event_channel != chan->address) { - ret = -EBUSY ; - goto release_direct; - } - - ret =ads1015_set_power_state (data, true); -if (ret <0 ) - goto release_direct; - - ret =ads1015_get_adc_result (data, chan->address, val); -if (ret <0 ) { -ads1015_set_power_state (data, false); - goto release_direct; - } - - *val =sign_extend32 (*val >> chan->scan_type.shift, - chan->scan_type.realbits -1 ); - - ret =ads1015_set_power_state (data, false); -if (ret <0 ) - goto release_direct; - - ret =IIO_VAL_INT ; -release_direct: +return ret; + ret =__ads1015_read_info_raw (data, chan, val);iio_device_release_direct_mode (indio_dev); -break ; +if (ret) +return ret; + +return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : idx = data->channel_data[chan->address].pga; *val = ads1015_fullscale_range[idx]; *val2 = chan->scan_type.realbits -1 ; - ret =IIO_VAL_FRACTIONAL_LOG2 ; -break ; +return IIO_VAL_FRACTIONAL_LOG2 ;case IIO_CHAN_INFO_SAMP_FREQ : idx = data->channel_data[chan->address].data_rate; *val = data->chip->data_rate[idx]; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ;default : - ret = -EINVAL ; -break ; +return -EINVAL ; } -mutex_unlock (&data->lock); - -return ret; } static int ads1015_write_raw(struct iio_dev *indio_dev,
@@ -599,23 +597,16 @@ static int ads1015_write_raw(struct iio_dev *indio_dev, int val2, long mask) {struct ads1015_data *data =iio_priv (indio_dev); -int ret; -mutex_lock (&data->lock); +guard (mutex)(&data->lock);switch (mask) {case IIO_CHAN_INFO_SCALE : - ret =ads1015_set_scale (data, chan, val, val2); -break ; +return ads1015_set_scale (data, chan, val, val2);case IIO_CHAN_INFO_SAMP_FREQ : - ret =ads1015_set_data_rate (data, chan->address, val); -break ; +return ads1015_set_data_rate (data, chan->address, val);default : - ret = -EINVAL ; -break ; +return -EINVAL ; } -mutex_unlock (&data->lock); - -return ret; } static int ads1015_read_event(struct iio_dev *indio_dev,
@@ -624,20 +615,18 @@ static int ads1015_read_event(struct iio_dev *indio_dev, int *val2) {struct ads1015_data *data =iio_priv (indio_dev); -int ret;unsigned int comp_queue;int period;int dr; -mutex_lock (&data->lock); +guard (mutex)(&data->lock);switch (info) {case IIO_EV_INFO_VALUE : *val = (dir ==IIO_EV_DIR_RISING ) ? data->thresh_data[chan->address].high_thresh : data->thresh_data[chan->address].low_thresh; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ;case IIO_EV_INFO_PERIOD : dr = data->channel_data[chan->address].data_rate; comp_queue = data->thresh_data[chan->address].comp_queue;
@@ -646,16 +635,10 @@ static int ads1015_read_event(struct iio_dev *indio_dev, *val = period /USEC_PER_SEC ; *val2 = period %USEC_PER_SEC ; - ret =IIO_VAL_INT_PLUS_MICRO ; -break ; +return IIO_VAL_INT_PLUS_MICRO ;default : - ret = -EINVAL ; -break ; +return -EINVAL ; } - -mutex_unlock (&data->lock); - -return ret; } static int ads1015_write_event(struct iio_dev *indio_dev,
@@ -666,24 +649,22 @@ static int ads1015_write_event(struct iio_dev *indio_dev,struct ads1015_data *data =iio_priv (indio_dev);const int *data_rate = data->chip->data_rate;int realbits = chan->scan_type.realbits; -int ret =0 ;long long period;int i;int dr; -mutex_lock (&data->lock); +guard (mutex)(&data->lock);switch (info) {case IIO_EV_INFO_VALUE : -if (val >=1 << (realbits -1 ) || val <-1 << (realbits -1 )) { - ret = -EINVAL ; -break ; - } +if (val >=1 << (realbits -1 ) || val <-1 << (realbits -1 )) +return -EINVAL ; +if (dir ==IIO_EV_DIR_RISING ) data->thresh_data[chan->address].high_thresh = val;else data->thresh_data[chan->address].low_thresh = val; -break ; +return 0 ;case IIO_EV_INFO_PERIOD : dr = data->channel_data[chan->address].data_rate; period = val *USEC_PER_SEC + val2;
@@ -694,15 +675,10 @@ static int ads1015_write_event(struct iio_dev *indio_dev,break ; } data->thresh_data[chan->address].comp_queue = i; -break ; +return 0 ;default : - ret = -EINVAL ; -break ; +return -EINVAL ; } - -mutex_unlock (&data->lock); - -return ret; } static int ads1015_read_event_config(struct iio_dev *indio_dev,
@@ -710,25 +686,19 @@ static int ads1015_read_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir) {struct ads1015_data *data =iio_priv (indio_dev); -int ret =0 ; -mutex_lock (&data->lock); -if (data->event_channel == chan->address) { -switch (dir) { -case IIO_EV_DIR_RISING : - ret =1 ; -break ; -case IIO_EV_DIR_EITHER : - ret = (data->comp_mode ==ADS1015_CFG_COMP_MODE_WINDOW ); -break ; -default : - ret = -EINVAL ; -break ; - } - } -mutex_unlock (&data->lock); +guard (mutex)(&data->lock); +if (data->event_channel != chan->address) +return -EBUSY ; -return ret; +switch (dir) { +case IIO_EV_DIR_RISING : +return 1 ; +case IIO_EV_DIR_EITHER : +return (data->comp_mode ==ADS1015_CFG_COMP_MODE_WINDOW ); +default : +return -EINVAL ; + } } static int ads1015_enable_event_config(struct ads1015_data *data,
@@ -813,14 +783,12 @@ static int ads1015_write_event_config(struct iio_dev *indio_dev,int comp_mode = (dir ==IIO_EV_DIR_EITHER ) ?ADS1015_CFG_COMP_MODE_WINDOW :ADS1015_CFG_COMP_MODE_TRAD ; -mutex_lock (&data->lock); +guard (mutex)(&data->lock);/* Prevent from enabling both buffer and event at a time */ ret =iio_device_claim_direct_mode (indio_dev); -if (ret) { -mutex_unlock (&data->lock); +if (ret)return ret; - }if (state) ret =ads1015_enable_event_config (data, chan, comp_mode);
@@ -828,8 +796,6 @@ static int ads1015_write_event_config(struct iio_dev *indio_dev, ret =ads1015_disable_event_config (data, chan, comp_mode);iio_device_release_direct_mode (indio_dev); -mutex_unlock (&data->lock); -return ret; }
Signature · 1 line
2.48.1
David Lechner
reviewerRe: [PATCH v2 5/8] iio: adc: ti-ads1015: Use guard(mutex) and factor out code for INFO_RAW
Quoted 9 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
By use of automatic lock release and introducing a new utility function to handle the core activity of reading the ADC channel, many more complex code flows can be replaced by direct returns.
Signed-off-by Jonathan Cameron <[email protected]>Cc Marek Vasut <[email protected]>---
...
Quoted 15 lines
static int ads1015_read_event_config(struct
iio_dev*indio_dev,drivers/iio/adc/ti-ads1015.c +0
-9@@ -710,25 +686,19 @@ static int ads1015_read_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir) {struct ads1015_data *data =iio_priv (indio_dev); -int ret =0 ; -mutex_lock (&data->lock); -if (data->event_channel == chan->address) { -switch (dir) { -case IIO_EV_DIR_RISING : - ret =1 ; -break ; -case IIO_EV_DIR_EITHER : - ret = (data->comp_mode ==ADS1015_CFG_COMP_MODE_WINDOW );
drivers/iio/adc/ti-ads1015.c static int ads1015_read_event_config(struct iio_dev *indio_dev, · line 692
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +3
-7-break ; -default : - ret = -EINVAL ; -break ; - } - } -mutex_unlock (&data->lock); +guard (mutex)(&data->lock); +if (data->event_channel != chan->address) +return -EBUSY ;
The old code returned 0 in this case instead of -EBUSY, so this seems like an unrelated or unintentional change.
Quoted 12 lines
drivers/iio/adc/ti-ads1015.c +8
-1-return ret; +switch (dir) { +case IIO_EV_DIR_RISING : +return 1 ; +case IIO_EV_DIR_EITHER : +return (data->comp_mode ==ADS1015_CFG_COMP_MODE_WINDOW ); +default : +return -EINVAL ; + } }
Jonathan Cameron
maintainerRe: [PATCH v2 5/8] iio: adc: ti-ads1015: Use guard(mutex) and factor out code for INFO_RAW
Quoted 33 lines · On Mon, 10 Mar 2025 18:18:57 -0500 David Lechner <[email protected]> wrote:
Quoted 9 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
By use of automatic lock release and introducing a new utility function to handle the core activity of reading the ADC channel, many more complex code flows can be replaced by direct returns.
Signed-off-by Jonathan Cameron <[email protected]>Cc Marek Vasut <[email protected]>---
...
Quoted 20 lines
static int ads1015_read_event_config(struct
iio_dev*indio_dev,drivers/iio/adc/ti-ads1015.c +0
-14@@ -710,25 +686,19 @@ static int ads1015_read_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir) {struct ads1015_data *data =iio_priv (indio_dev); -int ret =0 ; -mutex_lock (&data->lock); -if (data->event_channel == chan->address) { -switch (dir) { -case IIO_EV_DIR_RISING : - ret =1 ; -break ; -case IIO_EV_DIR_EITHER : - ret = (data->comp_mode ==ADS1015_CFG_COMP_MODE_WINDOW ); -break ; -default : - ret = -EINVAL ; -break ; - }
Quoted 9 lines
drivers/iio/adc/ti-ads1015.c static int ads1015_read_event_config(struct iio_dev *indio_dev, · line 692
Quoted 5 lines
drivers/iio/adc/ti-ads1015.c +3
-2- } -mutex_unlock (&data->lock); +guard (mutex)(&data->lock); +if (data->event_channel != chan->address) +return -EBUSY ;The old code returned 0 in this case instead of
-EBUSY, so this seems like an unrelated or unintentional change.
Good catch, not intended so I've made it return 0.
Thanks,
Quoted 12 lines
Quoted 12 lines
drivers/iio/adc/ti-ads1015.c +8
-1-return ret; +switch (dir) { +case IIO_EV_DIR_RISING : +return 1 ; +case IIO_EV_DIR_EITHER : +return (data->comp_mode ==ADS1015_CFG_COMP_MODE_WINDOW ); +default : +return -EINVAL ; + } }
Jonathan Cameron
maintainerPATCH v2 6/8 iio: adc: ti-ads1015: 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/adc/ti-ads1015.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/ti-ads1015.c +6 -8
@@ -569,11 +569,10 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,guard (mutex)(&data->lock);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 =__ads1015_read_info_raw (data, chan, val); -iio_device_release_direct_mode (indio_dev); +iio_device_release_direct (indio_dev);if (ret)return ret;
@@ -786,16 +785,15 @@ static int ads1015_write_event_config(struct iio_dev *indio_dev,guard (mutex)(&data->lock);/* Prevent from enabling both buffer and event at a time */ - ret =iio_device_claim_direct_mode (indio_dev); -if (ret) -return ret; +if (!iio_device_claim_direct (indio_dev)) +return -EBUSY ;if (state) ret =ads1015_enable_event_config (data, chan, comp_mode);else ret =ads1015_disable_event_config (data, chan, comp_mode); -iio_device_release_direct_mode (indio_dev); +iio_device_release_direct (indio_dev);return ret; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH v2 7/8 iio: adc: mxs-lradc: 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/adc/mxs-lradc-adc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/mxs-lradc-adc.c +6 -8
@@ -141,9 +141,8 @@ static int mxs_lradc_adc_read_single(struct iio_dev *iio_dev, int chan,* the same time, yet the code becomes horribly complicated. Therefore I * applied KISS principle here. */ - ret =iio_device_claim_direct_mode (iio_dev); -if (ret) -return ret; +if (!iio_device_claim_direct (iio_dev)) +return -EBUSY ;reinit_completion (&adc->completion);
@@ -192,7 +191,7 @@ static int mxs_lradc_adc_read_single(struct iio_dev *iio_dev, int chan,writel (LRADC_CTRL1_LRADC_IRQ_EN (0 ), adc->base +LRADC_CTRL1 +STMP_OFFSET_REG_CLR ); -iio_device_release_direct_mode (iio_dev); +iio_device_release_direct (iio_dev);return ret; }
@@ -275,9 +274,8 @@ static int mxs_lradc_adc_write_raw(struct iio_dev *iio_dev, adc->scale_avail[chan->channel];int ret; - ret =iio_device_claim_direct_mode (iio_dev); -if (ret) -return ret; +if (!iio_device_claim_direct (iio_dev)) +return -EBUSY ;switch (m) {case IIO_CHAN_INFO_SCALE :
@@ -300,7 +298,7 @@ static int mxs_lradc_adc_write_raw(struct iio_dev *iio_dev,break ; } -iio_device_release_direct_mode (iio_dev); +iio_device_release_direct (iio_dev);return ret; }
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerPATCH v2 8/8 iio: adc: rcar: 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/adc/rcar-gyroadc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/iio/adc/rcar-gyroadc.c +4 -5
@@ -199,13 +199,12 @@ static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev,if (!consumer)return -EINVAL ; - ret =iio_device_claim_direct_mode (indio_dev); -if (ret) -return ret; +if (!iio_device_claim_direct (indio_dev)) +return -EBUSY ; ret =rcar_gyroadc_set_power (priv, true);if (ret <0 ) { -iio_device_release_direct_mode (indio_dev); +iio_device_release_direct (indio_dev);return ret; }
@@ -213,7 +212,7 @@ static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev, *val &=BIT (priv->sample_width) -1 ; ret =rcar_gyroadc_set_power (priv, false); -iio_device_release_direct_mode (indio_dev); +iio_device_release_direct (indio_dev);if (ret <0 )return ret;
Signature · 1 line
2.48.1
Quoted 7 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Resend of remaining unreviewed updates in
drivers/iio/adc/*I will eventually just apply these, but I'd much rather someone else took a quick look to check I haven't done anything stupid!
Only managed to find one little potential oversight in patch 5/8.
Jonathan Cameron
maintainerQuoted 9 lines · On Mon, 10 Mar 2025 18:21:30 -0500 David Lechner <[email protected]> wrote:
Quoted 7 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Resend of remaining unreviewed updates in
drivers/iio/adc/*I will eventually just apply these, but I'd much rather someone else took a quick look to check I haven't done anything stupid!
Only managed to find one little potential oversight in patch 5/8.
Fixed that up.
Quoted 3 lines
Reviewed-by David Lechner <[email protected]>
Applied to the testing branch of iio.git.
Thanks for reviewing!
Jonathan