Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: mcp2221: fix get and get_direction for gpio

The mcp2221_raw_event retrieves the value and direction of gpio on the
same command, by setting the value on mcp->status and the direction on
mcp->gpio_dir; and the offset at which they are read is based on
mcp->gp_idx, set by the gpiochip callbacks.

However, the individual gpiochip calls set the index to look for
directly on the field they want to track. This create a "double offset"
in the final read in the response report.

Align the behaviour of mcp2221_raw_event and
mcp_gpio_get/mcp_gpio_get_direction by putting gp_idx on those calls to
the base offset of the gpio status struct.

Signed-off-by: Louis Morhet <lmorhet@kalrayinc.com>
Link: https://lore.kernel.org/r/dd0b23800a79d2a464e1e9ed429b018b69fd5df2.1680602387.git.lmorhet@kalrayinc.com
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

authored by

Louis Morhet and committed by
Benjamin Tissoires
ca6961d8 e36c31f8

+2 -2
+2 -2
drivers/hid/hid-mcp2221.c
··· 594 594 595 595 mcp->txbuf[0] = MCP2221_GPIO_GET; 596 596 597 - mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].value); 597 + mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset]); 598 598 599 599 mutex_lock(&mcp->lock); 600 600 ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); ··· 675 675 676 676 mcp->txbuf[0] = MCP2221_GPIO_GET; 677 677 678 - mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].direction); 678 + mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset]); 679 679 680 680 mutex_lock(&mcp->lock); 681 681 ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1);