[PATCH] iio: viperboard: Fix error handling in vprbrd_iio_read_raw

Salah Triki posted 1 patch 1 month, 1 week ago
drivers/iio/adc/viperboard_adc.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] iio: viperboard: Fix error handling in vprbrd_iio_read_raw
Posted by Salah Triki 1 month, 1 week ago
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 <salah.triki@gmail.com>
---
 drivers/iio/adc/viperboard_adc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c
index 9bb0b83c8f67..14d018b5aa33 100644
--- a/drivers/iio/adc/viperboard_adc.c
+++ b/drivers/iio/adc/viperboard_adc.c
@@ -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,
-- 
2.43.0
Re: [PATCH] iio: viperboard: Fix error handling in vprbrd_iio_read_raw
Posted by Andy Shevchenko 1 month, 1 week ago
On Tue, May 05, 2026 at 10:17:50PM +0100, Salah Triki wrote:
> 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.

...

>  		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).

>  		}

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] iio: viperboard: Fix error handling in vprbrd_iio_read_raw
Posted by Joshua Crofts 1 month, 1 week ago
On Tue, 5 May 2026 at 23:18, Salah Triki <salah.triki@gmail.com> wrote:
>
> 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 <salah.triki@gmail.com>

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

>
> diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c
> index 9bb0b83c8f67..14d018b5aa33 100644
> --- a/drivers/iio/adc/viperboard_adc.c
> +++ b/drivers/iio/adc/viperboard_adc.c
> @@ -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,
> --
> 2.43.0

Code-wise LGTM.

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards

CJD
Re: [PATCH] iio: viperboard: Fix error handling in vprbrd_iio_read_raw
Posted by Maxwell Doose 1 month, 1 week ago
On Tue, May 5, 2026 at 5:06 PM Joshua Crofts <joshua.crofts1@gmail.com> wrote:
>
> On Tue, 5 May 2026 at 23:18, Salah Triki <salah.triki@gmail.com> wrote:
> >
> > 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 <salah.triki@gmail.com>
>
> Nitpick, but I would add adc into the patch title ("iio: adc: viperboard: ...").
>
[snip]
>
> Code-wise LGTM.
>
> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
>

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

Reviewed-by: Maxwell Doose <m32285159@gmail.com>

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()())

> --
> Kind regards
>
> CJD
>