Skip to contentSkip to conversation

HID: Replace deprecated create_singlethread_workqueue

PATCH New George Karagounis 1 participant 4 messages Oct 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover HID: Replace deprecated create_singlethread_workqueue

Hi maintainers,

This patch series replaces the deprecated create_singlethread_workqueue() with the more efficient alloc_ordered_workqueue() in three HID drivers.

Changes in v2:
- Addressed Sashiko bot review regarding WQ_MEM_RECLAIM misuse. Changed flags to 0 since these queues do not participate in memory reclaim.
- Fixed a critical format string vulnerability in hid-haptic.c by passing the format string directly to alloc_ordered_workqueue() and removing the unnecessary kmalloc/sprintf.
- Verified runtime behavior by compiling a minimal kernel and booting in QEMU. Confirmed successful initialization and safe HID descriptor parsing via a uhid fuzzer. But needs testing on real hardware.

Best regards,
George

George Karagounis (3):
HID: haptic: Replace create_singlethread_workqueue with
alloc_ordered_workqueue
HID: elo: Replace create_singlethread_workqueue with
alloc_ordered_workqueue
HID: logitech-hidpp: Replace create_singlethread_workqueue with
alloc_ordered_workqueue

 drivers/hid/hid-elo.c            | 2 +-
 drivers/hid/hid-haptic.c         | 8 +-------
 drivers/hid/hid-logitech-hidpp.c | 2 +-
 3 files changed, 3 insertions(+), 9 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

PATCH v2 1/3 HID: haptic: Replace create_singlethread_workqueue with alloc_ordered_workqueue

create_singlethread_workqueue() is deprecated. Replace it with

alloc_ordered_workqueue() for the haptic workqueue.

Pass the format string directly to alloc_ordered_workqueue() to avoid

a format string vulnerability where hdev->name could contain % specifiers.

This also eliminates the need for the intermediate kmalloc/sprintf.

Use flags=0 as this workqueue only transmits output reports and is

not part of the memory reclaim path.

---
 drivers/hid/hid-haptic.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/hid/hid-haptic.c +1 -7
index 8760eeb08b2c..c3aa7db44766 100644
@@ -418,7 +418,6 @@ int hid_haptic_init(struct hid_device *hdev,
 		.hid_usage = HID_HP_WAVEFORMSTOP & HID_USAGE,
 	};
 	const char *prefix = "hid-haptic";
-	char *name;
 	int (*flush)(struct input_dev *dev, struct file *file);
 	int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
 
@@ -457,12 +456,7 @@ int hid_haptic_init(struct hid_device *hdev,
 	haptic->manual_trigger_report_len =
 		hid_report_len(haptic->manual_trigger_report);
 	mutex_init(&haptic->manual_trigger_mutex);
-	name = kmalloc(strlen(prefix) + strlen(hdev->name) + 2, GFP_KERNEL);
-	if (name) {
-		sprintf(name, "%s %s", prefix, hdev->name);
-		haptic->wq = create_singlethread_workqueue(name);
-		kfree(name);
-	}
+	haptic->wq = alloc_ordered_workqueue("%s %s", 0, prefix, hdev->name);
 	if (!haptic->wq) {
 		ret = -ENOMEM;
 		goto duration_map;
Signature · 1 line
2.56.0
#2 lore raw

PATCH v2 2/3 HID: elo: Replace create_singlethread_workqueue with alloc_ordered_workqueue

In reply to George Karagounis

create_singlethread_workqueue() is deprecated. Replace it with

alloc_ordered_workqueue() for the elousb workqueue.

Use flags=0 as this workqueue only transmits outgoing output reports

and is not depended upon during memory reclaim. Using WQ_MEM_RECLAIM

would unnecessarily spawn a rescuer thread and trigger

check_flush_dependency() warnings.

---
 drivers/hid/hid-elo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-elo.c +1 -1
index 86e8729e1975..8a96c0f7d5b0 100644
@@ -296,7 +296,7 @@ static int __init elo_driver_init(void)
 {
 	int ret;
 
-	wq = create_singlethread_workqueue("elousb");
+	wq = alloc_ordered_workqueue("elousb", 0);
 	if (!wq)
 		return -ENOMEM;
 
Signature · 1 line
2.56.0
#3 lore raw

PATCH v2 3/3 HID: logitech-hidpp: Replace create_singlethread_workqueue with alloc_ordered_workqueue

In reply to George Karagounis

create_singlethread_workqueue() is deprecated. Replace it with

alloc_ordered_workqueue() for the force feedback sendqueue.

Use flags=0 as this workqueue only queues outgoing force-feedback

commands and relies on GFP_KERNEL allocations, meaning it is not

depended upon during memory reclaim.

---
 drivers/hid/hid-logitech-hidpp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-logitech-hidpp.c +1 -1
index 27d83b8bbaaf..c4c578c42182 100644
@@ -2875,7 +2875,7 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
 		error = -ENOMEM;
 		goto err_free_data;
 	}
-	data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
+	data->wq = alloc_ordered_workqueue("hidpp-ff-sendqueue", 0);
 	if (!data->wq) {
 		error = -ENOMEM;
 		goto err_free_effect_ids;
Signature · 1 line
2.56.0