| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * HID raw devices, giving access to raw HID events. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 9 | 10 | * Copyright (c) 2007-2014 Jiri Kosina |
|---|
| 10 | 11 | */ |
|---|
| 11 | 12 | |
|---|
| 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 | | - */ |
|---|
| 21 | 13 | |
|---|
| 22 | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 23 | 15 | |
|---|
| .. | .. |
|---|
| 107 | 99 | |
|---|
| 108 | 100 | /* |
|---|
| 109 | 101 | * 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. |
|---|
| 112 | 102 | */ |
|---|
| 113 | 103 | static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, size_t count, unsigned char report_type) |
|---|
| 114 | 104 | { |
|---|
| .. | .. |
|---|
| 116 | 106 | struct hid_device *dev; |
|---|
| 117 | 107 | __u8 *buf; |
|---|
| 118 | 108 | int ret = 0; |
|---|
| 109 | + |
|---|
| 110 | + lockdep_assert_held(&minors_lock); |
|---|
| 119 | 111 | |
|---|
| 120 | 112 | if (!hidraw_table[minor] || !hidraw_table[minor]->exist) { |
|---|
| 121 | 113 | ret = -ENODEV; |
|---|
| .. | .. |
|---|
| 181 | 173 | * of buffer is the report number to request, or 0x0 if the defice does not |
|---|
| 182 | 174 | * use numbered reports. The report_type parameter can be HID_FEATURE_REPORT |
|---|
| 183 | 175 | * or HID_INPUT_REPORT. |
|---|
| 184 | | - * |
|---|
| 185 | | - * This function is to be called with the minors_lock mutex held. |
|---|
| 186 | 176 | */ |
|---|
| 187 | 177 | static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t count, unsigned char report_type) |
|---|
| 188 | 178 | { |
|---|
| .. | .. |
|---|
| 191 | 181 | __u8 *buf; |
|---|
| 192 | 182 | int ret = 0, len; |
|---|
| 193 | 183 | unsigned char report_number; |
|---|
| 184 | + |
|---|
| 185 | + lockdep_assert_held(&minors_lock); |
|---|
| 194 | 186 | |
|---|
| 195 | 187 | if (!hidraw_table[minor] || !hidraw_table[minor]->exist) { |
|---|
| 196 | 188 | ret = -ENODEV; |
|---|
| .. | .. |
|---|
| 205 | 197 | } |
|---|
| 206 | 198 | |
|---|
| 207 | 199 | 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)); |
|---|
| 210 | 202 | ret = -EINVAL; |
|---|
| 211 | 203 | goto out; |
|---|
| 212 | 204 | } |
|---|
| 213 | 205 | |
|---|
| 214 | 206 | 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)); |
|---|
| 217 | 209 | ret = -EINVAL; |
|---|
| 218 | 210 | goto out; |
|---|
| 219 | 211 | } |
|---|
| .. | .. |
|---|
| 354 | 346 | unsigned int minor = iminor(inode); |
|---|
| 355 | 347 | struct hidraw_list *list = file->private_data; |
|---|
| 356 | 348 | unsigned long flags; |
|---|
| 349 | + int i; |
|---|
| 357 | 350 | |
|---|
| 358 | 351 | mutex_lock(&minors_lock); |
|---|
| 359 | 352 | |
|---|
| 360 | 353 | spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags); |
|---|
| 354 | + for (i = list->tail; i < list->head; i++) |
|---|
| 355 | + kfree(list->buffer[i].value); |
|---|
| 361 | 356 | list_del(&list->node); |
|---|
| 362 | 357 | spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags); |
|---|
| 363 | 358 | kfree(list); |
|---|
| .. | .. |
|---|
| 459 | 454 | -EFAULT : len; |
|---|
| 460 | 455 | break; |
|---|
| 461 | 456 | } |
|---|
| 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 | + } |
|---|
| 462 | 466 | } |
|---|
| 463 | 467 | |
|---|
| 464 | 468 | ret = -ENOTTY; |
|---|
| .. | .. |
|---|
| 477 | 481 | .release = hidraw_release, |
|---|
| 478 | 482 | .unlocked_ioctl = hidraw_ioctl, |
|---|
| 479 | 483 | .fasync = hidraw_fasync, |
|---|
| 480 | | -#ifdef CONFIG_COMPAT |
|---|
| 481 | | - .compat_ioctl = hidraw_ioctl, |
|---|
| 482 | | -#endif |
|---|
| 484 | + .compat_ioctl = compat_ptr_ioctl, |
|---|
| 483 | 485 | .llseek = noop_llseek, |
|---|
| 484 | 486 | }; |
|---|
| 485 | 487 | |
|---|
| .. | .. |
|---|
| 606 | 608 | if (result < 0) |
|---|
| 607 | 609 | goto error_class; |
|---|
| 608 | 610 | |
|---|
| 609 | | - printk(KERN_INFO "hidraw: raw HID events driver (C) Jiri Kosina\n"); |
|---|
| 611 | + pr_info("raw HID events driver (C) Jiri Kosina\n"); |
|---|
| 610 | 612 | out: |
|---|
| 611 | 613 | return result; |
|---|
| 612 | 614 | |
|---|