Skip to content

Commit 0f5a24c

Browse files
Manoj ChourasiaJiri Kosina
authored andcommitted
HID: hidraw: close underlying device at removal of last reader
Even though device exist bit is set the underlying HW device should be closed when the last reader of the device is closed i.e. open count drops to zero. Signed-off-by: Manoj Chourasia <[email protected]> Reported-by: [email protected] Tested-by: [email protected] Signed-off-by: Jiri Kosina <[email protected]>
1 parent 550dbf4 commit 0f5a24c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/hid/hidraw.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,25 @@ static int hidraw_fasync(int fd, struct file *file, int on)
308308
static void drop_ref(struct hidraw *hidraw, int exists_bit)
309309
{
310310
if (exists_bit) {
311-
hid_hw_close(hidraw->hid);
312311
hidraw->exist = 0;
313-
if (hidraw->open)
312+
if (hidraw->open) {
313+
hid_hw_close(hidraw->hid);
314314
wake_up_interruptible(&hidraw->wait);
315+
}
315316
} else {
316317
--hidraw->open;
317318
}
318-
319-
if (!hidraw->open && !hidraw->exist) {
320-
device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
321-
hidraw_table[hidraw->minor] = NULL;
322-
kfree(hidraw);
319+
if (!hidraw->open) {
320+
if (!hidraw->exist) {
321+
device_destroy(hidraw_class,
322+
MKDEV(hidraw_major, hidraw->minor));
323+
hidraw_table[hidraw->minor] = NULL;
324+
kfree(hidraw);
325+
} else {
326+
/* close device for last reader */
327+
hid_hw_power(hidraw->hid, PM_HINT_NORMAL);
328+
hid_hw_close(hidraw->hid);
329+
}
323330
}
324331
}
325332

0 commit comments

Comments
 (0)