iio: viperboard: Fix error handling in vprbrd_iio_read_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.
--- drivers/iio/adc/viperboard_adc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/adc/viperboard_adc.c +2 -0
@@ -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
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")Signed-off-by Salah Triki <[email protected]>
Nitpick, but I would add adc into the patch title ("iio: adc: viperboard: ...").
Quoted 15 lines
drivers/iio/adc/viperboard_adc.c +2
-1@@ -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
Maxwell Doose
Reviewed-byQuoted 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")Signed-off-by Salah Triki <[email protected]>Nitpick, but I would add adc into the patch title ("iio: adc: viperboard: ...").
[snip]
Quoted 5 lines
Code-wise LGTM.
Reviewed-by Joshua Crofts <[email protected]>
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 regardsCJD
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
-0if (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