[PATCH] HID: hidraw: close underlying device at removal of last re=

From: Manoj Chourasia
Date: Tue Oct 01 2013 - 06:09:00 EST


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 <mchourasia@xxxxxxxxxx>
---
drivers/hid/hidraw.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index dbfe300..3c0dd44 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -305,19 +305,28 @@ static int hidraw_fasync(int fd, struct file *file, i=
nt on)
static void drop_ref(struct hidraw *hidraw, int exists_bit)
{
if (exists_bit) {
- hid_hw_close(hidraw->hid);
hidraw->exist =3D 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->mi=
nor));
- hidraw_table[hidraw->minor] =3D NULL;
- kfree(hidraw);
+ if (!hidraw->open) {
+ if (!hidraw->exist) {
+ device_destroy(hidraw_class,
+ MKDEV(hidraw_major, hidraw->minor));
+ hidraw_table[hidraw->minor] =3D NULL;
+ kfree(hidraw);
+ } else {
+ /* close device for last reader */
+ hid_hw_power(hidraw->hid, PM_HINT_NORMAL);
+ hid_hw_close(hidraw->hid);
+ }
}
+
}

static int hidraw_release(struct inode * inode, struct file * file)
--
1.7.9.5


-Regards
Manoj


--_002_F1F6C959961EA744BBD5B8EEF8B8FEA16DDD19DD43BGMAIL02nvidi_
Content-Type: application/octet-stream;
name="PATCH-hidraw-close-underlying-device-at-removal-of-las.patch"
Content-Description: PATCH-hidraw-close-underlying-device-at-removal-of-las.patch
Content-Disposition: attachment;
modification-date="Tue, 01 Oct 2013 13:27:13 GMT"; creation-date="Tue, 01 Oct 2013 13:26:34 GMT";
size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0KIAogc3RhdGljIGludCBoaWRyYXdfcmVsZWFzZShzdHJ1Y3QgaW5v
ZGUgKiBpbm9kZSwgc3RydWN0IGZpbGUgKiBmaWxlKQotLSAKMS43LjkuNQoK

--_002_F1F6C959961EA744BBD5B8EEF8B8FEA16DDD19DD43BGMAIL02nvidi_--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/