diff mbox series

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

Message ID 20220225034110.13341-1-baijiaju1990@gmail.com (mailing list archive)
State Mainlined
Commit fe23b6bbeac40de957724b90a88d46fb336e29a9
Delegated to: Jiri Kosina
Headers show
Series hid: hid-nintendo: check the return value of alloc_workqueue() | expand

Commit Message

Jia-Ju Bai Feb. 25, 2022, 3:41 a.m. UTC
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")
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/hid/hid-nintendo.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Silvan Jegen Feb. 26, 2022, 2:14 p.m. UTC | #1
Hi

Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
> 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")
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/hid/hid-nintendo.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
> index b6a9a0f3966e..2204de889739 100644
> --- a/drivers/hid/hid-nintendo.c
> +++ b/drivers/hid/hid-nintendo.c
> @@ -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!

Reviewed-by: Silvan Jegen <s.jegen@gmail.com>


Cheers,

Silvan
Jiri Kosina March 1, 2022, 2:58 p.m. UTC | #2
On Thu, 24 Feb 2022, Jia-Ju Bai wrote:

> 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")
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/hid/hid-nintendo.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
> index b6a9a0f3966e..2204de889739 100644
> --- a/drivers/hid/hid-nintendo.c
> +++ b/drivers/hid/hid-nintendo.c
> @@ -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.
diff mbox series

Patch

diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index b6a9a0f3966e..2204de889739 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -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);