iio: adc: ad4000: Add iio_device_claim_direct() to protect buffered captures
Subsystems (3)
PATCH 1/1 iio: adc: ad4000: Add iio_device_claim_direct() to protect buffered captures
Add iio_device_claim_direct() to protect buffered captures. In ad4000_write_raw_get_fmt, data reads are protected by the function call to avoid possible errors caused by concurrent access.
--- drivers/iio/adc/ad4000.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/adc/ad4000.c +3 -0
@@ -583,6 +583,9 @@ static int ad4000_write_raw_get_fmt(struct iio_dev *indio_dev, {switch (mask) {case IIO_CHAN_INFO_SCALE : +if (!iio_device_claim_direct (indio_dev)) +return -EBUSY ; +iio_device_release_direct (indio_dev);return IIO_VAL_INT_PLUS_NANO ;default :return IIO_VAL_INT_PLUS_MICRO ;
Signature · 1 line
2.34.1
Hi, Fernando, Octávio, Lucas,
I think you forgot to run get_maintainer.pl to get all the expected recipients for this patch. Also, even though the code seems to be syntactically correct, the proposed changes are not suitable for the IIO driver. See comments inline.
Quoted 19 lines · Octávio Carneiro
Add
iio_device_claim_direct()to protect buffered captures. Inad4000_write_raw_get_fmt, data reads are protected by the function call to avoid possible errors caused by concurrent access.Signed-off-by Fernando Lima <[email protected]>Co-developed-by Octávio Carneiro <[email protected]>Signed-off-by Octávio Carneiro <[email protected]>Co-developed-by Lucas Eiji <[email protected]>Signed-off-by Lucas Eiji <[email protected]>--- drivers/iio/adc/ad4000.c | 3 +++ 1 file changed, 3 insertions(+)drivers/iio/adc/ad4000.c +0
-0
drivers/iio/adc/ad4000.c static int ad4000_write_raw_get_fmt(struct iio_dev *indio_dev, · line 588
Quoted 6 lines
drivers/iio/adc/ad4000.c +3
-0@@ -583,6 +583,9 @@ static int ad4000_write_raw_get_fmt(struct iio_dev *indio_dev, {switch (mask) {case IIO_CHAN_INFO_SCALE : +if (!iio_device_claim_direct (indio_dev)) +return -EBUSY ; +iio_device_release_direct (indio_dev);
In the ad4000 driver, the main purpose of claiming IIO direct mode is to keep the integrity of buffered data capture. Basically, we want to avoid changes of device state properties and the issue of concurrent readings. Note that under the hood, iio_device_claim_direct() acquires a mutex lock. Also, it is good practice to protect only the critical paths and to not keep locks of access control mechanisms for longer than what's really needed. Thus, we claim IIO direct mode at ad4000_read_raw() and at ad4000_write_raw(), right before running ADC data or register access transfers.
So, the proposed addition is not needed and doesn't really follow best programming practices.
drivers/iio/adc/ad4000.c static int ad4000_write_raw_get_fmt(struct iio_dev *indio_dev, · line 591
Quoted 3 lines
drivers/iio/adc/ad4000.c +0
-0return IIO_VAL_INT_PLUS_NANO ;default :return IIO_VAL_INT_PLUS_MICRO ;
With best regards,
Marcelo