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

Subsystems: hid core layer, the rest

STALE3044d

3 messages, 3 authors, 2018-05-15 · open the first message on its own page

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

From: Dmitry Torokhov <hidden>
Date: 2018-05-09 19:12:22

From: Dmitry Torokhov <redacted>

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.

Signed-off-by: Dmitry Torokhov <redacted>
---
 drivers/hid/i2c-hid/i2c-hid.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 7230243b94d30..a59d483ff316a 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -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

Re: [PATCH] HID: i2c-hid: check if device is there before really probing

From: Benjamin Tissoires <hidden>
Date: 2018-05-14 08:30:00

On Wed, May 9, 2018 at 9:12 PM, Dmitry Torokhov [off-list ref] wrote:
From: Dmitry Torokhov <redacted>

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.

Signed-off-by: Dmitry Torokhov <redacted>
---
Looks good. Tested on a Dell XPS with an i2c-hid touchpad:
Reviewed-by: Benjamin Tissoires <redacted>

Cheers,
Benjamin
quoted hunk
 drivers/hid/i2c-hid/i2c-hid.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 7230243b94d30..a59d483ff316a 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -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

Re: [PATCH] HID: i2c-hid: check if device is there before really probing

From: Jiri Kosina <jikos@kernel.org>
Date: 2018-05-15 09:16:08

On Wed, 9 May 2018, Dmitry Torokhov wrote:
From: Dmitry Torokhov <redacted>

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.

Signed-off-by: Dmitry Torokhov <redacted>
Applied, thanks.

-- 
Jiri Kosina
SUSE Labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help