[RESEND,v2,4/7] media: uvcvideo: Do not return positive errors in uvc_query_ctrl()

Message ID 20220920-resend-v4l2-compliance-v2-4-b0ceb15353ac@chromium.org
State New
Headers
Series Follow-up patches for uvc v4l2-compliance |

Commit Message

Ricardo Ribalda Dec. 2, 2022, 5:21 p.m. UTC
  If the returned size of the query does not match the expected size or it
is zero, return -EPIPE instead of 0 or a positive value.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/usb/uvc/uvc_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Laurent Pinchart Dec. 29, 2022, 3:28 a.m. UTC | #1
Hi Ricardo,

Thank you for the patch.

On Fri, Dec 02, 2022 at 06:21:38PM +0100, Ricardo Ribalda wrote:
> If the returned size of the query does not match the expected size or it
> is zero, return -EPIPE instead of 0 or a positive value.

The commit message should explain why: this will avoid confusing the
caller (and ultimately userspace) that doesn't expect a positive or zero
value.

> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>

I'll update the commit message locally.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/usb/uvc/uvc_video.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 497073a50194..902f2817a743 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -83,7 +83,7 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
>  		dev_err(&dev->udev->dev,
>  			"Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n",
>  			uvc_query_name(query), cs, unit, ret, size);
> -		return ret;
> +		return ret < 0 ? ret : -EPIPE;
>  	}
>  
>  	/* reuse data[0] to request the error code. */
>
  

Patch

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 497073a50194..902f2817a743 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -83,7 +83,7 @@  int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
 		dev_err(&dev->udev->dev,
 			"Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n",
 			uvc_query_name(query), cs, unit, ret, size);
-		return ret;
+		return ret < 0 ? ret : -EPIPE;
 	}
 
 	/* reuse data[0] to request the error code. */