Skip to contentSkip to conversation

cpufreq: don't leave stale statistics pointer

PATCH In review Jan Beulich 2 participants 2 messages Apr 29, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: don't leave stale statistics pointer

Error paths of cpufreq_statistic_init() correctly free the base structure pointer, but the per-CPU variable would still hold it, mis- guiding e.g. cpufreq_statistic_update(). Defer installing of the pointer there until the structure was fully populated.

Fixes 755af07edba1 ("x86/cpufreq: don't use static array for large per-CPU data structures")
xen/drivers/cpufreq/utility.c +2 -1
@@ -113,7 +113,6 @@ int cpufreq_statistic_init(unsigned int
         spin_unlock(cpufreq_statistic_lock);
         return -ENOMEM;
     }
-    per_cpu(cpufreq_statistic_data, cpu) = pxpt;
 
     pxpt->u.trans_pt = xzalloc_array(uint64_t, count * count);
     if (!pxpt->u.trans_pt) {
@@ -139,6 +138,8 @@ int cpufreq_statistic_init(unsigned int
     pxpt->prev_state_wall = NOW();
     pxpt->prev_idle_wall = get_cpu_idle_time(cpu);
 
+    per_cpu(cpufreq_statistic_data, cpu) = pxpt;
+
     spin_unlock(cpufreq_statistic_lock);
 
     return 0;
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

Error paths of cpufreq_statistic_init() correctly free the base structure pointer, but the per-CPU variable would still hold it, mis- guiding e.g. cpufreq_statistic_update(). Defer installing of the pointer there until the structure was fully populated.

Fixes 755af07edba1 ("x86/cpufreq: don't use static array for large per-CPU data structures")