diff mbox series

HID: mcp2221: fix hang on probe while setting up gpiochip

Message ID 20220406032307.4001281-1-gavin@matician.com
State New
Headers show
Series HID: mcp2221: fix hang on probe while setting up gpiochip | expand

Commit Message

Gavin Li April 6, 2022, 3:23 a.m. UTC
From: Gavin Li <gavin@matician.com>

The driver expects HID events to be delivered to it during probe()
because the devm_gpiochip_add_data() call indirectly calls
get_direction(), which fires an HID command that expects an HID
response. Without this patch, the get_direction() would timeout (of 4
seconds) once per pin, leading to a 16 second delay before the device is
usable.

This patch adds calls to hid_device_io_start() and hid_device_io_stop()
to notify the HID subsystem that the driver is ready to receive events
before the probe() finishes.

Signed-off-by: Gavin Li <gavin@matician.com>
---
 drivers/hid/hid-mcp2221.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 4211b9839209b..567ef8b93376d 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -877,6 +877,9 @@  static int mcp2221_probe(struct hid_device *hdev,
 	}
 	i2c_set_adapdata(&mcp->adapter, mcp);
 
+	/* gpiolib calls get_direction(), so become ready to process events */
+	hid_device_io_start(hdev);
+
 	/* Setup GPIO chip */
 	mcp->gc = devm_kzalloc(&hdev->dev, sizeof(*mcp->gc), GFP_KERNEL);
 	if (!mcp->gc) {
@@ -902,6 +905,7 @@  static int mcp2221_probe(struct hid_device *hdev,
 	return 0;
 
 err_gc:
+	hid_device_io_stop(hdev);
 	i2c_del_adapter(&mcp->adapter);
 err_i2c:
 	hid_hw_close(mcp->hdev);