Skip to content

Commit 1f3a685

Browse files
mpegregkh
authored andcommitted
drivers/macintosh: Fix memleak in windfarm_pm112 driver
commit 93900337b9ac2f4eca427eff6d187be2dc3b5551 upstream. create_cpu_loop() calls smu_sat_get_sdb_partition() which does kmalloc() and returns the allocated buffer. In fact it's called twice, and neither buffer is freed. This results in a memory leak as reported by Erhard: unreferenced object 0xc00000047081f840 (size 32): comm "kwindfarm", pid 203, jiffies 4294880630 (age 5552.877s) hex dump (first 32 bytes): c8 06 02 7f ff 02 ff 01 fb bf 00 41 00 20 00 00 ...........A. .. 00 07 89 37 00 a0 00 00 00 00 00 00 00 00 00 00 ...7............ backtrace: [<0000000083f0a65c>] .smu_sat_get_sdb_partition+0xc4/0x2d0 [windfarm_smu_sat] [<000000003010fcb7>] .pm112_wf_notify+0x104c/0x13bc [windfarm_pm112] [<00000000b958b2dd>] .notifier_call_chain+0xa8/0x180 [<0000000070490868>] .blocking_notifier_call_chain+0x64/0x90 [<00000000131d8149>] .wf_thread_func+0x114/0x1a0 [<000000000d54838d>] .kthread+0x13c/0x190 [<00000000669b72bc>] .ret_from_kernel_thread+0x58/0x64 unreferenced object 0xc0000004737089f0 (size 16): comm "kwindfarm", pid 203, jiffies 4294880879 (age 5552.050s) hex dump (first 16 bytes): c4 04 01 7f 22 11 e0 e6 ff 55 7b 12 ec 11 00 00 ...."....U{..... backtrace: [<0000000083f0a65c>] .smu_sat_get_sdb_partition+0xc4/0x2d0 [windfarm_smu_sat] [<00000000b94ef7e1>] .pm112_wf_notify+0x1294/0x13bc [windfarm_pm112] [<00000000b958b2dd>] .notifier_call_chain+0xa8/0x180 [<0000000070490868>] .blocking_notifier_call_chain+0x64/0x90 [<00000000131d8149>] .wf_thread_func+0x114/0x1a0 [<000000000d54838d>] .kthread+0x13c/0x190 [<00000000669b72bc>] .ret_from_kernel_thread+0x58/0x64 Fix it by rearranging the logic so we deal with each buffer separately, which then makes it easy to free the buffer once we're done with it. Fixes: ac171c4 ("[PATCH] powerpc: Thermal control for dual core G5s") Cc: [email protected] # v2.6.16+ Reported-by: Erhard F. <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Tested-by: Erhard F. <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 25c2d1f commit 1f3a685

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/macintosh/windfarm_pm112.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/device.h>
1414
#include <linux/platform_device.h>
1515
#include <linux/reboot.h>
16+
#include <linux/slab.h>
1617
#include <asm/prom.h>
1718
#include <asm/smu.h>
1819

@@ -133,14 +134,6 @@ static int create_cpu_loop(int cpu)
133134
s32 tmax;
134135
int fmin;
135136

136-
/* Get PID params from the appropriate SAT */
137-
hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
138-
if (hdr == NULL) {
139-
printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
140-
return -EINVAL;
141-
}
142-
piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
143-
144137
/* Get FVT params to get Tmax; if not found, assume default */
145138
hdr = smu_sat_get_sdb_partition(chip, 0xC4 + core, NULL);
146139
if (hdr) {
@@ -153,6 +146,16 @@ static int create_cpu_loop(int cpu)
153146
if (tmax < cpu_all_tmax)
154147
cpu_all_tmax = tmax;
155148

149+
kfree(hdr);
150+
151+
/* Get PID params from the appropriate SAT */
152+
hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
153+
if (hdr == NULL) {
154+
printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
155+
return -EINVAL;
156+
}
157+
piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
158+
156159
/*
157160
* Darwin has a minimum fan speed of 1000 rpm for the 4-way and
158161
* 515 for the 2-way. That appears to be overkill, so for now,
@@ -175,6 +178,9 @@ static int create_cpu_loop(int cpu)
175178
pid.min = fmin;
176179

177180
wf_cpu_pid_init(&cpu_pid[cpu], &pid);
181+
182+
kfree(hdr);
183+
178184
return 0;
179185
}
180186

0 commit comments

Comments
 (0)