Skip to content

Commit f2d4a58

Browse files
hamishm-atlnzJiri Kosina
authored andcommitted
HID: mcp2221: Set driver data before I2C adapter add
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>
1 parent 4ea4ed2 commit f2d4a58

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/hid/hid-mcp2221.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,12 @@ static int mcp2221_probe(struct hid_device *hdev,
11571157
snprintf(mcp->adapter.name, sizeof(mcp->adapter.name),
11581158
"MCP2221 usb-i2c bridge");
11591159

1160+
i2c_set_adapdata(&mcp->adapter, mcp);
11601161
ret = devm_i2c_add_adapter(&hdev->dev, &mcp->adapter);
11611162
if (ret) {
11621163
hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret);
11631164
return ret;
11641165
}
1165-
i2c_set_adapdata(&mcp->adapter, mcp);
11661166

11671167
#if IS_REACHABLE(CONFIG_GPIOLIB)
11681168
/* Setup GPIO chip */

0 commit comments

Comments
 (0)