Re: [PATCH 2/2] platform/x86/intel: power-domains: Handle failed init in tpmi_get_power_domain_mask()
From: srinivas pandruvada
Date: Thu Sep 24 2026 - 17:43:53 EST
On Thu, 2026-09-24 at 12:36 -0700, Kristen Carlson Accardi wrote:
> tpmi_init() returns early on CPU models that are not in tpmi_cpu_ids,
> before tpmi_power_domain_mask is allocated. When the driver is built
> in, the exported tpmi_get_power_domain_mask() remains callable after
> the failed init. It returns NULL then only because it indexes the
> NULL
> array at offset 0 for the zeroed per-CPU data. If cpuhp_setup_state()
> fails, the error path frees the array but leaves the pointer set, so
> the helper would return a pointer into freed memory.
>
> Nothing in the tree calls tpmi_get_power_domain_mask() today, so this
> is hardening rather than a fix for a reachable bug. Return NULL when
> the array was not allocated, and clear the pointer wherever it is
> freed, as the previous patch does for domain_die_map.
>
> Assisted-by: LLM
> Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@xxxxxxxxx>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>
> ---
> drivers/platform/x86/intel/tpmi_power_domains.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/platform/x86/intel/tpmi_power_domains.c
> b/drivers/platform/x86/intel/tpmi_power_domains.c
> index ea51fc56297d..d89b9894c42a 100644
> --- a/drivers/platform/x86/intel/tpmi_power_domains.c
> +++ b/drivers/platform/x86/intel/tpmi_power_domains.c
> @@ -139,6 +139,13 @@ cpumask_t *tpmi_get_power_domain_mask(int
> cpu_no)
> cpumask_t *mask;
> int index;
>
> + /*
> + * When built in, this stays callable after tpmi_init()
> failed
> + * before allocating the array.
> + */
> + if (!tpmi_power_domain_mask)
> + return NULL;
> +
> if (cpu_no >= num_possible_cpus())
> return NULL;
>
> @@ -256,6 +263,7 @@ static int __init tpmi_init(void)
>
> free_domain_mask:
> kfree(tpmi_power_domain_mask);
> + tpmi_power_domain_mask = NULL;
>
> return ret;
> }
> @@ -265,6 +273,7 @@ static void __exit tpmi_exit(void)
> {
> cpuhp_remove_state(tpmi_hp_state);
> kfree(tpmi_power_domain_mask);
> + tpmi_power_domain_mask = NULL;
> kfree(domain_die_map);
> domain_die_map = NULL;
> }