Skip to contentSkip to conversation

HID: mcp2221: always initialize and cancel init_work

PATCH Applied Myeonghun Pak 2 participants 2 messages Oct 2 – Oct 16

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

PATCH 1/1 HID: mcp2221: always initialize and cancel init_work

The writable gpio_mode_enforce parameter can change between probe and remove.

If it changes from false to true after probe, remove skips cancellation of init_work. Pending or running work can then access devm-managed driver state after teardown. Changing it from true to false can make remove cancel an uninitialized delayed work item.

Initialize init_work whenever IIO is reachable and cancel it unconditionally on remove. Keep the parameter check only for scheduling the initialization.

The false-to-true cancellation gap was previously reported by Sashiko. We also encountered this issue during our static-analysis research.

Fixes 200e6c6e94fa ("HID: mcp2221: Add module parameter to enfoce GPIO mode")
Assisted-by LLM
---
 drivers/hid/hid-mcp2221.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/hid/hid-mcp2221.c +3 -5
index d52ce3531ab706db8ec908d57ad0383af9fafb1e..6515692b408ee7b6ee318cfa3f240321c133f2c4 100644
@@ -1072,8 +1072,7 @@ static void mcp2221_remove(struct hid_device *hdev)
 #if IS_REACHABLE(CONFIG_IIO)
 	struct mcp2221 *mcp = hid_get_drvdata(hdev);
 
-	if (!gpio_mode_enforce)
-		cancel_delayed_work_sync(&mcp->init_work);
+	cancel_delayed_work_sync(&mcp->init_work);
 #endif
 }
 
@@ -1347,10 +1346,9 @@ static int mcp2221_probe(struct hid_device *hdev,
 #endif
 
 #if IS_REACHABLE(CONFIG_IIO)
-	if (!gpio_mode_enforce) {
-		INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work);
+	INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work);
+	if (!gpio_mode_enforce)
 		schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
-	}
 #endif
 
 	return 0;
maintainer Applied
#1 lore raw
Quoted 15 lines · Myeonghun Pak

The writable gpio_mode_enforce parameter can change between probe and remove.

If it changes from false to true after probe, remove skips cancellation of init_work. Pending or running work can then access devm-managed driver state after teardown. Changing it from true to false can make remove cancel an uninitialized delayed work item.

Initialize init_work whenever IIO is reachable and cancel it unconditionally on remove. Keep the parameter check only for scheduling the initialization.

The false-to-true cancellation gap was previously reported by Sashiko. We also encountered this issue during our static-analysis research.

Quoted 6 lines
Fixes 200e6c6e94fa ("HID: mcp2221: Add module parameter to enfoce GPIO mode")
Assisted-by LLM

Applied to hid.git#for-7.3/upstream-fixes, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs