Skip to content

Commit 0499d5d

Browse files
Hamish Martingregkh
authored andcommitted
HID: mcp2221: Set driver data before I2C adapter add
commit f2d4a5834638bbc967371b9168c0b481519f7c5e upstream. 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/[email protected]/ Signed-off-by: Hamish Martin <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> Signed-off-by: Sumanth Gavini <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7c2a7b7 commit 0499d5d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/hid/hid-mcp2221.c

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

882+
i2c_set_adapdata(&mcp->adapter, mcp);
882883
ret = i2c_add_adapter(&mcp->adapter);
883884
if (ret) {
884885
hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret);
885886
goto err_i2c;
886887
}
887-
i2c_set_adapdata(&mcp->adapter, mcp);
888888

889889
/* Setup GPIO chip */
890890
mcp->gc = devm_kzalloc(&hdev->dev, sizeof(*mcp->gc), GFP_KERNEL);

0 commit comments

Comments
 (0)