]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (coretemp) replace hardcoded core count with dynamic value
authorRoman Bakshansky <bakshansky.lists@gmail.com>
Sat, 16 May 2026 11:42:52 +0000 (14:42 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 9 Jun 2026 15:23:00 +0000 (08:23 -0700)
The hardcoded maximum of 512 cores per package was first defined by commit
34cf8c657cf0 ("hwmon: (coretemp) Enlarge per package core count limit")
and later kept as a fallback with a TODO in commit 1a793caf6f69 ("hwmon:
(coretemp) Use dynamic allocated memory for core temp_data") because the
actual per-package core count was not reliably available at the time.

Now that topology_num_cores_per_package() is stable and suitable for use,
it's time to complete the TODO and allocate only the needed amount of
memory for core_data.

Signed-off-by: Roman Bakshansky <bakshansky.lists@gmail.com>
Link: https://lore.kernel.org/r/20260516114253.5466-2-bakshansky.lists@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/coretemp.c

index 6a0d94711eadb8923181725a39252807ae811e94..c722b1d8e480458a96dfd320dcc3771e5ffac371 100644 (file)
@@ -39,7 +39,6 @@ static int force_tjmax;
 module_param_named(tjmax, force_tjmax, int, 0444);
 MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
 
-#define NUM_REAL_CORES         512     /* Number of Real cores per cpu */
 #define CORETEMP_NAME_LENGTH   28      /* String Length of attrs */
 
 enum coretemp_attr_index {
@@ -485,13 +484,7 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag)
        struct temp_data *tdata;
 
        if (!pdata->core_data) {
-               /*
-                * TODO:
-                * The information of actual possible cores in a package is broken for now.
-                * Will replace hardcoded NUM_REAL_CORES with actual per package core count
-                * when this information becomes available.
-                */
-               pdata->nr_cores = NUM_REAL_CORES;
+               pdata->nr_cores = topology_num_cores_per_package();
                pdata->core_data = kzalloc_objs(struct temp_data *,
                                                pdata->nr_cores);
                if (!pdata->core_data)