[PATCH] HID: hid-core: Don't fail to remove a device on a signal

Subsystems: hid core layer, the rest

STALE1929d

2 messages, 1 author, 2021-05-16 · open the first message on its own page

[PATCH] HID: hid-core: Don't fail to remove a device on a signal

From: Uwe Kleine-König <hidden>
Date: 2021-05-05 20:53:33

The driver core ignores the return code of a remove function and
considers a device unbound unconditionally after .remove() returns. So
don't sleep interruptible while waiting on the mutex, as there is no
sane way to handle an interrupt. Just returning -EINTR as was done up to
now results in leaking resources because the hid driver's remove
callback (or hid_hw_stop()) isn't called.

Fixes: 4ea5454203d9 ("HID: Fix race condition between driver core and ll-driver")
Signed-off-by: Uwe Kleine-König <redacted>
---
 drivers/hid/hid-core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 0ae9f6df59d1..4095a4db623d 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2303,12 +2303,9 @@ static int hid_device_remove(struct device *dev)
 {
 	struct hid_device *hdev = to_hid_device(dev);
 	struct hid_driver *hdrv;
-	int ret = 0;
 
-	if (down_interruptible(&hdev->driver_input_lock)) {
-		ret = -EINTR;
-		goto end;
-	}
+	down(&hdev->driver_input_lock);
+
 	hdev->io_started = false;
 
 	hdrv = hdev->driver;
@@ -2323,8 +2320,8 @@ static int hid_device_remove(struct device *dev)
 
 	if (!hdev->io_started)
 		up(&hdev->driver_input_lock);
-end:
-	return ret;
+
+	return 0;
 }
 
 static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
-- 
2.30.2

Re: [PATCH] HID: hid-core: Don't fail to remove a device on a signal

From: Uwe Kleine-König <hidden>
Date: 2021-05-16 20:06:10

Hello,

On Wed, May 05, 2021 at 10:53:19PM +0200, Uwe Kleine-König wrote:
quoted hunk
The driver core ignores the return code of a remove function and
considers a device unbound unconditionally after .remove() returns. So
don't sleep interruptible while waiting on the mutex, as there is no
sane way to handle an interrupt. Just returning -EINTR as was done up to
now results in leaking resources because the hid driver's remove
callback (or hid_hw_stop()) isn't called.

Fixes: 4ea5454203d9 ("HID: Fix race condition between driver core and ll-driver")
Signed-off-by: Uwe Kleine-König <redacted>
---
 drivers/hid/hid-core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 0ae9f6df59d1..4095a4db623d 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2303,12 +2303,9 @@ static int hid_device_remove(struct device *dev)
 {
 	struct hid_device *hdev = to_hid_device(dev);
 	struct hid_driver *hdrv;
-	int ret = 0;
 
-	if (down_interruptible(&hdev->driver_input_lock)) {
-		ret = -EINTR;
-		goto end;
-	}
+	down(&hdev->driver_input_lock);
+
 	hdev->io_started = false;
 
 	hdrv = hdev->driver;
@@ -2323,8 +2320,8 @@ static int hid_device_remove(struct device *dev)
 
 	if (!hdev->io_started)
 		up(&hdev->driver_input_lock);
-end:
-	return ret;
+
+	return 0;
 }
 
 static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
apart from a whitespace difference and a different commti log this patch
is the same as Dmitry's patch that became commit f2145f8dc566 ("HID: do
not use down_interruptible() when unbinding devices").

So my patch can be disregarded.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help