Skip to contentSkip to conversation

iio: viperboard: Fix error handling in vprbrd_iio_read_raw

PATCH Superseded Salah Triki 4 participants 4 messages May 5 – May 6 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: 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")
---
 drivers/iio/adc/viperboard_adc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/adc/viperboard_adc.c +2 -0
index 9bb0b83c8f67..14d018b5aa33 100644
@@ -72,6 +72,8 @@ static int vprbrd_iio_read_raw(struct iio_dev *iio_dev,
 		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);
+			goto error;
 		}
 
 		ret = usb_control_msg(vb->usb_dev,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 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")

Nitpick, but I would add adc into the patch title ("iio: adc: viperboard: ...").

Quoted 15 lines
drivers/iio/adc/viperboard_adc.c +2 -1
index 9bb0b83c8f67..14d018b5aa33 100644
@@ -72,6 +72,8 @@ static int vprbrd_iio_read_raw(struct iio_dev *iio_dev,
                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);
+                       goto error;
                }
 
                ret = usb_control_msg(vb->usb_dev,
--
Quoted 1 line

2.43.0

Code-wise LGTM.

Signature · 3 lines
Kind regards

CJD
Reviewed-by
#2 lore raw
Quoted 14 lines · Joshua Crofts
Quoted 9 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")

Nitpick, but I would add adc into the patch title ("iio: adc: viperboard: ...").

[snip]

Quoted 5 lines

Code-wise LGTM.

Agree with Joshua here. Should add adc to subject but lgtm.

best regards,
max

(p.s., might be a good idea to send a patch for this file replacing all of the mutex_lock()s and unlock()s with guard()())

Quoted 5 lines

--
Kind regards

CJD

#3 lore raw
In reply to Salah Triki
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 76

Quoted 5 lines
drivers/iio/adc/viperboard_adc.c +2 -0
 		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);
+			goto error;

Printing message can be out from critical section (yeah, the guard()() or whatever change may do it differently, but it's unrelated to this patch).

Quoted 1 line

}

Signature · 2 lines
With Best Regards,
Andy Shevchenko