hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/hid/hidraw.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * HID raw devices, giving access to raw HID events.
34 *
....@@ -9,15 +10,6 @@
910 * Copyright (c) 2007-2014 Jiri Kosina
1011 */
1112
12
-/*
13
- * This program is free software; you can redistribute it and/or modify it
14
- * under the terms and conditions of the GNU General Public License,
15
- * version 2, as published by the Free Software Foundation.
16
- *
17
- * You should have received a copy of the GNU General Public License along with
18
- * this program; if not, write to the Free Software Foundation, Inc.,
19
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20
- */
2113
2214 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2315
....@@ -107,8 +99,6 @@
10799
108100 /*
109101 * The first byte of the report buffer is expected to be a report number.
110
- *
111
- * This function is to be called with the minors_lock mutex held.
112102 */
113103 static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, size_t count, unsigned char report_type)
114104 {
....@@ -116,6 +106,8 @@
116106 struct hid_device *dev;
117107 __u8 *buf;
118108 int ret = 0;
109
+
110
+ lockdep_assert_held(&minors_lock);
119111
120112 if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
121113 ret = -ENODEV;
....@@ -181,8 +173,6 @@
181173 * of buffer is the report number to request, or 0x0 if the defice does not
182174 * use numbered reports. The report_type parameter can be HID_FEATURE_REPORT
183175 * or HID_INPUT_REPORT.
184
- *
185
- * This function is to be called with the minors_lock mutex held.
186176 */
187177 static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t count, unsigned char report_type)
188178 {
....@@ -191,6 +181,8 @@
191181 __u8 *buf;
192182 int ret = 0, len;
193183 unsigned char report_number;
184
+
185
+ lockdep_assert_held(&minors_lock);
194186
195187 if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
196188 ret = -ENODEV;
....@@ -205,15 +197,15 @@
205197 }
206198
207199 if (count > HID_MAX_BUFFER_SIZE) {
208
- printk(KERN_WARNING "hidraw: pid %d passed too large report\n",
209
- task_pid_nr(current));
200
+ hid_warn(dev, "pid %d passed too large report\n",
201
+ task_pid_nr(current));
210202 ret = -EINVAL;
211203 goto out;
212204 }
213205
214206 if (count < 2) {
215
- printk(KERN_WARNING "hidraw: pid %d passed too short report\n",
216
- task_pid_nr(current));
207
+ hid_warn(dev, "pid %d passed too short report\n",
208
+ task_pid_nr(current));
217209 ret = -EINVAL;
218210 goto out;
219211 }
....@@ -354,10 +346,13 @@
354346 unsigned int minor = iminor(inode);
355347 struct hidraw_list *list = file->private_data;
356348 unsigned long flags;
349
+ int i;
357350
358351 mutex_lock(&minors_lock);
359352
360353 spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
354
+ for (i = list->tail; i < list->head; i++)
355
+ kfree(list->buffer[i].value);
361356 list_del(&list->node);
362357 spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
363358 kfree(list);
....@@ -459,6 +454,15 @@
459454 -EFAULT : len;
460455 break;
461456 }
457
+
458
+ if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWUNIQ(0))) {
459
+ int len = strlen(hid->uniq) + 1;
460
+ if (len > _IOC_SIZE(cmd))
461
+ len = _IOC_SIZE(cmd);
462
+ ret = copy_to_user(user_arg, hid->uniq, len) ?
463
+ -EFAULT : len;
464
+ break;
465
+ }
462466 }
463467
464468 ret = -ENOTTY;
....@@ -477,9 +481,7 @@
477481 .release = hidraw_release,
478482 .unlocked_ioctl = hidraw_ioctl,
479483 .fasync = hidraw_fasync,
480
-#ifdef CONFIG_COMPAT
481
- .compat_ioctl = hidraw_ioctl,
482
-#endif
484
+ .compat_ioctl = compat_ptr_ioctl,
483485 .llseek = noop_llseek,
484486 };
485487
....@@ -606,7 +608,7 @@
606608 if (result < 0)
607609 goto error_class;
608610
609
- printk(KERN_INFO "hidraw: raw HID events driver (C) Jiri Kosina\n");
611
+ pr_info("raw HID events driver (C) Jiri Kosina\n");
610612 out:
611613 return result;
612614