Message ID | 20190218195440.19680-1-vadimp@mellanox.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | [v2,hwmon] hwmon: (pmbus) Fix driver info initialization in probe routine | expand |
On 2/18/19 11:54 AM, Vadim Pasternak wrote: > 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") > Signed-off-by: Vadim Pasternak <vadimp@mellanox.com> Applied. Thanks, Guenter > --- > v1->v2: > Comments pointed out by Guenter: > - Use devm_kmemdup(). > --- > drivers/hwmon/pmbus/tps53679.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwmon/pmbus/tps53679.c b/drivers/hwmon/pmbus/tps53679.c > index 85b515cd9df0..2bc352c5357f 100644 > --- a/drivers/hwmon/pmbus/tps53679.c > +++ b/drivers/hwmon/pmbus/tps53679.c > @@ -80,7 +80,14 @@ 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_kmemdup(&client->dev, &tps53679_info, sizeof(*info), > + GFP_KERNEL); > + if (!info) > + return -ENOMEM; > + > + return pmbus_do_probe(client, id, info); > } > > static const struct i2c_device_id tps53679_id[] = { >
diff --git a/drivers/hwmon/pmbus/tps53679.c b/drivers/hwmon/pmbus/tps53679.c index 85b515cd9df0..2bc352c5357f 100644 --- a/drivers/hwmon/pmbus/tps53679.c +++ b/drivers/hwmon/pmbus/tps53679.c @@ -80,7 +80,14 @@ 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_kmemdup(&client->dev, &tps53679_info, sizeof(*info), + GFP_KERNEL); + if (!info) + return -ENOMEM; + + return pmbus_do_probe(client, id, info); } static const struct i2c_device_id tps53679_id[] = {
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") Signed-off-by: Vadim Pasternak <vadimp@mellanox.com> --- v1->v2: Comments pointed out by Guenter: - Use devm_kmemdup(). --- drivers/hwmon/pmbus/tps53679.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)