forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/media/usb/uvc/uvc_ctrl.c
....@@ -1,16 +1,12 @@
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
9
+#include <asm/barrier.h>
1410 #include <linux/kernel.h>
1511 #include <linux/list.h>
1612 #include <linux/module.h>
....@@ -38,7 +34,7 @@
3834 * Controls
3935 */
4036
41
-static struct uvc_control_info uvc_ctrls[] = {
37
+static const struct uvc_control_info uvc_ctrls[] = {
4238 {
4339 .entity = UVC_GUID_UVC_PROCESSING,
4440 .selector = UVC_PU_BRIGHTNESS_CONTROL,
....@@ -354,13 +350,13 @@
354350 },
355351 };
356352
357
-static struct uvc_menu_info power_line_frequency_controls[] = {
353
+static const struct uvc_menu_info power_line_frequency_controls[] = {
358354 { 0, "Disabled" },
359355 { 1, "50 Hz" },
360356 { 2, "60 Hz" },
361357 };
362358
363
-static struct uvc_menu_info exposure_auto_controls[] = {
359
+static const struct uvc_menu_info exposure_auto_controls[] = {
364360 { 2, "Auto Mode" },
365361 { 1, "Manual Mode" },
366362 { 4, "Shutter Priority Mode" },
....@@ -421,7 +417,7 @@
421417 data[first+1] = min_t(int, abs(value), 0xff);
422418 }
423419
424
-static struct uvc_control_mapping uvc_ctrl_mappings[] = {
420
+static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
425421 {
426422 .id = V4L2_CID_BRIGHTNESS,
427423 .name = "Brightness",
....@@ -982,7 +978,7 @@
982978 s32 value = mapping->get(mapping, UVC_GET_CUR, data);
983979
984980 if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
985
- struct uvc_menu_info *menu = mapping->menu_info;
981
+ const struct uvc_menu_info *menu = mapping->menu_info;
986982 unsigned int i;
987983
988984 for (i = 0; i < mapping->menu_count; ++i, ++menu) {
....@@ -1029,13 +1025,13 @@
10291025 {
10301026 struct uvc_control_mapping *master_map = NULL;
10311027 struct uvc_control *master_ctrl = NULL;
1032
- struct uvc_menu_info *menu;
1028
+ const struct uvc_menu_info *menu;
10331029 unsigned int i;
10341030
10351031 memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl));
10361032 v4l2_ctrl->id = mapping->id;
10371033 v4l2_ctrl->type = mapping->v4l2_type;
1038
- strlcpy(v4l2_ctrl->name, mapping->name, sizeof(v4l2_ctrl->name));
1034
+ strscpy(v4l2_ctrl->name, mapping->name, sizeof(v4l2_ctrl->name));
10391035 v4l2_ctrl->flags = 0;
10401036
10411037 if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR))
....@@ -1149,7 +1145,7 @@
11491145 int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
11501146 struct v4l2_querymenu *query_menu)
11511147 {
1152
- struct uvc_menu_info *menu_info;
1148
+ const struct uvc_menu_info *menu_info;
11531149 struct uvc_control_mapping *mapping;
11541150 struct uvc_control *ctrl;
11551151 u32 index = query_menu->index;
....@@ -1195,7 +1191,7 @@
11951191 }
11961192 }
11971193
1198
- strlcpy(query_menu->name, menu_info->name, sizeof(query_menu->name));
1194
+ strscpy(query_menu->name, menu_info->name, sizeof(query_menu->name));
11991195
12001196 done:
12011197 mutex_unlock(&chain->ctrl_mutex);
....@@ -1280,17 +1276,12 @@
12801276 uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes);
12811277 }
12821278
1283
-static void uvc_ctrl_status_event_work(struct work_struct *work)
1279
+void uvc_ctrl_status_event(struct uvc_video_chain *chain,
1280
+ struct uvc_control *ctrl, const u8 *data)
12841281 {
1285
- struct uvc_device *dev = container_of(work, struct uvc_device,
1286
- async_ctrl.work);
1287
- struct uvc_ctrl_work *w = &dev->async_ctrl;
1288
- struct uvc_video_chain *chain = w->chain;
12891282 struct uvc_control_mapping *mapping;
1290
- struct uvc_control *ctrl = w->ctrl;
12911283 struct uvc_fh *handle;
12921284 unsigned int i;
1293
- int ret;
12941285
12951286 mutex_lock(&chain->ctrl_mutex);
12961287
....@@ -1298,7 +1289,7 @@
12981289 ctrl->handle = NULL;
12991290
13001291 list_for_each_entry(mapping, &ctrl->info.mappings, list) {
1301
- s32 value = __uvc_ctrl_get_value(mapping, w->data);
1292
+ s32 value = __uvc_ctrl_get_value(mapping, data);
13021293
13031294 /*
13041295 * handle may be NULL here if the device sends auto-update
....@@ -1317,6 +1308,20 @@
13171308 }
13181309
13191310 mutex_unlock(&chain->ctrl_mutex);
1311
+}
1312
+
1313
+static void uvc_ctrl_status_event_work(struct work_struct *work)
1314
+{
1315
+ struct uvc_device *dev = container_of(work, struct uvc_device,
1316
+ async_ctrl.work);
1317
+ struct uvc_ctrl_work *w = &dev->async_ctrl;
1318
+ int ret;
1319
+
1320
+ uvc_ctrl_status_event(w->chain, w->ctrl, w->data);
1321
+
1322
+ /* The barrier is needed to synchronize with uvc_status_stop(). */
1323
+ if (smp_load_acquire(&dev->flush_status))
1324
+ return;
13201325
13211326 /* Resubmit the URB. */
13221327 w->urb->interval = dev->int_ep->desc.bInterval;
....@@ -1326,8 +1331,8 @@
13261331 ret);
13271332 }
13281333
1329
-bool uvc_ctrl_status_event(struct urb *urb, struct uvc_video_chain *chain,
1330
- struct uvc_control *ctrl, const u8 *data)
1334
+bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain,
1335
+ struct uvc_control *ctrl, const u8 *data)
13311336 {
13321337 struct uvc_device *dev = chain->dev;
13331338 struct uvc_ctrl_work *w = &dev->async_ctrl;
....@@ -2025,18 +2030,14 @@
20252030 static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl,
20262031 const struct uvc_control_info *info)
20272032 {
2028
- int ret = 0;
2029
-
20302033 ctrl->info = *info;
20312034 INIT_LIST_HEAD(&ctrl->info.mappings);
20322035
20332036 /* Allocate an array to save control values (cur, def, max, etc.) */
20342037 ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1,
20352038 GFP_KERNEL);
2036
- if (ctrl->uvc_data == NULL) {
2037
- ret = -ENOMEM;
2038
- goto done;
2039
- }
2039
+ if (!ctrl->uvc_data)
2040
+ return -ENOMEM;
20402041
20412042 ctrl->initialized = 1;
20422043
....@@ -2044,10 +2045,7 @@
20442045 "entity %u\n", ctrl->info.entity, ctrl->info.selector,
20452046 dev->udev->devpath, ctrl->entity->id);
20462047
2047
-done:
2048
- if (ret < 0)
2049
- kfree(ctrl->uvc_data);
2050
- return ret;
2048
+ return 0;
20512049 }
20522050
20532051 /*