Skip to content

Commit 81114fc

Browse files
Eliav Farbergroeck
authored andcommitted
hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined
Bug - in case "intel,vm-map" is missing in device-tree ,'num' is set to 0, and no voltage channel infos are allocated. The reason num is set to 0 when "intel,vm-map" is missing is to set the entire pvt->vm_idx[] with incremental channel numbers, but it didn't take into consideration that same num is used later in devm_kcalloc(). If "intel,vm-map" does exist there is no need to set the unspecified channels with incremental numbers, because the unspecified channels can't be accessed in pvt_read_in() which is the only other place besides the probe functions that uses pvt->vm_idx[]. This change fixes the bug by moving the incremental channel numbers setting to be done only if "intel,vm-map" property is defined (starting loop from 0), and removing 'num = 0'. Fixes: 9d82335 ("hwmon: Add hardware monitoring driver for Moortec MR75203 PVT controller") Signed-off-by: Eliav Farber <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent d0b34d5 commit 81114fc

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/hwmon/mr75203.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,12 @@ static int mr75203_probe(struct platform_device *pdev)
584584
ret = device_property_read_u8_array(dev, "intel,vm-map",
585585
pvt->vm_idx, vm_num);
586586
if (ret) {
587-
num = 0;
587+
/*
588+
* Incase intel,vm-map property is not defined, we
589+
* assume incremental channel numbers.
590+
*/
591+
for (i = 0; i < vm_num; i++)
592+
pvt->vm_idx[i] = i;
588593
} else {
589594
for (i = 0; i < vm_num; i++)
590595
if (pvt->vm_idx[i] >= vm_num ||
@@ -594,13 +599,6 @@ static int mr75203_probe(struct platform_device *pdev)
594599
}
595600
}
596601

597-
/*
598-
* Incase intel,vm-map property is not defined, we assume
599-
* incremental channel numbers.
600-
*/
601-
for (i = num; i < vm_num; i++)
602-
pvt->vm_idx[i] = i;
603-
604602
in_config = devm_kcalloc(dev, num + 1,
605603
sizeof(*in_config), GFP_KERNEL);
606604
if (!in_config)

0 commit comments

Comments
 (0)