Skip to contentSkip to conversation

media: uvcvideo: Fix custom control mapping probing

PATCH In review Ricardo Ribalda 3 participants 4 messages Jul 22, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: uvcvideo: Fix custom control mapping probing

Custom control mapping introduced a bug, where the filter function was applied to every single control.

Fix it so it is only applied to the matching controls.

The following dmesg errors during probe are now fixed:

usb 1-5: Found UVC 1.00 device Integrated_Webcam_HD (0c45:670c) usb 1-5: Failed to query (GET_CUR) UVC control 2 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 3 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 6 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 7 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 8 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 9 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 10 on unit 2: -75 (exp. 1).

Fixes 8f4362a8d42b ("media: uvcvideo: Allow custom control mapping")

---
Paul, could you check if this fixes your issue, thanks!
---
Changes in v2:
- Replace !(A && B) with (!A || !B)
- Add error message to commit message
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/media/usb/uvc/uvc_ctrl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +5 -3
index 0136df5732ba..4fe26e82e3d1 100644
@@ -2680,6 +2680,10 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); ++i) {
 		const struct uvc_control_mapping *mapping = &uvc_ctrl_mappings[i];
 
+		if (!uvc_entity_match_guid(ctrl->entity, mapping->entity) ||
+		    ctrl->info.selector != mapping->selector)
+			continue;
+
 		/* Let the device provide a custom mapping. */
 		if (mapping->filter_mapping) {
 			mapping = mapping->filter_mapping(chain, ctrl);
@@ -2687,9 +2691,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 				continue;
 		}
 
-		if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
-		    ctrl->info.selector == mapping->selector)
-			__uvc_ctrl_add_mapping(chain, ctrl, mapping);
+		__uvc_ctrl_add_mapping(chain, ctrl, mapping);
 	}
 }
 

---
base-commit: 68a72104cbcf38ad16500216e213fa4eb21c4be2
change-id: 20240722-fix-filter-mapping-18477dc69048

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

Dear Ricardo,

Thank you for sending v2.

Am 22.07.24 um 13:52 schrieb Ricardo Ribalda:

Quoted 16 lines

Custom control mapping introduced a bug, where the filter function was applied to every single control.

Fix it so it is only applied to the matching controls.

The following dmesg errors during probe are now fixed:

usb 1-5: Found UVC 1.00 device Integrated_Webcam_HD (0c45:670c) usb 1-5: Failed to query (GET_CUR) UVC control 2 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 3 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 6 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 7 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 8 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 9 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 10 on unit 2: -75 (exp. 1).

Quoted 1 line

Menze*l*

Quoted 31 lines
Fixes 8f4362a8d42b ("media: uvcvideo: Allow custom control mapping")

---
Paul, could you check if this fixes your issue, thanks!
---
Changes in v2:
- Replace !(A && B) with (!A || !B)
- Add error message to commit message
- Link to v1: https://lore.kernel.org/r/[email protected]

---
  drivers/media/usb/uvc/uvc_ctrl.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +4 -0
index 0136df5732ba..4fe26e82e3d1 100644
@@ -2680,6 +2680,10 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
  	for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); ++i) {
  		const struct uvc_control_mapping *mapping = &uvc_ctrl_mappings[i];
 
+		if (!uvc_entity_match_guid(ctrl->entity, mapping->entity) ||
+		    ctrl->info.selector != mapping->selector)
+			continue;
+
  		/* Let the device provide a custom mapping. */
  		if (mapping->filter_mapping) {
  			mapping = mapping->filter_mapping(chain, ctrl);

drivers/media/usb/uvc/uvc_ctrl.c static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, · line 2696

Quoted 9 lines
drivers/media/usb/uvc/uvc_ctrl.c +1 -3
@@ -2687,9 +2691,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
  				continue;
  		}
 
-		if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
-		    ctrl->info.selector == mapping->selector)
-			__uvc_ctrl_add_mapping(chain, ctrl, mapping);
+		__uvc_ctrl_add_mapping(chain, ctrl, mapping);
  	}
  }

Kind regards,

Paul

maintainer Tested-by Paul Menzel Reviewed-by on v2 1/1
#2 lore raw
In reply to Ricardo Ribalda
Quoted 16 lines · Ricardo Ribalda

