[PATCH v3 6/8] media: uvcvideo: Do not enable camera during UVCIOC_CTRL_MAP*

Ricardo Ribalda posted 8 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v3 6/8] media: uvcvideo: Do not enable camera during UVCIOC_CTRL_MAP*
Posted by Ricardo Ribalda 3 months, 1 week ago
The device does not need to be enabled to do this, it is merely an
internal data operation.

Reviewed-by: Hans de Goede <hansg@kernel.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 7ab1bdcfb493fe9f47dbdc86da23cba98d7d10ff..350cd2cc88f872d2e8bd19e2b8fb067894916364 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -1178,10 +1178,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
 	void __user *up = compat_ptr(arg);
 	long ret;
 
-	ret = uvc_pm_get(handle->stream->dev);
-	if (ret)
-		return ret;
-
 	switch (cmd) {
 	case UVCIOC_CTRL_MAP32:
 		ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
@@ -1197,9 +1193,15 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
 
 	case UVCIOC_CTRL_QUERY32:
 		ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
+		if (ret)
+			break;
+
+		ret = uvc_pm_get(handle->stream->dev);
 		if (ret)
 			break;
 		ret = uvc_xu_ctrl_query(handle->chain, &karg.xqry);
+		uvc_pm_put(handle->stream->dev);
+
 		if (ret)
 			break;
 		ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
@@ -1212,8 +1214,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
 		break;
 	}
 
-	uvc_pm_put(handle->stream->dev);
-
 	return ret;
 }
 #endif
@@ -1226,6 +1226,7 @@ static long uvc_v4l2_unlocked_ioctl(struct file *file,
 
 	/* The following IOCTLs do not need to turn on the camera. */
 	switch (cmd) {
+	case UVCIOC_CTRL_MAP:
 	case VIDIOC_CREATE_BUFS:
 	case VIDIOC_DQBUF:
 	case VIDIOC_ENUM_FMT:

-- 
2.50.0.727.gbf7dc18ff4-goog
Re: [PATCH v3 6/8] media: uvcvideo: Do not enable camera during UVCIOC_CTRL_MAP*
Posted by Laurent Pinchart 3 months, 1 week ago
Hi Ricardo,

Thank you for the patch.

On Mon, Jun 30, 2025 at 02:20:31PM +0000, Ricardo Ribalda wrote:
> The device does not need to be enabled to do this, it is merely an
> internal data operation.

How about the following code path ?

uvc_ioctl_xu_ctrl_map()
  uvc_ctrl_add_mapping()
    uvc_ctrl_init_xu_ctrl()
      uvc_ctrl_fill_xu_info()
        uvc_query_ctrl()

?

> Reviewed-by: Hans de Goede <hansg@kernel.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 7ab1bdcfb493fe9f47dbdc86da23cba98d7d10ff..350cd2cc88f872d2e8bd19e2b8fb067894916364 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -1178,10 +1178,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
>  	void __user *up = compat_ptr(arg);
>  	long ret;
>  
> -	ret = uvc_pm_get(handle->stream->dev);
> -	if (ret)
> -		return ret;
> -
>  	switch (cmd) {
>  	case UVCIOC_CTRL_MAP32:
>  		ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
> @@ -1197,9 +1193,15 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
>  
>  	case UVCIOC_CTRL_QUERY32:
>  		ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
> +		if (ret)
> +			break;
> +
> +		ret = uvc_pm_get(handle->stream->dev);
>  		if (ret)
>  			break;
>  		ret = uvc_xu_ctrl_query(handle->chain, &karg.xqry);
> +		uvc_pm_put(handle->stream->dev);
> +
>  		if (ret)
>  			break;
>  		ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
> @@ -1212,8 +1214,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
>  		break;
>  	}
>  
> -	uvc_pm_put(handle->stream->dev);
> -
>  	return ret;
>  }
>  #endif
> @@ -1226,6 +1226,7 @@ static long uvc_v4l2_unlocked_ioctl(struct file *file,
>  
>  	/* The following IOCTLs do not need to turn on the camera. */
>  	switch (cmd) {
> +	case UVCIOC_CTRL_MAP:
>  	case VIDIOC_CREATE_BUFS:
>  	case VIDIOC_DQBUF:
>  	case VIDIOC_ENUM_FMT:

-- 
Regards,

Laurent Pinchart
Re: [PATCH v3 6/8] media: uvcvideo: Do not enable camera during UVCIOC_CTRL_MAP*
Posted by Ricardo Ribalda 3 months, 1 week ago
Hi

On Tue, 1 Jul 2025 at 00:15, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> Thank you for the patch.
>
> On Mon, Jun 30, 2025 at 02:20:31PM +0000, Ricardo Ribalda wrote:
> > The device does not need to be enabled to do this, it is merely an
> > internal data operation.
>
> How about the following code path ?

Ups, thanks for catching this.

I will probably rename uvc_ctrl_add_mapping() to
uvc_ctrl_add_xu_mapping() in a future set.

Regards!

>
> uvc_ioctl_xu_ctrl_map()
>   uvc_ctrl_add_mapping()
>     uvc_ctrl_init_xu_ctrl()
>       uvc_ctrl_fill_xu_info()
>         uvc_query_ctrl()
>
> ?
>
> > Reviewed-by: Hans de Goede <hansg@kernel.org>
> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > ---
> >  drivers/media/usb/uvc/uvc_v4l2.c | 13 +++++++------
> >  1 file changed, 7 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> > index 7ab1bdcfb493fe9f47dbdc86da23cba98d7d10ff..350cd2cc88f872d2e8bd19e2b8fb067894916364 100644
> > --- a/drivers/media/usb/uvc/uvc_v4l2.c
> > +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> > @@ -1178,10 +1178,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
> >       void __user *up = compat_ptr(arg);
> >       long ret;
> >
> > -     ret = uvc_pm_get(handle->stream->dev);
> > -     if (ret)
> > -             return ret;
> > -
> >       switch (cmd) {
> >       case UVCIOC_CTRL_MAP32:
> >               ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up);
> > @@ -1197,9 +1193,15 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
> >
> >       case UVCIOC_CTRL_QUERY32:
> >               ret = uvc_v4l2_get_xu_query(&karg.xqry, up);
> > +             if (ret)
> > +                     break;
> > +
> > +             ret = uvc_pm_get(handle->stream->dev);
> >               if (ret)
> >                       break;
> >               ret = uvc_xu_ctrl_query(handle->chain, &karg.xqry);
> > +             uvc_pm_put(handle->stream->dev);
> > +
> >               if (ret)
> >                       break;
> >               ret = uvc_v4l2_put_xu_query(&karg.xqry, up);
> > @@ -1212,8 +1214,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file,
> >               break;
> >       }
> >
> > -     uvc_pm_put(handle->stream->dev);
> > -
> >       return ret;
> >  }
> >  #endif
> > @@ -1226,6 +1226,7 @@ static long uvc_v4l2_unlocked_ioctl(struct file *file,
> >
> >       /* The following IOCTLs do not need to turn on the camera. */
> >       switch (cmd) {
> > +     case UVCIOC_CTRL_MAP:
> >       case VIDIOC_CREATE_BUFS:
> >       case VIDIOC_DQBUF:
> >       case VIDIOC_ENUM_FMT:
>
> --
> Regards,
>
> Laurent Pinchart



-- 
Ricardo Ribalda