Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753286Ab3JANf6 (ORCPT ); Tue, 1 Oct 2013 09:35:58 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:7206 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752718Ab3JANf5 (ORCPT ); Tue, 1 Oct 2013 09:35:57 -0400 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Tue, 01 Oct 2013 06:35:57 -0700 From: Manoj Chourasia To: "jkosina@suse.cz" , "Mika Westerberg (mika.westerberg@linux.intel.com)" CC: "linux-kernel@vger.kernel.org" Date: Tue, 1 Oct 2013 19:05:56 +0530 Subject: FW: [PATCH] hidraw: close underlying device at removal of last reader Thread-Topic: [PATCH] hidraw: close underlying device at removal of last reader Thread-Index: Ac6+qppQHC4L5S3uS5u9ddG6R22DJAAACmqQ Message-ID: Accept-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Content-Language: en-US Content-Type: multipart/mixed; boundary="_002_F1F6C959961EA744BBD5B8EEF8B8FEA16DDD19DD43BGMAIL02nvidi_" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5671 Lines: 127 --_002_F1F6C959961EA744BBD5B8EEF8B8FEA16DDD19DD43BGMAIL02nvidi_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Jiri, Mika Westerberg mika.westerberg@linux.intel.com reported a bug introduced i= n hid driver after=20 commit 212a871a393 (HID: hidraw: correctly deallocate memory on device disc= onnect)=20 that hidraw doesn't close the underlying hid device when the device node is= closed last time. I am proposing following patch as fix. =A0Please review it. =A0Mika will he= lp in testing. ---------------------------------------- >From b37519b65be0d51b90c5fc177c0dc0cd2f6358b1 Mon Sep 17 00:00:00 2001 From: Manoj Chourasia Date: Tue, 1 Oct 2013 15:39:00 +0530 Subject: [PATCH] HID: hidraw: close underlying device at removal of last re= ader 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 --- 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=1641; filename="PATCH-hidraw-close-underlying-device-at-removal-of-las.patch" Content-Transfer-Encoding: base64 RnJvbSBiMzc1MTliNjViZTBkNTFiOTBjNWZjMTc3YzBkYzBjZDJmNjM1OGI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FEA16DDD19DD43BGMAIL02nvidi_-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/