Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f5a24c6 authored by Manoj Chourasia's avatar Manoj Chourasia Committed by Jiri Kosina
Browse files

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: default avatarManoj Chourasia <mchourasia@nvidia.com>
Reported-by: default avatar <mika.westerberg@linux.intel.com>
Tested-by: default avatar <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 550dbf47
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -308,18 +308,25 @@ static int hidraw_fasync(int fd, struct file *file, int on)
static void drop_ref(struct hidraw *hidraw, int exists_bit)
{
	if (exists_bit) {
		hid_hw_close(hidraw->hid);
		hidraw->exist = 0;
		if (hidraw->open)
		if (hidraw->open) {
			hid_hw_close(hidraw->hid);
			wake_up_interruptible(&hidraw->wait);
		}
	} else {
		--hidraw->open;
	}

	if (!hidraw->open && !hidraw->exist) {
		device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
	if (!hidraw->open) {
		if (!hidraw->exist) {
			device_destroy(hidraw_class,
					MKDEV(hidraw_major, hidraw->minor));
			hidraw_table[hidraw->minor] = NULL;
			kfree(hidraw);
		} else {
			/* close device for last reader */
			hid_hw_power(hidraw->hid, PM_HINT_NORMAL);
			hid_hw_close(hidraw->hid);
		}
	}
}