Re: [PATCH 1/1] cpufreq: prevent NULL dereference in cpufreq_online
From: Rafael J. Wysocki
Date: Wed Feb 05 2025 - 15:04:21 EST
On Wed, Feb 5, 2025 at 7:14 PM Aboorva Devarajan <aboorvad@xxxxxxxxxxxxx> wrote:
>
> Ensure `cpufreq_driver->set_boost` is non-NULL before using it in
> `cpufreq_online` to prevent a potential NULL pointer dereference.
>
> Reported-by: Gautam Menghani <gautam@xxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/c9e56c5f54cc33338762c94e9bed7b5a0d5de812.camel@xxxxxxxxxxxxx/
> Fixes: dd016f379ebc ("cpufreq: Introduce a more generic way to set default per-policy boost flag")
> Suggested-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>
> Signed-off-by: Aboorva Devarajan <aboorvad@xxxxxxxxxxxxx>
> ---
> drivers/cpufreq/cpufreq.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index e0048856ecee..30ffbddc7ece 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1571,7 +1571,8 @@ static int cpufreq_online(unsigned int cpu)
> policy->cdev = of_cpufreq_cooling_register(policy);
>
> /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */
> - if (policy->boost_enabled != cpufreq_boost_enabled()) {
> + if (cpufreq_driver->set_boost &&
> + policy->boost_enabled != cpufreq_boost_enabled()) {
> policy->boost_enabled = cpufreq_boost_enabled();
> ret = cpufreq_driver->set_boost(policy, policy->boost_enabled);
> if (ret) {
> --
Applied as 6.14-rc material, thanks!