]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpufreq: governor: fix double free in cpufreq_dbs_governor_init() error path
authorGuangshuo Li <lgs201920130244@gmail.com>
Wed, 1 Apr 2026 02:45:35 +0000 (10:45 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 1 Apr 2026 14:08:15 +0000 (16:08 +0200)
When kobject_init_and_add() fails, cpufreq_dbs_governor_init() calls
kobject_put(&dbs_data->attr_set.kobj).

The kobject release callback cpufreq_dbs_data_release() calls
gov->exit(dbs_data) and kfree(dbs_data), but the current error path
then calls gov->exit(dbs_data) and kfree(dbs_data) again, causing a
double free.

Keep the direct kfree(dbs_data) for the gov->init() failure path, but
after kobject_init_and_add() has been called, let kobject_put() handle
the cleanup through cpufreq_dbs_data_release().

Fixes: 4ebe36c94aed ("cpufreq: Fix kobject memleak")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Cc: All applicable <stable@vger.kernel.org>
Link: https://patch.msgid.link/20260401024535.1395801-1-lgs201920130244@gmail.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq_governor.c

index acf101878733212f8ad81885de49e033b900cc83..86f35e45191423ebcfe22a463ccc57bc5031eec7 100644 (file)
@@ -468,13 +468,13 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
        /* Failure, so roll back. */
        pr_err("initialization failed (dbs_data kobject init error %d)\n", ret);
 
-       kobject_put(&dbs_data->attr_set.kobj);
-
        policy->governor_data = NULL;
 
        if (!have_governor_per_policy())
                gov->gdbs_data = NULL;
-       gov->exit(dbs_data);
+
+       kobject_put(&dbs_data->attr_set.kobj);
+       goto free_policy_dbs_info;
 
 free_dbs_data:
        kfree(dbs_data);