diff mbox series

[v3] hid: logitech: check the return value of create_singlethread_workqueue

Message ID 20190314052402.31448-1-kjlu@umn.edu (mailing list archive)
State Mainlined
Commit 6c44b15e1c9076d925d5236ddadf1318b0a25ce2
Delegated to: Jiri Kosina
Headers show
Series [v3] hid: logitech: check the return value of create_singlethread_workqueue | expand

Commit Message

Kangjie Lu March 14, 2019, 5:24 a.m. UTC
create_singlethread_workqueue may fail and return NULL. The fix
checks if it is NULL to avoid NULL pointer dereference.
Also, the fix moves the call of create_singlethread_workqueue
earlier to avoid resource-release issues.

--
V3: do not introduce memory leaks.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/hid/hid-logitech-hidpp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Jiri Kosina March 19, 2019, 10:48 a.m. UTC | #1
On Thu, 14 Mar 2019, Kangjie Lu wrote:

> create_singlethread_workqueue may fail and return NULL. The fix
> checks if it is NULL to avoid NULL pointer dereference.
> Also, the fix moves the call of create_singlethread_workqueue
> earlier to avoid resource-release issues.
> 
> --
> V3: do not introduce memory leaks.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

The signoff has to be in the commit log, not in the "notes" area. I've 
fixed that and applied.
diff mbox series

Patch

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 15ed6177a7a3..0a243247b231 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2111,6 +2111,13 @@  static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
 		kfree(data);
 		return -ENOMEM;
 	}
+	data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
+	if (!data->wq) {
+		kfree(data->effect_ids);
+		kfree(data);
+		return -ENOMEM;
+	}
+
 	data->hidpp = hidpp;
 	data->feature_index = feature_index;
 	data->version = version;
@@ -2155,7 +2162,6 @@  static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
 	/* ignore boost value at response.fap.params[2] */
 
 	/* init the hardware command queue */
-	data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
 	atomic_set(&data->workqueue_size, 0);
 
 	/* initialize with zero autocenter to get wheel in usable state */