summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHamish Martin <hamish.martin@alliedtelesis.co.nz>2023-10-25 16:55:10 +1300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-12-20 17:01:58 +0100
commit2afe67cfe8f121b1b9dd244a0edc01b89cd65813 (patch)
tree951abfc5d2d71bfabf8e9a1a5b0f1983de6f2ab6
parent086f91f3ce3b8d13cb794b955002b74444a384fa (diff)
downloadlinux-stable-2afe67cfe8f121b1b9dd244a0edc01b89cd65813.tar.gz
linux-stable-2afe67cfe8f121b1b9dd244a0edc01b89cd65813.tar.bz2
linux-stable-2afe67cfe8f121b1b9dd244a0edc01b89cd65813.zip
HID: mcp2221: Set driver data before I2C adapter add
[ Upstream commit f2d4a5834638bbc967371b9168c0b481519f7c5e ] The process of adding an I2C adapter can invoke I2C accesses on that new adapter (see i2c_detect()). Ensure we have set the adapter's driver data to avoid null pointer dereferences in the xfer functions during the adapter add. This has been noted in the past and the same fix proposed but not completed. See: https://lore.kernel.org/lkml/ef597e73-ed71-168e-52af-0d19b03734ac@vigem.de/ Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz> Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/hid/hid-mcp2221.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 72883e0ce757..b95f31cf0fa2 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -1157,12 +1157,12 @@ static int mcp2221_probe(struct hid_device *hdev,
snprintf(mcp->adapter.name, sizeof(mcp->adapter.name),
"MCP2221 usb-i2c bridge");
+ i2c_set_adapdata(&mcp->adapter, mcp);
ret = devm_i2c_add_adapter(&hdev->dev, &mcp->adapter);
if (ret) {
hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret);
return ret;
}
- i2c_set_adapdata(&mcp->adapter, mcp);
#if IS_REACHABLE(CONFIG_GPIOLIB)
/* Setup GPIO chip */