aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang Shi <yang.shi@linaro.org>2016-11-10 16:06:39 -0500
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2017-01-15 00:36:06 -0500
commitf4dbba591945dc301c302672adefba9e2ec08dc5 (patch)
tree1f806fb2dbfee1fdea1759440a75848776fcd8c8
parentb1c14a39adcf2237f31bcd0cd858bed5c54f2aee (diff)
locktorture: Fix potential memory leak with rw lock test
When running locktorture module with the below commands with kmemleak enabled: $ modprobe locktorture torture_type=rw_lock_irq $ rmmod locktorture The below kmemleak got caught: root@10:~# echo scan > /sys/kernel/debug/kmemleak [ 323.197029] kmemleak: 2 new suspected memory leaks (see /sys/kernel/debug/kmemleak) root@10:~# cat /sys/kernel/debug/kmemleak unreferenced object 0xffffffc07592d500 (size 128): comm "modprobe", pid 368, jiffies 4294924118 (age 205.824s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 c3 7b 02 00 00 00 00 00 .........{...... 00 00 00 00 00 00 00 00 d7 9b 02 00 00 00 00 00 ................ backtrace: [<ffffff80081e5a88>] create_object+0x110/0x288 [<ffffff80086c6078>] kmemleak_alloc+0x58/0xa0 [<ffffff80081d5acc>] __kmalloc+0x234/0x318 [<ffffff80006fa130>] 0xffffff80006fa130 [<ffffff8008083ae4>] do_one_initcall+0x44/0x138 [<ffffff800817e28c>] do_init_module+0x68/0x1cc [<ffffff800811c848>] load_module+0x1a68/0x22e0 [<ffffff800811d340>] SyS_finit_module+0xe0/0xf0 [<ffffff80080836f0>] el0_svc_naked+0x24/0x28 [<ffffffffffffffff>] 0xffffffffffffffff unreferenced object 0xffffffc07592d480 (size 128): comm "modprobe", pid 368, jiffies 4294924118 (age 205.824s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 3b 6f 01 00 00 00 00 00 ........;o...... 00 00 00 00 00 00 00 00 23 6a 01 00 00 00 00 00 ........#j...... backtrace: [<ffffff80081e5a88>] create_object+0x110/0x288 [<ffffff80086c6078>] kmemleak_alloc+0x58/0xa0 [<ffffff80081d5acc>] __kmalloc+0x234/0x318 [<ffffff80006fa22c>] 0xffffff80006fa22c [<ffffff8008083ae4>] do_one_initcall+0x44/0x138 [<ffffff800817e28c>] do_init_module+0x68/0x1cc [<ffffff800811c848>] load_module+0x1a68/0x22e0 [<ffffff800811d340>] SyS_finit_module+0xe0/0xf0 [<ffffff80080836f0>] el0_svc_naked+0x24/0x28 [<ffffffffffffffff>] 0xffffffffffffffff It is because cxt.lwsa and cxt.lrsa don't get freed in module_exit, so free them in lock_torture_cleanup() and free writer_tasks if reader_tasks is failed at memory allocation. Signed-off-by: Yang Shi <yang.shi@linaro.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
-rw-r--r--kernel/locking/locktorture.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index f8c5af52a131..d3de04b12f8c 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -780,6 +780,10 @@ static void lock_torture_cleanup(void)
780 else 780 else
781 lock_torture_print_module_parms(cxt.cur_ops, 781 lock_torture_print_module_parms(cxt.cur_ops,
782 "End of test: SUCCESS"); 782 "End of test: SUCCESS");
783
784 kfree(cxt.lwsa);
785 kfree(cxt.lrsa);
786
783end: 787end:
784 torture_cleanup_end(); 788 torture_cleanup_end();
785} 789}
@@ -924,6 +928,8 @@ static int __init lock_torture_init(void)
924 GFP_KERNEL); 928 GFP_KERNEL);
925 if (reader_tasks == NULL) { 929 if (reader_tasks == NULL) {
926 VERBOSE_TOROUT_ERRSTRING("reader_tasks: Out of memory"); 930 VERBOSE_TOROUT_ERRSTRING("reader_tasks: Out of memory");
931 kfree(writer_tasks);
932 writer_tasks = NULL;
927 firsterr = -ENOMEM; 933 firsterr = -ENOMEM;
928 goto unwind; 934 goto unwind;
929 } 935 }