Skip to contentSkip to conversation

iio: adc: viperboard: Fix error handling in vprbrd_iio_read_raw

PATCH In review Salah Triki 4 participants 4 messages May 7 – May 11 IIO

lore
Share & tools
lore
#0 lore 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.

Fixes ffd8a6e7a778 ("iio: adc: Add viperboard adc driver")

---
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
index 9bb0b83c8f67..f7ce3effd730 100644
@@ -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
#1 lore raw
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 -1
 		if (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
Reviewed-by on v2 1/1
#3 lore raw
In reply to Salah Triki
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")

---

LGTM (though Andy's comment makes sense):

Quoted 24 lines

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
index 9bb0b83c8f67..f7ce3effd730 100644
@@ -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,

maintainer
#2 lore raw
In reply to Andy Shevchenko
Quoted 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 -1
 		if (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;
 		}