Skip to contentSkip to conversation

hwmon: (peci/cputemp) Fix off-by-one in coretemp_label allocation

PATCH Applied Zev Weiss 3 participants 3 messages Feb 2, 2023 – Feb 3, 2023

Subsystems (2)
lore
Share & tools
lore

Zev Weiss

author
#0 lore raw

PATCH 1/1 hwmon: (peci/cputemp) Fix off-by-one in coretemp_label allocation

The find_last_bit() call produces the index of the highest-numbered core in core_mask; because cores are numbered from zero, the number of elements we need to allocate is one more than that.

Fixes bf3608f338e9 ("hwmon: peci: Add cputemp driver")
---
 drivers/hwmon/peci/cputemp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/peci/cputemp.c +1 -1
index ec9851daf2e8..f13cc4170f58 100644
@@ -431,7 +431,7 @@ static int create_temp_label(struct peci_cputemp *priv)
 	unsigned long core_max = find_last_bit(priv->core_mask, CORE_NUMS_MAX);
 	int i;
 
-	priv->coretemp_label = devm_kzalloc(priv->dev, core_max * sizeof(char *), GFP_KERNEL);
+	priv->coretemp_label = devm_kzalloc(priv->dev, (core_max + 1) * sizeof(char *), GFP_KERNEL);
 	if (!priv->coretemp_label)
 		return -ENOMEM;
 
Signature · 1 line
2.39.1.236.ga8a28b9eace8
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Zev Weiss

The find_last_bit() call produces the index of the highest-numbered core in core_mask; because cores are numbered from zero, the number of elements we need to allocate is one more than that.

Cc [email protected] # v5.18
Fixes bf3608f338e9 ("hwmon: peci: Add cputemp driver")

Thanks for catching it.

Quoted 20 lines

---
 drivers/hwmon/peci/cputemp.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/peci/cputemp.c +0 -0
index ec9851daf2e8..f13cc4170f58 100644
@@ -431,7 +431,7 @@ static int create_temp_label(struct peci_cputemp *priv)
         unsigned long core_max = find_last_bit(priv->core_mask,
 CORE_NUMS_MAX);
         int i;


-       priv->coretemp_label = devm_kzalloc(priv->dev, core_max * sizeof(char *), GFP_KERNEL);
+       priv->coretemp_label = devm_kzalloc(priv->dev, (core_max + 1) * sizeof(char *), GFP_KERNEL);
        if (!priv->coretemp_label)
                return -ENOMEM;

maintainer Applied
#2 lore raw
In reply to Zev Weiss
Quoted 8 lines · Zev Weiss

The find_last_bit() call produces the index of the highest-numbered core in core_mask; because cores are numbered from zero, the number of elements we need to allocate is one more than that.

Fixes bf3608f338e9 ("hwmon: peci: Add cputemp driver")

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/peci/cputemp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/peci/cputemp.c +1 -1
index ec9851daf2e8..f13cc4170f58 100644
@@ -431,7 +431,7 @@ static int create_temp_label(struct peci_cputemp *priv)
 	unsigned long core_max = find_last_bit(priv->core_mask, CORE_NUMS_MAX);
 	int i;
 
-	priv->coretemp_label = devm_kzalloc(priv->dev, core_max * sizeof(char *), GFP_KERNEL);
+	priv->coretemp_label = devm_kzalloc(priv->dev, (core_max + 1) * sizeof(char *), GFP_KERNEL);
 	if (!priv->coretemp_label)
 		return -ENOMEM;