summaryrefslogtreecommitdiff
path: root/drivers/hid/usbhid/hiddev.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2019-08-21 14:35:16 +0300
committerLinus Walleij <linus.walleij@linaro.org>2019-08-21 14:35:16 +0300
commit880e4f93f94677dff02f795352ed4f069ee046b7 (patch)
tree339be7ef0256eb6586180f014a8bd8f2f3e7fa72 /drivers/hid/usbhid/hiddev.c
parent19d17d935b29f30510874fd34e93357eea0daba2 (diff)
parentd1abaeb3be7b5fa6d7a1fbbd2e14e3310005c4c1 (diff)
downloadlinux-880e4f93f94677dff02f795352ed4f069ee046b7.tar.xz
Merge tag 'v5.3-rc5' into devel
Linux 5.3-rc5
Diffstat (limited to 'drivers/hid/usbhid/hiddev.c')
-rw-r--r--drivers/hid/usbhid/hiddev.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 55b72573066b..4e11cc6fc34b 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -284,6 +284,14 @@ static int hiddev_open(struct inode *inode, struct file *file)
spin_unlock_irq(&list->hiddev->list_lock);
mutex_lock(&hiddev->existancelock);
+ /*
+ * recheck exist with existance lock held to
+ * avoid opening a disconnected device
+ */
+ if (!list->hiddev->exist) {
+ res = -ENODEV;
+ goto bail_unlock;
+ }
if (!list->hiddev->open++)
if (list->hiddev->exist) {
struct hid_device *hid = hiddev->hid;
@@ -300,6 +308,10 @@ bail_normal_power:
hid_hw_power(hid, PM_HINT_NORMAL);
bail_unlock:
mutex_unlock(&hiddev->existancelock);
+
+ spin_lock_irq(&list->hiddev->list_lock);
+ list_del(&list->node);
+ spin_unlock_irq(&list->hiddev->list_lock);
bail:
file->private_data = NULL;
vfree(list);