Skip to contentSkip to conversation

Input: elants_i2c - Fix NULL dereference at probing

PATCH Applied Takashi Iwai 2 participants 4 messages May 28, 2021 – Jun 2, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 Input: elants_i2c - Fix NULL dereference at probing

The recent change in elants_i2c driver to support more chips introduced a regression leading to Oops at probing. The driver reads id->driver_data, but the id may be NULL depending on the device type the driver gets bound.

Replace the driver data extraction with the device_get_match_data() helper, and define the driver data in OF table, too.

Fixes 9517b95bdc46 ("Input: elants_i2c - add support for eKTF3624")

---
v1->v2: Use device_get_match_data()
v2->v3: Fix pointer cast

 drivers/input/touchscreen/elants_i2c.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/touchscreen/elants_i2c.c +3 -3
index 17540bdb1eaf..0f9e3ec99aae 100644
@@ -1396,7 +1396,7 @@ static int elants_i2c_probe(struct i2c_client *client,
 	init_completion(&ts->cmd_done);
 
 	ts->client = client;
-	ts->chip_id = (enum elants_chip_id)id->driver_data;
+	ts->chip_id = (enum elants_chip_id)(uintptr_t)device_get_match_data(&client->dev);
 	i2c_set_clientdata(client, ts);
 
 	ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
@@ -1636,8 +1636,8 @@ MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
 
 #ifdef CONFIG_OF
 static const struct of_device_id elants_of_match[] = {
-	{ .compatible = "elan,ekth3500" },
-	{ .compatible = "elan,ektf3624" },
+	{ .compatible = "elan,ekth3500", .data = (void *)EKTH3500 },
+	{ .compatible = "elan,ektf3624", .data = (void *)EKTF3624 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, elants_of_match);
Signature · 1 line
2.26.2
#1 lore raw

PATCH v3 2/2 Input: elants_i2c - Switch to probe_new

Now that we get rid of the usage of id argument at probe again, let's switch to the new i2c probe method; this will avoid for people misusing the possibly unassigned id pointer again.

---
 drivers/input/touchscreen/elants_i2c.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/touchscreen/elants_i2c.c +2 -3
index 0f9e3ec99aae..68f542bb809f 100644
@@ -1369,8 +1369,7 @@ static bool elants_acpi_is_hid_device(struct device *dev)
 }
 #endif
 
-static int elants_i2c_probe(struct i2c_client *client,
-			    const struct i2c_device_id *id)
+static int elants_i2c_probe(struct i2c_client *client)
 {
 	union i2c_smbus_data dummy;
 	struct elants_data *ts;
@@ -1644,7 +1643,7 @@ MODULE_DEVICE_TABLE(of, elants_of_match);
 #endif
 
 static struct i2c_driver elants_i2c_driver = {
-	.probe = elants_i2c_probe,
+	.probe_new = elants_i2c_probe,
 	.id_table = elants_i2c_id,
 	.driver = {
 		.name = DEVICE_NAME,
Signature · 1 line
2.26.2
maintainer Applied
#2 lore raw

Re: [PATCH v3 2/2] Input: elants_i2c - Switch to probe_new

Quoted 5 lines · Takashi Iwai

Now that we get rid of the usage of id argument at probe again, let's switch to the new i2c probe method; this will avoid for people misusing the possibly unassigned id pointer again.

Applied, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#3 lore raw
In reply to Takashi Iwai
Quoted 5 lines · Takashi Iwai

The recent change in elants_i2c driver to support more chips introduced a regression leading to Oops at probing. The driver reads id->driver_data, but the id may be NULL depending on the device type the driver gets bound.

Quoted 7 lines

Replace the driver data extraction with the device_get_match_data() helper, and define the driver data in OF table, too.

Fixes 9517b95bdc46 ("Input: elants_i2c - add support for eKTF3624")

Applied, thank you.

Signature · 1 line
Dmitry