Skip to contentSkip to conversation

hwmon: (pmbus) Fix driver info initialization in probe routine

PATCH Superseded Vadim Pasternak 2 participants 2 messages Feb 17, 2019 – Feb 18, 2019 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (pmbus) Fix driver info initialization in probe routine

Fix tps53679_probe() by using dynamically allocated "pmbus_driver_info" structure instead of static. Usage of static structures causes overwritten of the field "vrm_version", in case the system is equipped with several tps53679 devices with the different "vrm_version". In such case the last probed device overwrites this field for all others.

Fixes 610526527a13 ("hwmon: (pmbus) Add support for Texas Instruments tps53679 device")
---
 drivers/hwmon/pmbus/tps53679.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/tps53679.c +9 -1
index 85b515cd9df0..45eacc504e2f 100644
@@ -80,7 +80,15 @@ static struct pmbus_driver_info tps53679_info = {
 static int tps53679_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
-	return pmbus_do_probe(client, id, &tps53679_info);
+	struct pmbus_driver_info *info;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	memcpy(info, &tps53679_info, sizeof(*info));
+
+	return pmbus_do_probe(client, id, info);
 }
 
 static const struct i2c_device_id tps53679_id[] = {
Signature · 1 line
2.11.0
maintainer
#1 lore raw

Hi,

Quoted 20 lines · Vadim Pasternak

Fix tps53679_probe() by using dynamically allocated "pmbus_driver_info" structure instead of static. Usage of static structures causes overwritten of the field "vrm_version", in case the system is equipped with several tps53679 devices with the different "vrm_version". In such case the last probed device overwrites this field for all others.

Fixes 610526527a13 ("hwmon: (pmbus) Add support for Texas Instruments tps53679 device")
---
 drivers/hwmon/pmbus/tps53679.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/tps53679.c +0 -0
index 85b515cd9df0..45eacc504e2f 100644
@@ -80,7 +80,15 @@ static struct pmbus_driver_info tps53679_info = {
 static int tps53679_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)

drivers/hwmon/pmbus/tps53679.c static struct pmbus_driver_info tps53679_info = { · line 90

Quoted 10 lines
drivers/hwmon/pmbus/tps53679.c +8 -1
 {
-	return pmbus_do_probe(client, id, &tps53679_info);
+	struct pmbus_driver_info *info;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	memcpy(info, &tps53679_info, sizeof(*info));
+

Good find, but why not use devm_kmemdup() ?

Thanks,
Guenter

Quoted 4 lines
drivers/hwmon/pmbus/tps53679.c +1 -0
+	return pmbus_do_probe(client, id, info);
 }
 
 static const struct i2c_device_id tps53679_id[] = {