forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/media/usb/uvc/uvc_ctrl.c
....@@ -1,14 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * uvc_ctrl.c -- USB Video Class driver - Controls
34 *
45 * Copyright (C) 2005-2010
56 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
127 */
138
149 #include <linux/kernel.h>
....@@ -38,7 +33,7 @@
3833 * Controls
3934 */
4035
41
-static struct uvc_control_info uvc_ctrls[] = {
36
+static const struct uvc_control_info uvc_ctrls[] = {
4237 {
4338 .entity = UVC_GUID_UVC_PROCESSING,
4439 .selector = UVC_PU_BRIGHTNESS_CONTROL,
....@@ -354,13 +349,13 @@
354349 },
355350 };
356351
357
-static struct uvc_menu_info power_line_frequency_controls[] = {
352
+static const struct uvc_menu_info power_line_frequency_controls[] = {
358353 { 0, "Disabled" },
359354 { 1, "50 Hz" },
360355 { 2, "60 Hz" },
361356 };
362357
363
-static struct uvc_menu_info exposure_auto_controls[] = {
358
+static const struct uvc_menu_info exposure_auto_controls[] = {
364359 { 2, "Auto Mode" },
365360 { 1, "Manual Mode" },
366361 { 4, "Shutter Priority Mode" },
....@@ -421,7 +416,7 @@
421416 data[first+1] = min_t(int, abs(value), 0xff);
422417 }
423418
424
-static struct uvc_control_mapping uvc_ctrl_mappings[] = {
419
+static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
425420 {
426421 .id = V4L2_CID_BRIGHTNESS,
427422 .name = "Brightness",
....@@ -982,7 +977,7 @@
982977 s32 value = mapping->get(mapping, UVC_GET_CUR, data);
983978
984979 if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
985
- struct uvc_menu_info *menu = mapping->menu_info;
980
+ const struct uvc_menu_info *menu = mapping->menu_info;
986981 unsigned int i;
987982
988983 for (i = 0; i < mapping->menu_count; ++i, ++menu) {
....@@ -1029,13 +1024,13 @@
10291024 {
10301025 struct uvc_control_mapping *master_map = NULL;
10311026 struct uvc_control *master_ctrl = NULL;
1032
- struct uvc_menu_info *menu;
1027
+ const struct uvc_menu_info *menu;
10331028 unsigned int i;
10341029
10351030 memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl));
10361031 v4l2_ctrl->id = mapping->id;
10371032 v4l2_ctrl->type = mapping->v4l2_type;
1038
- strlcpy(v4l2_ctrl->name, mapping->name, sizeof(v4l2_ctrl->name));
1033
+ strscpy(v4l2_ctrl->name, mapping->name, sizeof(v4l2_ctrl->name));
10391034 v4l2_ctrl->flags = 0;
10401035
10411036 if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR))
....@@ -1149,7 +1144,7 @@
11491144 int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
11501145 struct v4l2_querymenu *query_menu)
11511146 {
1152
- struct uvc_menu_info *menu_info;
1147
+ const struct uvc_menu_info *menu_info;
11531148 struct uvc_control_mapping *mapping;
11541149 struct uvc_control *ctrl;
11551150 u32 index = query_menu->index;
....@@ -1195,7 +1190,7 @@
11951190 }
11961191 }
11971192
1198
- strlcpy(query_menu->name, menu_info->name, sizeof(query_menu->name));
1193
+ strscpy(query_menu->name, menu_info->name, sizeof(query_menu->name));
11991194
12001195 done:
12011196 mutex_unlock(&chain->ctrl_mutex);
....@@ -2025,18 +2020,14 @@
20252020 static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl,
20262021 const struct uvc_control_info *info)
20272022 {
2028
- int ret = 0;
2029
-
20302023 ctrl->info = *info;
20312024 INIT_LIST_HEAD(&ctrl->info.mappings);
20322025
20332026 /* Allocate an array to save control values (cur, def, max, etc.) */
20342027 ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1,
20352028 GFP_KERNEL);
2036
- if (ctrl->uvc_data == NULL) {
2037
- ret = -ENOMEM;
2038
- goto done;
2039
- }
2029
+ if (!ctrl->uvc_data)
2030
+ return -ENOMEM;
20402031
20412032 ctrl->initialized = 1;
20422033
....@@ -2044,10 +2035,7 @@
20442035 "entity %u\n", ctrl->info.entity, ctrl->info.selector,
20452036 dev->udev->devpath, ctrl->entity->id);
20462037
2047
-done:
2048
- if (ret < 0)
2049
- kfree(ctrl->uvc_data);
2050
- return ret;
2038
+ return 0;
20512039 }
20522040
20532041 /*