Skip to contentSkip to conversation

HID: i2c-hid-of: fix NULL-deref on failed power up

PATCH In review Johan Hovold 4 participants 4 messages Jan 26, 2024 – Feb 1, 2024

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

PATCH 1/1 HID: i2c-hid-of: fix NULL-deref on failed power up

A while back the I2C HID implementation was split in an ACPI and OF part, but the new OF driver never initialises the client pointer which is dereferenced on power-up failures.

Fixes b33752c30023 ("HID: i2c-hid: Reorganize so ACPI and OF are separate modules")
Cc Douglas Anderson <[email protected]>
---
 drivers/hid/i2c-hid/i2c-hid-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/i2c-hid/i2c-hid-of.c +1 -0
index c4e1fa0273c8..8be4d576da77 100644
@@ -87,6 +87,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
 	if (!ihid_of)
 		return -ENOMEM;
 
+	ihid_of->client = client;
 	ihid_of->ops.power_up = i2c_hid_of_power_up;
 	ihid_of->ops.power_down = i2c_hid_of_power_down;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 18 lines · Johan Hovold

A while back the I2C HID implementation was split in an ACPI and OF part, but the new OF driver never initialises the client pointer which is dereferenced on power-up failures.

Fixes b33752c30023 ("HID: i2c-hid: Reorganize so ACPI and OF are separate modules")
Cc Douglas Anderson <[email protected]>
---
 drivers/hid/i2c-hid/i2c-hid-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/i2c-hid/i2c-hid-of.c +0 -0
index c4e1fa0273c8..8be4d576da77 100644

drivers/hid/i2c-hid/i2c-hid-of.c static int i2c_hid_of_probe(struct i2c_client *client) · line 90

Quoted 4 lines
drivers/hid/i2c-hid/i2c-hid-of.c +1 -0
@@ -87,6 +87,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
        if (!ihid_of)
                return -ENOMEM;
 
+       ihid_of->client = client;

Good catch and thanks for the fix. FWIW, I'd be OK w/

That being said, I'd be even happier if you simply removed the "client" from the structure and removed the error printout. regulator_bulk_enable() already prints error messages when a failure happens and thus the error printout is redundant and wastes space.

-Doug

maintainer
#2 lore raw
Quoted 20 lines · Doug Anderson
Quoted 20 lines

A while back the I2C HID implementation was split in an ACPI and OF part, but the new OF driver never initialises the client pointer which is dereferenced on power-up failures.

Fixes b33752c30023 ("HID: i2c-hid: Reorganize so ACPI and OF are separate modules")
Cc Douglas Anderson <[email protected]>
---
 drivers/hid/i2c-hid/i2c-hid-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/i2c-hid/i2c-hid-of.c +0 -0
index c4e1fa0273c8..8be4d576da77 100644
@@ -87,6 +87,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
        if (!ihid_of)
                return -ENOMEM;
 
Quoted 5 lines

drivers/hid/i2c-hid/i2c-hid-of.c static int i2c_hid_of_probe(struct i2c_client *client) · line 90

Quoted 1 line
drivers/hid/i2c-hid/i2c-hid-of.c +1 -0
+       ihid_of->client = client;

Good catch and thanks for the fix. FWIW, I'd be OK w/

I've now queued this as a fix for 6.8 ....

Quoted 4 lines

That being said, I'd be even happier if you simply removed the "client" from the structure and removed the error printout. regulator_bulk_enable() already prints error messages when a failure happens and thus the error printout is redundant and wastes space.

... and this can be done for 6.9.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#3 lore raw
In reply to Doug Anderson
Quoted 6 lines · Doug Anderson
Quoted 3 lines · Johan Hovold

A while back the I2C HID implementation was split in an ACPI and OF part, but the new OF driver never initialises the client pointer which is dereferenced on power-up failures.

Quoted 8 lines

Good catch and thanks for the fix. FWIW, I'd be OK w/

That being said, I'd be even happier if you simply removed the "client" from the structure and removed the error printout. regulator_bulk_enable() already prints error messages when a failure happens and thus the error printout is redundant and wastes space.

True, but that error message does not include the device that tried to use the regulator.

I actually hit this when adding dev_dbg() to the function in question. For such cases, it's also convenient to have struct device easily accessible so I think it should be ok to just leave this pointer in.

Johan