[PATCH] HID: mcp2221: Use the direction field for high GPIO outputs

From: Haowen Tu

Date: Fri Nov 13 2026 - 04:16:11 EST


The GPIO_GET response handler stores the pin value in mcp->status and the
pin direction in mcp->gpio_dir. Consequently,
mcp_send_data_req_status() returns either zero or one on a successful
GPIO_GET request.

mcp_gpio_get_direction() treats any nonzero return as an error and returns
it directly. For a high output this returns one, which means
GPIO_LINE_DIRECTION_IN, instead of checking the output direction reported
by the device.

Only return early for negative errors so both pin levels use gpio_dir to
determine the direction.

Fixes: ca6961d8a851 ("HID: mcp2221: fix get and get_direction for gpio")
Signed-off-by: Haowen Tu <tuhaowen@xxxxxxxxxxxxx>
---
drivers/hid/hid-mcp2221.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 3f05d6e288f9..3358b7d0c5e4 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -810,7 +810,7 @@ static int mcp_gpio_get_direction(struct gpio_chip *gc,
ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1);
mutex_unlock(&mcp->lock);

- if (ret)
+ if (ret < 0)
return ret;

if (mcp->gpio_dir == MCP2221_DIR_IN)
--
2.50.1