Skip to contentSkip to conversation

HID: i2c-hid: check if device is there before really probing

PATCH Applied Dmitry Torokhov 3 participants 3 messages May 9, 2018 – May 15, 2018 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: i2c-hid: check if device is there before really probing

From: Dmitry Torokhov <[email protected]>

On many Chromebooks touch devices are multi-sourced; the components are electrically compatible and one can be freely swapped for another without changing the OS image or firmware.

To avoid bunch of scary messages when device is not actually present in the system let's try testing basic communication with it and if there is no response terminate probe early with -ENXIO.

---
 drivers/hid/i2c-hid/i2c-hid.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/hid/i2c-hid/i2c-hid.c +8 -0
index 7230243b94d30..a59d483ff316a 100644
@@ -1048,6 +1048,14 @@ static int i2c_hid_probe(struct i2c_client *client,
 	pm_runtime_enable(&client->dev);
 	device_enable_async_suspend(&client->dev);
 
+	/* Make sure there is something at this address */
+	ret = i2c_smbus_read_byte(client);
+	if (ret < 0) {
+		dev_dbg(&client->dev, "nothing at this address: %d\n", ret);
+		ret = -ENXIO;
+		goto err_pm;
+	}
+
 	ret = i2c_hid_fetch_hid_descriptor(ihid);
 	if (ret < 0)
 		goto err_pm;
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dmitry Torokhov

From: Dmitry Torokhov <[email protected]>

On many Chromebooks touch devices are multi-sourced; the components are electrically compatible and one can be freely swapped for another without changing the OS image or firmware.

Quoted 6 lines

To avoid bunch of scary messages when device is not actually present in the system let's try testing basic communication with it and if there is no response terminate probe early with -ENXIO.

---

Looks good. Tested on a Dell XPS with an i2c-hid touchpad:

Cheers,
Benjamin

Quoted 25 lines
 drivers/hid/i2c-hid/i2c-hid.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/hid/i2c-hid/i2c-hid.c +8 -1
index 7230243b94d30..a59d483ff316a 100644
@@ -1048,6 +1048,14 @@ static int i2c_hid_probe(struct i2c_client *client,
        pm_runtime_enable(&client->dev);
        device_enable_async_suspend(&client->dev);
 
+       /* Make sure there is something at this address */
+       ret = i2c_smbus_read_byte(client);
+       if (ret < 0) {
+               dev_dbg(&client->dev, "nothing at this address: %d\n", ret);
+               ret = -ENXIO;
+               goto err_pm;
+       }
+
        ret = i2c_hid_fetch_hid_descriptor(ihid);
        if (ret < 0)
                goto err_pm;
--

2.17.0.441.gb46fe60e1d-goog

maintainer Applied
#2 lore raw
In reply to Dmitry Torokhov
Quoted 11 lines · Dmitry Torokhov

From: Dmitry Torokhov <[email protected]>

On many Chromebooks touch devices are multi-sourced; the components are electrically compatible and one can be freely swapped for another without changing the OS image or firmware.

To avoid bunch of scary messages when device is not actually present in the system let's try testing basic communication with it and if there is no response terminate probe early with -ENXIO.

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs