]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
media: uvcvideo: Refactor uvc_ctrl_mappings_uvcXX
authorRicardo Ribalda <ribalda@chromium.org>
Thu, 5 Jan 2023 13:52:55 +0000 (14:52 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:33:30 +0000 (09:33 +0100)
[ Upstream commit 96a160b068e09b4ed5a32e2179e5219fc3545eca ]

Convert the array of structs into an array of pointers, that way the
mappings can be reused.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Stable-dep-of: 3aa8628eb78a ("media: uvcvideo: Refactor power_line_frequency_controls_limited")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/usb/uvc/uvc_ctrl.c

index 32c182987d52c49a6fdacf31c19df004e1d64b36..3c46c33b9e571be175a9f72be27430a1668bd6f0 100644 (file)
@@ -723,34 +723,40 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
        },
 };
 
-static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = {
-       {
-               .id             = V4L2_CID_POWER_LINE_FREQUENCY,
-               .entity         = UVC_GUID_UVC_PROCESSING,
-               .selector       = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
-               .size           = 2,
-               .offset         = 0,
-               .v4l2_type      = V4L2_CTRL_TYPE_MENU,
-               .data_type      = UVC_CTRL_DATA_TYPE_ENUM,
-               .menu_info      = power_line_frequency_controls,
-               .menu_mask      = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
-                                         V4L2_CID_POWER_LINE_FREQUENCY_DISABLED),
-       },
+static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = {
+       .id             = V4L2_CID_POWER_LINE_FREQUENCY,
+       .entity         = UVC_GUID_UVC_PROCESSING,
+       .selector       = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
+       .size           = 2,
+       .offset         = 0,
+       .v4l2_type      = V4L2_CTRL_TYPE_MENU,
+       .data_type      = UVC_CTRL_DATA_TYPE_ENUM,
+       .menu_info      = power_line_frequency_controls,
+       .menu_mask      = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
+                                 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED),
 };
 
-static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = {
-       {
-               .id             = V4L2_CID_POWER_LINE_FREQUENCY,
-               .entity         = UVC_GUID_UVC_PROCESSING,
-               .selector       = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
-               .size           = 2,
-               .offset         = 0,
-               .v4l2_type      = V4L2_CTRL_TYPE_MENU,
-               .data_type      = UVC_CTRL_DATA_TYPE_ENUM,
-               .menu_info      = power_line_frequency_controls,
-               .menu_mask      = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO,
-                                         V4L2_CID_POWER_LINE_FREQUENCY_DISABLED),
-       },
+static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = {
+       &uvc_ctrl_power_line_mapping_uvc11,
+       NULL, /* Sentinel */
+};
+
+static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = {
+       .id             = V4L2_CID_POWER_LINE_FREQUENCY,
+       .entity         = UVC_GUID_UVC_PROCESSING,
+       .selector       = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
+       .size           = 2,
+       .offset         = 0,
+       .v4l2_type      = V4L2_CTRL_TYPE_MENU,
+       .data_type      = UVC_CTRL_DATA_TYPE_ENUM,
+       .menu_info      = power_line_frequency_controls,
+       .menu_mask      = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO,
+                                 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED),
+};
+
+static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = {
+       &uvc_ctrl_power_line_mapping_uvc15,
+       NULL, /* Sentinel */
 };
 
 /* ------------------------------------------------------------------------
@@ -2474,8 +2480,7 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev,
 static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
                               struct uvc_control *ctrl)
 {
-       const struct uvc_control_mapping *mappings;
-       unsigned int num_mappings;
+       const struct uvc_control_mapping **mappings;
        unsigned int i;
 
        /*
@@ -2542,16 +2547,11 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
        }
 
        /* Finally process version-specific mappings. */
-       if (chain->dev->uvc_version < 0x0150) {
-               mappings = uvc_ctrl_mappings_uvc11;
-               num_mappings = ARRAY_SIZE(uvc_ctrl_mappings_uvc11);
-       } else {
-               mappings = uvc_ctrl_mappings_uvc15;
-               num_mappings = ARRAY_SIZE(uvc_ctrl_mappings_uvc15);
-       }
+       mappings = chain->dev->uvc_version < 0x0150
+                ? uvc_ctrl_mappings_uvc11 : uvc_ctrl_mappings_uvc15;
 
-       for (i = 0; i < num_mappings; ++i) {
-               const struct uvc_control_mapping *mapping = &mappings[i];
+       for (i = 0; mappings[i]; ++i) {
+               const struct uvc_control_mapping *mapping = mappings[i];
 
                if (uvc_entity_match_guid(ctrl->entity, mapping->entity) &&
                    ctrl->info.selector == mapping->selector)