]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
hwmon: (peci/cputemp) Fix off-by-one in coretemp_label allocation
authorZev Weiss <zev@bewilderbeest.net>
Thu, 2 Feb 2023 02:18:25 +0000 (18:18 -0800)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 14 Mar 2023 15:47:34 +0000 (16:47 +0100)
BugLink: https://bugs.launchpad.net/bugs/2011425
commit f00093608fa790580da309bb9feb5108fbe7c331 upstream.

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.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Cc: stable@kernel.org # v5.18
Fixes: bf3608f338e9 ("hwmon: peci: Add cputemp driver")
Reviewed-by: Iwona Winiarska <iwona.winiarska@intel.com>
Link: https://lore.kernel.org/r/20230202021825.21486-1-zev@bewilderbeest.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
drivers/hwmon/peci/cputemp.c

index 57470fda5f6c91f46c02ff3563f8dbd781342527..30850a479f61fdf96b5ae1cdd985b09802575bdc 100644 (file)
@@ -402,7 +402,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;