Skip to contentSkip to conversation

hid: hid-nintendo: check the return value of alloc_workqueue()

PATCH In review Jia-Ju Bai 3 participants 3 messages Feb 25, 2022 – Mar 1, 2022

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 hid: hid-nintendo: check the return value of alloc_workqueue()

The function alloc_workqueue() in nintendo_hid_probe() can fail, but there is no check of its return value. To fix this bug, its return value should be checked with new error handling code.

Fixes c4eae84feff3e ("HID: nintendo: add rumble support")
---
 drivers/hid/hid-nintendo.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hid/hid-nintendo.c +4 -0
index b6a9a0f3966e..2204de889739 100644
@@ -2128,6 +2128,10 @@ static int nintendo_hid_probe(struct hid_device *hdev,
 	spin_lock_init(&ctlr->lock);
 	ctlr->rumble_queue = alloc_workqueue("hid-nintendo-rumble_wq",
 					     WQ_FREEZABLE | WQ_MEM_RECLAIM, 0);
+	if (!ctlr->rumble_queue) {
+		ret = -ENOMEM;
+		goto err;
+	}
 	INIT_WORK(&ctlr->rumble_worker, joycon_rumble_worker);
 
 	ret = hid_parse(hdev);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 16 lines · Jia-Ju Bai

The function alloc_workqueue() in nintendo_hid_probe() can fail, but there is no check of its return value. To fix this bug, its return value should be checked with new error handling code.

Fixes c4eae84feff3e ("HID: nintendo: add rumble support")
---
 drivers/hid/hid-nintendo.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hid/hid-nintendo.c +0 -0
index b6a9a0f3966e..2204de889739 100644

drivers/hid/hid-nintendo.c static int nintendo_hid_probe(struct hid_device *hdev, · line 2137

Quoted 10 lines
drivers/hid/hid-nintendo.c +4 -0
@@ -2128,6 +2128,10 @@ static int nintendo_hid_probe(struct hid_device *hdev,
 	spin_lock_init(&ctlr->lock);
 	ctlr->rumble_queue = alloc_workqueue("hid-nintendo-rumble_wq",
 					     WQ_FREEZABLE | WQ_MEM_RECLAIM, 0);
+	if (!ctlr->rumble_queue) {
+		ret = -ENOMEM;
+		goto err;
+	}
 	INIT_WORK(&ctlr->rumble_worker, joycon_rumble_worker);
 
 	ret = hid_parse(hdev);

LGTM!

Cheers,

Silvan

maintainer
#2 lore raw
In reply to Jia-Ju Bai
Quoted 16 lines · Jia-Ju Bai

The function alloc_workqueue() in nintendo_hid_probe() can fail, but there is no check of its return value. To fix this bug, its return value should be checked with new error handling code.

Fixes c4eae84feff3e ("HID: nintendo: add rumble support")
---
 drivers/hid/hid-nintendo.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hid/hid-nintendo.c +0 -0
index b6a9a0f3966e..2204de889739 100644

drivers/hid/hid-nintendo.c static int nintendo_hid_probe(struct hid_device *hdev, · line 2135

Quoted 8 lines
drivers/hid/hid-nintendo.c +4 -0
@@ -2128,6 +2128,10 @@ static int nintendo_hid_probe(struct hid_device *hdev,
 	spin_lock_init(&ctlr->lock);
 	ctlr->rumble_queue = alloc_workqueue("hid-nintendo-rumble_wq",
 					     WQ_FREEZABLE | WQ_MEM_RECLAIM, 0);
+	if (!ctlr->rumble_queue) {
+		ret = -ENOMEM;
+		goto err;
+	}
 	INIT_WORK(&ctlr->rumble_worker, joycon_rumble_worker);

Thanks for the patch.

For future submissions, please try to make sure to always follow the subsystem-specific formatting of the shortlog (upperacase "HID: " prefix in this case).

I've fixed that up and applied.

Signature · 2 lines
Jiri Kosina
SUSE Labs