iio: adc: viperboard: Fix error handling in vprbrd_iio_read_raw
PATCH v2 1/1 iio: adc: viperboard: Fix error handling in vprbrd_iio_read_raw
The driver proceeds to the reception phase even if the preceding transmission fails.
This uses a goto error label for an early bail out and ensures the mutex is properly unlocked in case of failure.
---
Changes in v2:
- Add "adc" to the patch title.
- Move dev_err() out of the mutex critical section.
- Include Reviewed-by tags from Joshua and Maxwell.
drivers/iio/adc/viperboard_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/viperboard_adc.c +3 -1
@@ -70,8 +70,10 @@ static int vprbrd_iio_read_raw(struct iio_dev *iio_dev,VPRBRD_USB_TYPE_OUT ,0x0000 ,0x0000 , admsg, sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS);if (ret !=sizeof (struct vprbrd_adc_msg )) { -dev_err (&iio_dev->dev,"usb send error on adc read\n" ); error = -EREMOTEIO ; +mutex_unlock (&vb->lock); +dev_err (&iio_dev->dev,"usb send error on adc read\n" ); + goto error; } ret = usb_control_msg(vb->usb_dev,
Signature · 1 line
2.43.0
Quoted 5 lines · Salah Triki
The driver proceeds to the reception phase even if the preceding transmission fails.
This uses a goto error label for an early bail out and ensures the mutex is properly unlocked in case of failure.
...
drivers/iio/adc/viperboard_adc.c static int vprbrd_iio_read_raw(struct iio_dev *iio_dev, · line 73
Quoted 3 lines
drivers/iio/adc/viperboard_adc.c +0
-1if (ret !=sizeof (struct vprbrd_adc_msg )) { -dev_err (&iio_dev->dev,"usb send error on adc read\n" ); error = -EREMOTEIO ;
This also a local variable that doesn't need to be in the critical section, right?
Quoted 4 lines
drivers/iio/adc/viperboard_adc.c +3
-0+mutex_unlock (&vb->lock); +dev_err (&iio_dev->dev,"usb send error on adc read\n" ); + goto error; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Salah Triki
The driver proceeds to the reception phase even if the preceding transmission fails.
This uses a goto error label for an early bail out and ensures the mutex is properly unlocked in case of failure.
Fixes ffd8a6e7a778 ("iio: adc: Add viperboard adc driver")Signed-off-by Salah Triki <[email protected]>Reviewed-by Joshua Crofts <[email protected]>Reviewed-by Maxwell Doose <[email protected]>---
LGTM (though Andy's comment makes sense):
Quoted 24 lines
Changes in v2:
- Add "adc" to the patch title.
- Movedev_err()out of the mutex critical section.
- Include Reviewed-by tags from Joshua and Maxwell.drivers/iio/adc/viperboard_adc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/adc/viperboard_adc.c +3
-1@@ -70,8 +70,10 @@ static int vprbrd_iio_read_raw(struct iio_dev *iio_dev, VPRBRD_USB_TYPE_OUT, 0x0000, 0x0000, admsg, sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS); if (ret != sizeof(struct vprbrd_adc_msg)) { -dev_err (&iio_dev->dev,"usb send error on adc read\n" ); error = -EREMOTEIO; +mutex_unlock (&vb->lock); +dev_err (&iio_dev->dev,"usb send error on adc read\n" ); + goto error; }
ret = usb_control_msg(vb->usb_dev,
Jonathan Cameron
maintainerQuoted 7 lines · On Sat, 9 May 2026 10:56:26 +0300 Andy Shevchenko…
Quoted 5 lines · Salah Triki
The driver proceeds to the reception phase even if the preceding transmission fails.
This uses a goto error label for an early bail out and ensures the mutex is properly unlocked in case of failure.
Quoted 8 lines
...
drivers/iio/adc/viperboard_adc.c static int vprbrd_iio_read_raw(struct iio_dev *iio_dev, · line 73
Quoted 3 lines
drivers/iio/adc/viperboard_adc.c +0
-1if (ret !=sizeof (struct vprbrd_adc_msg )) { -dev_err (&iio_dev->dev,"usb send error on adc read\n" ); error = -EREMOTEIO ;This also a local variable that doesn't need to be in the critical section, right?
Tweaked and applied to the fixes-togreg branch of iio.git + marked for stable.
Quoted 6 lines
Quoted 5 lines
drivers/iio/adc/viperboard_adc.c +3
-0+mutex_unlock (&vb->lock); +dev_err (&iio_dev->dev,"usb send error on adc read\n" ); + goto error; }