Skip to contentSkip to conversation

usb: typec: stusb160x: add missing NULL check for i2c_get_match_data()

PATCH In review Joshua Crofts 3 participants 6 messages Aug 6 – Aug 24

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

PATCH 1/1 usb: typec: stusb160x: add missing NULL check for i2c_get_match_data()

In stusb160x_probe(), the return value of i2c_get_match_data() is not checked, causing a null pointer dereference later on if the device was registered manually (without devicetree or ACPI).

Fix this by adding a NULL check for the return value of i2c_get_match_data().

Reported-by [email protected]
Fixes 823754697556 ("usb: typec: stusb160x: Make use of i2c_get_match_data()")
---
 drivers/usb/typec/stusb160x.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/typec/stusb160x.c +2 -0
index 6d85b25b40bc..8f3435c669cd 100644
@@ -645,6 +645,8 @@ static int stusb160x_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, chip);
 
 	regmap_config = i2c_get_match_data(client);
+	if (!regmap_config)
+		return -ENODEV;
 
 	chip->regmap = devm_regmap_init_i2c(client, regmap_config);
 	if (IS_ERR(chip->regmap)) {
Signature · 1 line
2.47.3
#1 lore raw
Quoted 4 lines · On Thu, 6 Aug 2026 08:43:01 +0000 Joshua Crofts <[email protected]>…

In stusb160x_probe(), the return value of i2c_get_match_data() is not checked, causing a null pointer dereference later on if the device was registered manually (without devicetree or ACPI).

Quoted 8 lines

Fix this by adding a NULL check for the return value of i2c_get_match_data().

Reported-by [email protected]
Fixes 823754697556 ("usb: typec: stusb160x: Make use of i2c_get_match_data()")

---

Ugh, forgot to Cc stable.

Signature · 2 lines
Kind regards,
Joshua Crofts
#2 lore raw
In reply to Joshua Crofts
Quoted 20 lines · On Thu, 6 Aug 2026 08:43:01 +0000 Joshua Crofts <[email protected]>…

In stusb160x_probe(), the return value of i2c_get_match_data() is not checked, causing a null pointer dereference later on if the device was registered manually (without devicetree or ACPI).

Fix this by adding a NULL check for the return value of i2c_get_match_data().

Reported-by [email protected]
Fixes 823754697556 ("usb: typec: stusb160x: Make use of i2c_get_match_data()")
---
 drivers/usb/typec/stusb160x.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/typec/stusb160x.c +0 -0
index 6d85b25b40bc..8f3435c669cd 100644

drivers/usb/typec/stusb160x.c static int stusb160x_probe(struct i2c_client *client) · line 652

Quoted 8 lines
drivers/usb/typec/stusb160x.c +2 -0
@@ -645,6 +645,8 @@ static int stusb160x_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, chip);
 
 	regmap_config = i2c_get_match_data(client);
+	if (!regmap_config)
+		return -ENODEV;
 
 	chip->regmap = devm_regmap_init_i2c(client, regmap_config);
 	if (IS_ERR(chip->regmap)) {

Hi Greg and Heikki,

A (very) gentle ping on this patch. Do you need a v2 to include the Cc to stable?

Signature · 2 lines
Kind regards,
Joshua Crofts
#3 lore raw
Quoted 29 lines · Joshua Crofts
Quoted 26 lines · On Thu, 6 Aug 2026 08:43:01 +0000 Joshua Crofts <[email protected]>…

In stusb160x_probe(), the return value of i2c_get_match_data() is not checked, causing a null pointer dereference later on if the device was registered manually (without devicetree or ACPI).

Fix this by adding a NULL check for the return value of i2c_get_match_data().

Reported-by [email protected]
Fixes 823754697556 ("usb: typec: stusb160x: Make use of i2c_get_match_data()")
---
 drivers/usb/typec/stusb160x.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/typec/stusb160x.c +2 -0
index 6d85b25b40bc..8f3435c669cd 100644
@@ -645,6 +645,8 @@ static int stusb160x_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, chip);
 
 	regmap_config = i2c_get_match_data(client);
+	if (!regmap_config)
+		return -ENODEV;
 
Quoted 6 lines

drivers/usb/typec/stusb160x.c static int stusb160x_probe(struct i2c_client *client) · line 652

Quoted 2 lines
drivers/usb/typec/stusb160x.c +0 -0
 	chip->regmap = devm_regmap_init_i2c(client, regmap_config);
 	if (IS_ERR(chip->regmap)) {

Hi Greg and Heikki,

A (very) gentle ping on this patch. Do you need a v2 to include the

It's the middle of the merge window, we can't do anything until -rc1 is out.

Also, this patch really isn't even needed, just don't attempt to bind drivers to devices that are not the correct device.

thanks,

greg k-h

#4 lore raw
In reply to Joshua Crofts
Quoted 2 lines · Joshua Crofts

On Thu, 6 Aug 2026 08:43:01 +0000
Joshua Crofts <[email protected]> wrote:

...

Quoted 3 lines

drivers/usb/typec/stusb160x.c static int stusb160x_probe(struct i2c_client *client) · line 649

Quoted 3 lines
drivers/usb/typec/stusb160x.c +2 -0
 	regmap_config = i2c_get_match_data(client);
+	if (!regmap_config)
+		return -ENODEV;

Return -ENODATA here, it will distinguish better in case of debugging.

Quoted 2 lines

A (very) gentle ping on this patch. Do you need a v2 to include the Cc to stable?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 11 lines · On Mon, 24 Aug 2026 09:48:26 +0300 Andy Shevchenko…
Quoted 2 lines · Joshua Crofts

On Thu, 6 Aug 2026 08:43:01 +0000
Joshua Crofts <[email protected]> wrote:

...

Quoted 3 lines

drivers/usb/typec/stusb160x.c static int stusb160x_probe(struct i2c_client *client) · line 649

Quoted 3 lines
drivers/usb/typec/stusb160x.c +2 -0
 	regmap_config = i2c_get_match_data(client);
+	if (!regmap_config)
+		return -ENODEV;  

Return -ENODATA here, it will distinguish better in case of debugging.

Yep, this was before our discussion about this in IIO :)

Signature · 2 lines
Kind regards,
Joshua Crofts