Skip to contentSkip to conversation

media: uvcvideo: user entity get_cur in uvc_ctrl_set

PATCH Superseded Yunke Cao 2 participants 3 messages Jun 21, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yunke Cao

author
#0 lore raw

PATCH 1/1 media: uvcvideo: user entity get_cur in uvc_ctrl_set

Entity controls should get_cur using an entity-defined function instead of via a query. Fix this in uvc_ctrl_set.

Fixes 65900c581d01 ("media: uvcvideo: Allow entity-defined get_info and get_cur")
---
 drivers/media/usb/uvc/uvc_ctrl.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +8 -2
index 0e78233fc8a0..54c047019313 100644
@@ -1787,15 +1787,21 @@ int uvc_ctrl_set(struct uvc_fh *handle,
 		if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) {
 			memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
 				0, ctrl->info.size);
+		} else if (ctrl->entity->get_cur) {
+			ret = ctrl->entity->get_cur(chain->dev,
+				ctrl->entity,
+				ctrl->info.selector,
+				uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+				ctrl->info.size);
 		} else {
 			ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
 				ctrl->entity->id, chain->dev->intfnum,
 				ctrl->info.selector,
 				uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
 				ctrl->info.size);
-			if (ret < 0)
-				return ret;
 		}
+		if (ret < 0)
+			return ret;
 
 		ctrl->loaded = 1;
 	}
Signature · 1 line
2.37.0.rc0.104.g0611611a94-goog
maintainer
#1 lore raw

Hi Yunke,

Thank you for the patch.

Quoted 24 lines · Yunke Cao

Entity controls should get_cur using an entity-defined function instead of via a query. Fix this in uvc_ctrl_set.

Fixes 65900c581d01 ("media: uvcvideo: Allow entity-defined get_info and get_cur")
---
 drivers/media/usb/uvc/uvc_ctrl.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +6 -0
index 0e78233fc8a0..54c047019313 100644
@@ -1787,15 +1787,21 @@ int uvc_ctrl_set(struct uvc_fh *handle,
 		if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) {
 			memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
 				0, ctrl->info.size);
+		} else if (ctrl->entity->get_cur) {
+			ret = ctrl->entity->get_cur(chain->dev,
+				ctrl->entity,
+				ctrl->info.selector,
+				uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+				ctrl->info.size);
 		} else {

drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_set(struct uvc_fh *handle, · line 1804

Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
 			ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
 				ctrl->entity->id, chain->dev->intfnum,
 				ctrl->info.selector,
 				uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
 				ctrl->info.size);
-			if (ret < 0)
-				return ret;
 		}
+		if (ret < 0)
+			return ret;

ret may be used uninitialized here.

drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_set(struct uvc_fh *handle, · line 1806

Quoted 2 lines
drivers/media/usb/uvc/uvc_ctrl.c +0 -0
 		ctrl->loaded = 1;

There's very similar code in __uvc_ctrl_get(), could it be factored out, maybe into a __uvc_ctrl_get_cur() function ?

Quoted 1 line
drivers/media/usb/uvc/uvc_ctrl.c +0 -0
 	}
Signature · 3 lines
Regards,

Laurent Pinchart
author
#2 lore raw

Hi Laurent,

Thanks for the review.

Quoted 44 lines · Laurent Pinchart

Hi Yunke,

Thank you for the patch.

Quoted 24 lines · Yunke Cao

Entity controls should get_cur using an entity-defined function instead of via a query. Fix this in uvc_ctrl_set.

Fixes 65900c581d01 ("media: uvcvideo: Allow entity-defined get_info and get_cur")
---
 drivers/media/usb/uvc/uvc_ctrl.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +6 -0
index 0e78233fc8a0..54c047019313 100644
@@ -1787,15 +1787,21 @@ int uvc_ctrl_set(struct uvc_fh *handle,
              if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) {
                      memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
                              0, ctrl->info.size);
+             } else if (ctrl->entity->get_cur) {
+                     ret = ctrl->entity->get_cur(chain->dev,
+                             ctrl->entity,
+                             ctrl->info.selector,
+                             uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                             ctrl->info.size);
              } else {

drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_set(struct uvc_fh *handle, · line 1804

Quoted 10 lines
drivers/media/usb/uvc/uvc_ctrl.c +2 -2
                      ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
                              ctrl->entity->id, chain->dev->intfnum,
                              ctrl->info.selector,
                              uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
                              ctrl->info.size);
-                     if (ret < 0)
-                             return ret;
              }
+             if (ret < 0)
+                     return ret;

ret may be used uninitialized here.

Quoted 1 line
Quoted 5 lines
Quoted 1 line
              ctrl->loaded = 1;

There's very similar code in __uvc_ctrl_get(), could it be factored out, maybe into a __uvc_ctrl_get_cur() function ?

Sounds good! I'm sending out v2.

Changelog since v1:
-Factored out common logic into __uvc_ctrl_load_cur(). (I called it "load_cur" because I feel it's a bit more accurate)

Best,
Yunke

Quoted 6 lines
Quoted 1 line
      }

--
Regards,

Laurent Pinchart