media: uvcvideo: Override default flags
Subsystems (2)
PATCH 1/1 media: uvcvideo: Override default flags
When the UVC device has a control that is readonly it doesn't set the SET_CUR flag. For example the privacy control has SET_CUR flag set in the defaults in the uvc_ctrls variable. Even if the device does not have it set, it's not cleared by uvc_ctrl_get_flags.
Originally written with assignment in commit 859086ae3636 ("media:
uvcvideo: Apply flags from device to actual properties"). But changed to |= in commit 0dc68cabdb62 ("media: uvcvideo: Prevent setting unavailable flags"). It would not clear the default flags.
With this patch applied the correct flags are reported to user space. Tested with:
``` > v4l2-ctl --list-ctrls | grep privacy privacy 0x009a0910 (bool) : default=0 value=0 flags=read-only ```
--- drivers/media/usb/uvc/uvc_ctrl.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +17 -9
@@ -2031,15 +2031,23 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev,else ret =uvc_query_ctrl (dev,UVC_GET_INFO , ctrl->entity->id, dev->intfnum, info->selector, data,1 ); -if (!ret) - info->flags |= (data[0 ] &UVC_CONTROL_CAP_GET ? -UVC_CTRL_FLAG_GET_CUR :0 ) - | (data[0 ] &UVC_CONTROL_CAP_SET ? -UVC_CTRL_FLAG_SET_CUR :0 ) - | (data[0 ] &UVC_CONTROL_CAP_AUTOUPDATE ? -UVC_CTRL_FLAG_AUTO_UPDATE :0 ) - | (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ? -UVC_CTRL_FLAG_ASYNCHRONOUS :0 ); +if (!ret) { + info->flags = (data[0 ] &UVC_CONTROL_CAP_GET ) + ? (info->flags |UVC_CTRL_FLAG_GET_CUR ) + : (info->flags & ~UVC_CTRL_FLAG_GET_CUR ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_SET ) + ? (info->flags |UVC_CTRL_FLAG_SET_CUR ) + : (info->flags & ~UVC_CTRL_FLAG_SET_CUR ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_AUTOUPDATE ) + ? (info->flags |UVC_CTRL_FLAG_AUTO_UPDATE ) + : (info->flags & ~UVC_CTRL_FLAG_AUTO_UPDATE ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ) + ? (info->flags |UVC_CTRL_FLAG_ASYNCHRONOUS ) + : (info->flags & ~UVC_CTRL_FLAG_ASYNCHRONOUS ); + }kfree (data);return ret;
Signature · 1 line
2.43.0
Hi Daniel
Thanks for the patch. Some minor nits.
Feel free to ignore it if you prefer your style.
Quoted 19 lines · Daniel Schaefer
When the UVC device has a control that is readonly it doesn't set the
SET_CURflag. For example the privacy control hasSET_CURflag set in the defaults in theuvc_ctrlsvariable. Even if the device does not have it set, it's not cleared byuvc_ctrl_get_flags.Originally written with assignment in commit
859086ae3636("media:
uvcvideo: Apply flags from device to actual properties"). But changed to |= in commit0dc68cabdb62("media: uvcvideo: Prevent setting unavailable flags"). It would not clear the default flags.With this patch applied the correct flags are reported to user space. Tested with:
``` > v4l2-ctl --list-ctrls | grep privacy privacy 0x009a0910 (bool) : default=0 value=0 flags=read-only ```
Quoted 6 lines
Cc Edgar Thier <[email protected]>Cc Kieran Bingham <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Kieran Levin <[email protected]>Signed-off-by Daniel Schaefer <[email protected]>
Quoted 28 lines
--- drivers/media/usb/uvc/uvc_ctrl.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +7
-9@@ -2031,15 +2031,23 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev,else ret =uvc_query_ctrl (dev,UVC_GET_INFO , ctrl->entity->id, dev->intfnum, info->selector, data,1 ); -if (!ret) - info->flags |= (data[0 ] &UVC_CONTROL_CAP_GET ? -UVC_CTRL_FLAG_GET_CUR :0 ) - | (data[0 ] &UVC_CONTROL_CAP_SET ? -UVC_CTRL_FLAG_SET_CUR :0 ) - | (data[0 ] &UVC_CONTROL_CAP_AUTOUPDATE ? -UVC_CTRL_FLAG_AUTO_UPDATE :0 ) - | (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ? -UVC_CTRL_FLAG_ASYNCHRONOUS :0 ); +if (!ret) { + info->flags = (data[0 ] &UVC_CONTROL_CAP_GET ) + ? (info->flags |UVC_CTRL_FLAG_GET_CUR ) + : (info->flags & ~UVC_CTRL_FLAG_GET_CUR ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_SET ) + ? (info->flags | UVC_CTRL_FLAG_SET_CUR)
drivers/media/usb/uvc/uvc_ctrl.c static int uvc_ctrl_get_flags(struct uvc_device *dev, · line 2050
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ : (info->flags & ~UVC_CTRL_FLAG_SET_CUR); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_AUTOUPDATE ) + ? (info->flags |UVC_CTRL_FLAG_AUTO_UPDATE ) + : (info->flags & ~UVC_CTRL_FLAG_AUTO_UPDATE ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ) + ? (info->flags |UVC_CTRL_FLAG_ASYNCHRONOUS ) + : (info->flags & ~UVC_CTRL_FLAG_ASYNCHRONOUS ); + }
nit: I would have done it as
drivers/media/usb/uvc/uvc_ctrl.c +7 -1
@@ -2031,7 +2031,12 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev,else ret =uvc_query_ctrl (dev,UVC_GET_INFO , ctrl->entity->id, dev->intfnum, info->selector, data,1 ); -if (!ret) +if (!ret) { + info->flags &= ~(UVC_CTRL_FLAG_GET_CUR | +UVC_CTRL_FLAG_SET_CUR | +UVC_CTRL_FLAG_AUTO_UPDATE | +UVC_CTRL_FLAG_ASYNCHRONOUS ); + info->flags |= (data[0 ] &UVC_CONTROL_CAP_GET ?UVC_CTRL_FLAG_GET_CUR :0 ) | (data[0] & UVC_CONTROL_CAP_SET ?
@@ -2040,6 +2045,7 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev, UVC_CTRL_FLAG_AUTO_UPDATE : 0) | (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ?UVC_CTRL_FLAG_ASYNCHRONOUS :0 ); + }
Quoted 7 lines
drivers/media/usb/uvc/uvc_ctrl.c +0
-1kfree (data);return ret; --2.43.0
Signature · 1 line
Ricardo Ribalda
Quoted 7 lines · Ricardo Ribalda
Hi Daniel
Thanks for the patch. Some minor nits.
Feel free to ignore it if you prefer your style.
Sure, that's also a nice way to do it. I'm okay with either one, whatever the media subsystem maintainers prefer.
Quoted 94 lines · Ricardo Ribalda
Hi Daniel
Thanks for the patch. Some minor nits.
Feel free to ignore it if you prefer your style.
Quoted 19 lines · Daniel Schaefer
When the UVC device has a control that is readonly it doesn't set the
SET_CURflag. For example the privacy control hasSET_CURflag set in the defaults in theuvc_ctrlsvariable. Even if the device does not have it set, it's not cleared byuvc_ctrl_get_flags.Originally written with assignment in commit
859086ae3636("media:
uvcvideo: Apply flags from device to actual properties"). But changed to |= in commit0dc68cabdb62("media: uvcvideo: Prevent setting unavailable flags"). It would not clear the default flags.With this patch applied the correct flags are reported to user space. Tested with:
``` > v4l2-ctl --list-ctrls | grep privacy privacy 0x009a0910 (bool) : default=0 value=0 flags=read-only ```Quoted 6 lines
Cc Edgar Thier <[email protected]>Cc Kieran Bingham <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Kieran Levin <[email protected]>Signed-off-by Daniel Schaefer <[email protected]>Fixes 0dc68cabdb62 ("media: uvcvideo: Prevent setting unavailable flags")Reviewed-by Ricardo Ribalda <[email protected]>Quoted 28 lines
--- drivers/media/usb/uvc/uvc_ctrl.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)drivers/media/usb/uvc/uvc_ctrl.c +7
-9@@ -2031,15 +2031,23 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev,else ret =uvc_query_ctrl (dev,UVC_GET_INFO , ctrl->entity->id, dev->intfnum, info->selector, data,1 ); -if (!ret) - info->flags |= (data[0 ] &UVC_CONTROL_CAP_GET ? -UVC_CTRL_FLAG_GET_CUR :0 ) - | (data[0 ] &UVC_CONTROL_CAP_SET ? -UVC_CTRL_FLAG_SET_CUR :0 ) - | (data[0 ] &UVC_CONTROL_CAP_AUTOUPDATE ? -UVC_CTRL_FLAG_AUTO_UPDATE :0 ) - | (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ? -UVC_CTRL_FLAG_ASYNCHRONOUS :0 ); +if (!ret) { + info->flags = (data[0 ] &UVC_CONTROL_CAP_GET ) + ? (info->flags |UVC_CTRL_FLAG_GET_CUR ) + : (info->flags & ~UVC_CTRL_FLAG_GET_CUR ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_SET ) + ? (info->flags | UVC_CTRL_FLAG_SET_CUR)drivers/media/usb/uvc/uvc_ctrl.c static int uvc_ctrl_get_flags(struct uvc_device *dev, · line 2050
Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +10
-0+ : (info->flags & ~UVC_CTRL_FLAG_SET_CUR); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_AUTOUPDATE ) + ? (info->flags |UVC_CTRL_FLAG_AUTO_UPDATE ) + : (info->flags & ~UVC_CTRL_FLAG_AUTO_UPDATE ); + + info->flags = (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ) + ? (info->flags |UVC_CTRL_FLAG_ASYNCHRONOUS ) + : (info->flags & ~UVC_CTRL_FLAG_ASYNCHRONOUS ); + }nit: I would have done it as
drivers/media/usb/uvc/uvc_ctrl.c +6
-1@@ -2031,7 +2031,12 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev,else ret =uvc_query_ctrl (dev,UVC_GET_INFO , ctrl->entity->id, dev->intfnum, info->selector, data,1 ); -if (!ret) +if (!ret) { + info->flags &= ~(UVC_CTRL_FLAG_GET_CUR | +UVC_CTRL_FLAG_SET_CUR | +UVC_CTRL_FLAG_AUTO_UPDATE | +UVC_CTRL_FLAG_ASYNCHRONOUS ); + info->flags |= (data[0 ] &UVC_CONTROL_CAP_GET ?UVC_CTRL_FLAG_GET_CUR :0 ) | (data[0] & UVC_CONTROL_CAP_SET ?
drivers/media/usb/uvc/uvc_ctrl.c static int uvc_ctrl_get_flags(struct uvc_device *dev, · line 2048
Quoted 4 lines
drivers/media/usb/uvc/uvc_ctrl.c +1
-0@@ -2040,6 +2045,7 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev, UVC_CTRL_FLAG_AUTO_UPDATE : 0) | (data[0 ] &UVC_CONTROL_CAP_ASYNCHRONOUS ?UVC_CTRL_FLAG_ASYNCHRONOUS :0 ); + }
I prefer that slightly too.
I'll make the change in my tree, no need to send a v2.
Quoted 3 lines
Quoted 3 lines
drivers/media/usb/uvc/uvc_ctrl.c +0
-0kfree (data);return ret;
Signature · 3 lines
Regards, Laurent Pinchart