Custom control mapping introduced a bug, where the filter function was applied to every single control.

Fix it so it is only applied to the matching controls.

The following dmesg errors during probe are now fixed:

usb 1-5: Found UVC 1.00 device Integrated_Webcam_HD (0c45:670c) usb 1-5: Failed to query (GET_CUR) UVC control 2 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 3 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 6 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 7 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 8 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 9 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 10 on unit 2: -75 (exp. 1).

Quoted 5 lines
Fixes 8f4362a8d42b ("media: uvcvideo: Allow custom control mapping")

I'll add

from v1 and fix the reported-by tag.

Quoted 41 lines

---
Paul, could you check if this fixes your issue, thanks!
---
Changes in v2:
- Replace !(A && B) with (!A || !B)
- Add error message to commit message
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/media/usb/uvc/uvc_ctrl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +5 -4
index 0136df5732ba..4fe26e82e3d1 100644
@@ -2680,6 +2680,10 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); ++i) {
 		const struct uvc_control_mapping *mapping = &uvc_ctrl_mappings[i];
 
+		if (!uvc_entity_match_guid(ctrl->entity, mapping->entity) ||
+		    ctrl->info.selector != mapping->selector)
+			continue;
+
 		/* Let the device provide a custom mapping. */
 		if (mapping->filter_mapping) {
 			mapping = mapping->filter_mapping(chain, ctrl);
@@ -2687,9 +2691,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 				continue;
 		}
 
-		if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
-		    ctrl->info.selector == mapping->selector)
-			__uvc_ctrl_add_mapping(chain, ctrl, mapping);
+		__uvc_ctrl_add_mapping(chain, ctrl, mapping);
 	}
 }
 
 
---

base-commit: 68a72104cbcf38ad16500216e213fa4eb21c4be2
change-id: 20240722-fix-filter-mapping-18477dc69048

Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw
Quoted 24 lines · Laurent Pinchart
Quoted 16 lines · Ricardo Ribalda

Custom control mapping introduced a bug, where the filter function was applied to every single control.

Fix it so it is only applied to the matching controls.

The following dmesg errors during probe are now fixed:

usb 1-5: Found UVC 1.00 device Integrated_Webcam_HD (0c45:670c) usb 1-5: Failed to query (GET_CUR) UVC control 2 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 3 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 6 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 7 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 8 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 9 on unit 2: -75 (exp. 1). usb 1-5: Failed to query (GET_CUR) UVC control 10 on unit 2: -75 (exp. 1).

Quoted 5 lines
Fixes 8f4362a8d42b ("media: uvcvideo: Allow custom control mapping")
Quoted 8 lines

I'll add

from v1 and fix the reported-by tag.

Thanks :)

Quoted 46 lines
Quoted 39 lines

---
Paul, could you check if this fixes your issue, thanks!
---
Changes in v2:
- Replace !(A && B) with (!A || !B)
- Add error message to commit message
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/media/usb/uvc/uvc_ctrl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +5 -4
index 0136df5732ba..4fe26e82e3d1 100644
@@ -2680,6 +2680,10 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
      for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); ++i) {
              const struct uvc_control_mapping *mapping = &uvc_ctrl_mappings[i];
 
+             if (!uvc_entity_match_guid(ctrl->entity, mapping->entity) ||
+                 ctrl->info.selector != mapping->selector)
+                     continue;
+
              /* Let the device provide a custom mapping. */
              if (mapping->filter_mapping) {
                      mapping = mapping->filter_mapping(chain, ctrl);
@@ -2687,9 +2691,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
                              continue;
              }
 
-             if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
-                 ctrl->info.selector == mapping->selector)
-                     __uvc_ctrl_add_mapping(chain, ctrl, mapping);
+             __uvc_ctrl_add_mapping(chain, ctrl, mapping);
      }
 }
 
 
---
Quoted 2 lines

base-commit: 68a72104cbcf38ad16500216e213fa4eb21c4be2
change-id: 20240722-fix-filter-mapping-18477dc69048

--
Regards,

Laurent Pinchart

Signature · 1 line
Ricardo Ribalda