Skip to content

Commit 7961df1

Browse files
Alan-CoxJiri Kosina
authored andcommitted
HID: Switch hiddev to unlocked_ioctl
Push down the BKL. In some cases compat_ioctl already doesn't take the BKL so we don't either. Some of the locking here seems already dubious and object lifetimes want documenting Signed-off-by: Alan Cox <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 6f0168d commit 7961df1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/hid/usbhid/hiddev.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd,
406406
uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL);
407407
if (!uref_multi)
408408
return -ENOMEM;
409+
lock_kernel();
409410
uref = &uref_multi->uref;
410411
if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
411412
if (copy_from_user(uref_multi, user_arg,
@@ -501,12 +502,15 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd,
501502
}
502503

503504
goodreturn:
505+
unlock_kernel();
504506
kfree(uref_multi);
505507
return 0;
506508
fault:
509+
unlock_kernel();
507510
kfree(uref_multi);
508511
return -EFAULT;
509512
inval:
513+
unlock_kernel();
510514
kfree(uref_multi);
511515
return -EINVAL;
512516
}
@@ -540,7 +544,7 @@ static noinline int hiddev_ioctl_string(struct hiddev *hiddev, unsigned int cmd,
540544
return len;
541545
}
542546

543-
static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
547+
static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
544548
{
545549
struct hiddev_list *list = file->private_data;
546550
struct hiddev *hiddev = list->hiddev;
@@ -555,7 +559,10 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
555559
struct usbhid_device *usbhid = hid->driver_data;
556560
void __user *user_arg = (void __user *)arg;
557561
int i;
562+
563+
/* Called without BKL by compat methods so no BKL taken */
558564

565+
/* FIXME: Who or what stop this racing with a disconnect ?? */
559566
if (!hiddev->exist)
560567
return -EIO;
561568

@@ -768,7 +775,7 @@ static const struct file_operations hiddev_fops = {
768775
.poll = hiddev_poll,
769776
.open = hiddev_open,
770777
.release = hiddev_release,
771-
.ioctl = hiddev_ioctl,
778+
.unlocked_ioctl = hiddev_ioctl,
772779
.fasync = hiddev_fasync,
773780
#ifdef CONFIG_COMPAT
774781
.compat_ioctl = hiddev_compat_ioctl,

0 commit comments

Comments
 (0)