Skip to content

Commit 6dcf9d0

Browse files
lgs2513rafaeljw
authored andcommitted
cpufreq: governor: fix double free in cpufreq_dbs_governor_init() error path
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: 4ebe36c ("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>
1 parent 7aaa804 commit 6dcf9d0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/cpufreq/cpufreq_governor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
468468
/* Failure, so roll back. */
469469
pr_err("initialization failed (dbs_data kobject init error %d)\n", ret);
470470

471-
kobject_put(&dbs_data->attr_set.kobj);
472-
473471
policy->governor_data = NULL;
474472

475473
if (!have_governor_per_policy())
476474
gov->gdbs_data = NULL;
477-
gov->exit(dbs_data);
475+
476+
kobject_put(&dbs_data->attr_set.kobj);
477+
goto free_policy_dbs_info;
478478

479479
free_dbs_data:
480480
kfree(dbs_data);

0 commit comments

Comments
 (0)