* [PATCH v1 hwmon] hwmon: (pmbus) Fix driver info initialization in probe routine
@ 2019-02-17 17:41 Vadim Pasternak
2019-02-18 15:58 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Vadim Pasternak @ 2019-02-17 17:41 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, 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")
Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
---
drivers/hwmon/pmbus/tps53679.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/pmbus/tps53679.c b/drivers/hwmon/pmbus/tps53679.c
index 85b515cd9df0..45eacc504e2f 100644
--- a/drivers/hwmon/pmbus/tps53679.c
+++ b/drivers/hwmon/pmbus/tps53679.c
@@ -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[] = {
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1 hwmon] hwmon: (pmbus) Fix driver info initialization in probe routine
2019-02-17 17:41 [PATCH v1 hwmon] hwmon: (pmbus) Fix driver info initialization in probe routine Vadim Pasternak
@ 2019-02-18 15:58 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2019-02-18 15:58 UTC (permalink / raw)
To: Vadim Pasternak; +Cc: linux-hwmon
Hi,
On Sun, Feb 17, 2019 at 05:41:55PM +0000, 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>
> ---
> drivers/hwmon/pmbus/tps53679.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/pmbus/tps53679.c b/drivers/hwmon/pmbus/tps53679.c
> index 85b515cd9df0..45eacc504e2f 100644
> --- a/drivers/hwmon/pmbus/tps53679.c
> +++ b/drivers/hwmon/pmbus/tps53679.c
> @@ -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));
> +
Good find, but why not use devm_kmemdup() ?
Thanks,
Guenter
> + return pmbus_do_probe(client, id, info);
> }
>
> static const struct i2c_device_id tps53679_id[] = {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-18 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-17 17:41 [PATCH v1 hwmon] hwmon: (pmbus) Fix driver info initialization in probe routine Vadim Pasternak
2019-02-18 15:58 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).