linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: i2c-hid: check if device is there before really probing
@ 2018-05-09 19:12 Dmitry Torokhov
  2018-05-14  8:29 ` Benjamin Tissoires
  2018-05-15  9:16 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2018-05-09 19:12 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Benjamin Tissoires, linux-input, linux-kernel, Brian Norris,
	Douglas Anderson

From: Dmitry Torokhov <dtor@chromium.org>

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 <dtor@chromium.org>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: i2c-hid: check if device is there before really probing
  2018-05-09 19:12 [PATCH] HID: i2c-hid: check if device is there before really probing Dmitry Torokhov
@ 2018-05-14  8:29 ` Benjamin Tissoires
  2018-05-15  9:16 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Tissoires @ 2018-05-14  8:29 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, open list:HID CORE LAYER, lkml, Brian Norris,
	Douglas Anderson

On Wed, May 9, 2018 at 9:12 PM, Dmitry Torokhov <dtor@google.com> wrote:
> From: Dmitry Torokhov <dtor@chromium.org>
>
> 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 <dtor@chromium.org>
> ---

Looks good. Tested on a Dell XPS with an i2c-hid touchpad:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Cheers,
Benjamin

>  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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: i2c-hid: check if device is there before really probing
  2018-05-09 19:12 [PATCH] HID: i2c-hid: check if device is there before really probing Dmitry Torokhov
  2018-05-14  8:29 ` Benjamin Tissoires
@ 2018-05-15  9:16 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2018-05-15  9:16 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Benjamin Tissoires, linux-input, linux-kernel, Brian Norris,
	Douglas Anderson

On Wed, 9 May 2018, Dmitry Torokhov wrote:

> From: Dmitry Torokhov <dtor@chromium.org>
> 
> 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 <dtor@chromium.org>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-15  9:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-09 19:12 [PATCH] HID: i2c-hid: check if device is there before really probing Dmitry Torokhov
2018-05-14  8:29 ` Benjamin Tissoires
2018-05-15  9:16 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).