Skip to content

Commit c9284b7

Browse files
Chunyu-HuZhengShunQian
authored andcommitted
cpufreq: cppc_cpufreq: Fix cppc_cpufreq_init() failure path
[ Upstream commit 55b55ab ] Kmemleak reported the below leak. When cppc_cpufreq_init went into failure path, the cpu mask is not freed. After fix, this report is gone. And to avaoid potential NULL pointer reference, check the cpu value first. unreferenced object 0xffff800fd5ea4880 (size 128): comm "swapper/0", pid 1, jiffies 4294939510 (age 668.680s) hex dump (first 32 bytes): 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 .... ........... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<ffff0000082c4ae4>] __kmalloc_node+0x278/0x634 [<ffff0000088f4a74>] alloc_cpumask_var_node+0x28/0x60 [<ffff0000088f4af0>] zalloc_cpumask_var+0x14/0x1c [<ffff000008d20254>] cppc_cpufreq_init+0xd0/0x19c [<ffff000008083828>] do_one_initcall+0xec/0x15c [<ffff000008cd1018>] kernel_init_freeable+0x1f4/0x2a4 [<ffff0000089099b0>] kernel_init+0x18/0x10c [<ffff000008084d50>] ret_from_fork+0x10/0x18 [<ffffffffffffffff>] 0xffffffffffffffff Signed-off-by: Chunyu Hu <[email protected]> Acked-by: Viresh Kumar <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8b88006 commit c9284b7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ static int __init cppc_cpufreq_init(void)
176176
return ret;
177177

178178
out:
179-
for_each_possible_cpu(i)
180-
kfree(all_cpu_data[i]);
179+
for_each_possible_cpu(i) {
180+
cpu = all_cpu_data[i];
181+
if (!cpu)
182+
break;
183+
free_cpumask_var(cpu->shared_cpu_map);
184+
kfree(cpu);
185+
}
181186

182187
kfree(all_cpu_data);
183188
return -ENODEV;

0 commit comments

Comments
 (0)