Skip to contentSkip to conversation

Input: elan_i2c - check if device is there before really probing

PATCH In review Dmitry Torokhov 3 participants 5 messages May 9, 2017 – May 11, 2017

Subsystems (2)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

PATCH v2 1/1 Input: elan_i2c - check if device is there before really probing

Before trying to properly initialize the touchpad and generate bunch of errors, let's first see it there is anything at the given address. If we get error, fail silently with -ENXIO.

---

v2: switched over to i2c_smbus_read_byte() as Guenter suggested

 drivers/input/mouse/elan_i2c_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/mouse/elan_i2c_core.c +7 -0
index 5d3b53dd2fa2..3b616cb7c67f 100644
@@ -1091,6 +1091,13 @@ static int elan_probe(struct i2c_client *client,
 		return error;
 	}
 
+	/* Make sure there is something at this address */
+	error = i2c_smbus_read_byte(client);
+	if (error < 0) {
+		dev_dbg(&client->dev, "nothing at this address: %d\n", error);
+		return -ENXIO;
+	}
+
 	/* Initialize the touchpad. */
 	error = elan_initialize(data);
 	if (error)
Signature · 5 lines
2.13.0.rc2.291.g57267f2277-goog


-- 
Dmitry
#1 lore raw

drivers/input/mouse/elan_i2c_core.c static int elan_probe(struct i2c_client *client, · line 1098

Quoted 5 lines · Dmitry Torokhov
drivers/input/mouse/elan_i2c_core.c +5 -0
+       /* Make sure there is something at this address */
+       error = i2c_smbus_read_byte(client);
+       if (error < 0) {
+               dev_dbg(&client->dev, "nothing at this address: %d\n", error);
+               return -ENXIO;

You could return the real error code here: 'return error'

author maintainer
#2 lore raw
Quoted 10 lines · Fabio Estevam

drivers/input/mouse/elan_i2c_core.c static int elan_probe(struct i2c_client *client, · line 1098

Quoted 5 lines · Dmitry Torokhov
drivers/input/mouse/elan_i2c_core.c +5 -0
+       /* Make sure there is something at this address */
+       error = i2c_smbus_read_byte(client);
+       if (error < 0) {
+               dev_dbg(&client->dev, "nothing at this address: %d\n", error);
+               return -ENXIO;

You could return the real error code here: 'return error'

That is the point of the patch - we want to fail silently if the device is not actually there and fails even the simplest communication. Driver core treats ENXIO and ENODEV as special and does not log errors.

Thanks.

Signature · 1 line
Dmitry
#3 lore raw
Quoted 3 lines · Dmitry Torokhov

That is the point of the patch - we want to fail silently if the device is not actually there and fails even the simplest communication. Driver core treats ENXIO and ENODEV as special and does not log errors.

Got it, thanks for the explanation!

Reviewed-by on v2 1/1
#4 lore raw
In reply to Dmitry Torokhov
Quoted 5 lines · Dmitry Torokhov

Before trying to properly initialize the touchpad and generate bunch of errors, let's first see it there is anything at the given address. If we get error, fail silently with -ENXIO.

Quoted 25 lines

---

v2: switched over to i2c_smbus_read_byte() as Guenter suggested

 drivers/input/mouse/elan_i2c_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/mouse/elan_i2c_core.c +7 -0
index 5d3b53dd2fa2..3b616cb7c67f 100644
@@ -1091,6 +1091,13 @@ static int elan_probe(struct i2c_client *client,
 		return error;
 	}
 
+	/* Make sure there is something at this address */
+	error = i2c_smbus_read_byte(client);
+	if (error < 0) {
+		dev_dbg(&client->dev, "nothing at this address: %d\n", error);
+		return -ENXIO;
+	}
+
 	/* Initialize the touchpad. */
 	error = elan_initialize(data);
 	if (error)