Commit 6b5cca7
clk: test: Fix some memory leaks
CONFIG_CLK_KUNIT_TEST=y, CONFIG_DEBUG_KMEMLEAK=y
and CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y, the following memory leak occurs.
If the KUNIT_ASSERT_*() fails, the latter (exit() or testcases)
clk_put() or clk_hw_unregister() will fail to release the clk resource
and cause memory leaks, use new clk_hw_register_kunit()
and clk_hw_get_clk_kunit() to automatically release them.
unreferenced object 0xffffff80c6af5000 (size 512):
comm "kunit_try_catch", pid 371, jiffies 4294896001
hex dump (first 32 bytes):
20 4c c0 86 e1 ff ff ff e0 1a c0 86 e1 ff ff ff L..............
c0 75 e3 c6 80 ff ff ff 00 00 00 00 00 00 00 00 .u..............
backtrace (crc 8ca788fa):
[<00000000e21852d0>] kmemleak_alloc+0x34/0x40
[<000000009c583f7b>] __kmalloc_cache_noprof+0x26c/0x2f4
[<00000000d1bc850c>] __clk_register+0x80/0x1ecc
[<00000000b08c78c5>] clk_hw_register+0xc4/0x110
[<00000000b16d6df8>] clk_multiple_parents_mux_test_init+0x238/0x288
[<0000000014a7e804>] kunit_try_run_case+0x10c/0x3ac
[<0000000026b41f03>] kunit_generic_run_threadfn_adapter+0x80/0xec
[<0000000066619fb8>] kthread+0x2e8/0x374
[<00000000a1157f53>] ret_from_fork+0x10/0x20
unreferenced object 0xffffff80c6e37880 (size 96):
comm "kunit_try_catch", pid 371, jiffies 4294896002
hex dump (first 32 bytes):
00 50 af c6 80 ff ff ff 00 00 00 00 00 00 00 00 .P..............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc b4b766dd):
[<00000000e21852d0>] kmemleak_alloc+0x34/0x40
[<000000009c583f7b>] __kmalloc_cache_noprof+0x26c/0x2f4
[<0000000086e7dd64>] clk_hw_create_clk.part.0.isra.0+0x58/0x2f4
[<00000000dcf1ac31>] clk_hw_get_clk+0x8c/0x114
[<000000006fab5bfa>] clk_test_multiple_parents_mux_set_range_set_parent_get_rate+0x3c/0xa0
[<00000000c97db55a>] kunit_try_run_case+0x13c/0x3ac
[<0000000026b41f03>] kunit_generic_run_threadfn_adapter+0x80/0xec
[<0000000066619fb8>] kthread+0x2e8/0x374
[<00000000a1157f53>] ret_from_fork+0x10/0x20
unreferenced object 0xffffff80c2b56900 (size 96):
comm "kunit_try_catch", pid 395, jiffies 4294896107
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 e0 49 c0 86 e1 ff ff ff .........I......
backtrace (crc 2e59b327):
[<00000000e21852d0>] kmemleak_alloc+0x34/0x40
[<00000000c6c715a8>] __kmalloc_noprof+0x2bc/0x3c0
[<00000000f04a7951>] __clk_register+0x70c/0x1ecc
[<00000000b08c78c5>] clk_hw_register+0xc4/0x110
[<00000000cafa9563>] clk_orphan_transparent_multiple_parent_mux_test_init+0x1a8/0x1dc
[<0000000014a7e804>] kunit_try_run_case+0x10c/0x3ac
[<0000000026b41f03>] kunit_generic_run_threadfn_adapter+0x80/0xec
[<0000000066619fb8>] kthread+0x2e8/0x374
[<00000000a1157f53>] ret_from_fork+0x10/0x20
unreferenced object 0xffffff80c87c9400 (size 512):
comm "kunit_try_catch", pid 483, jiffies 4294896907
hex dump (first 32 bytes):
a0 44 c0 86 e1 ff ff ff e0 1a c0 86 e1 ff ff ff .D..............
20 05 a8 c8 80 ff ff ff 00 00 00 00 00 00 00 00 ...............
backtrace (crc c25b43fb):
[<00000000e21852d0>] kmemleak_alloc+0x34/0x40
[<000000009c583f7b>] __kmalloc_cache_noprof+0x26c/0x2f4
[<00000000d1bc850c>] __clk_register+0x80/0x1ecc
[<00000000b08c78c5>] clk_hw_register+0xc4/0x110
[<000000002688be48>] clk_single_parent_mux_test_init+0x1a0/0x1d4
[<0000000014a7e804>] kunit_try_run_case+0x10c/0x3ac
[<0000000026b41f03>] kunit_generic_run_threadfn_adapter+0x80/0xec
[<0000000066619fb8>] kthread+0x2e8/0x374
[<00000000a1157f53>] ret_from_fork+0x10/0x20
unreferenced object 0xffffff80c6dd2380 (size 96):
comm "kunit_try_catch", pid 483, jiffies 4294896908
hex dump (first 32 bytes):
00 94 7c c8 80 ff ff ff 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 (crc 4401212):
[<00000000e21852d0>] kmemleak_alloc+0x34/0x40
[<000000009c583f7b>] __kmalloc_cache_noprof+0x26c/0x2f4
[<0000000086e7dd64>] clk_hw_create_clk.part.0.isra.0+0x58/0x2f4
[<00000000dcf1ac31>] clk_hw_get_clk+0x8c/0x114
[<0000000063eb2c90>] clk_test_single_parent_mux_set_range_disjoint_child_last+0x3c/0xa0
[<00000000c97db55a>] kunit_try_run_case+0x13c/0x3ac
[<0000000026b41f03>] kunit_generic_run_threadfn_adapter+0x80/0xec
[<0000000066619fb8>] kthread+0x2e8/0x374
[<00000000a1157f53>] ret_from_fork+0x10/0x20
......
Fixes: 02cdeac ("clk: tests: Add tests for single parent mux")
Fixes: 2e9cad1 ("clk: tests: Add some tests for orphan with multiple parents")
Fixes: 433fb8a ("clk: tests: Add missing test case for ranges")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/r/20241016022658.2131826-1-ruanjinjie@huawei.com
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>1 parent 23dbbe8 commit 6b5cca7
1 file changed
+14
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
484 | | - | |
| 484 | + | |
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
492 | | - | |
| 492 | + | |
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | 499 | | |
510 | 500 | | |
511 | 501 | | |
| |||
561 | 551 | | |
562 | 552 | | |
563 | 553 | | |
564 | | - | |
| 554 | + | |
565 | 555 | | |
566 | 556 | | |
567 | 557 | | |
568 | 558 | | |
569 | 559 | | |
570 | 560 | | |
571 | | - | |
| 561 | + | |
572 | 562 | | |
573 | 563 | | |
574 | 564 | | |
575 | | - | |
| 565 | + | |
576 | 566 | | |
577 | 567 | | |
578 | 568 | | |
| |||
593 | 583 | | |
594 | 584 | | |
595 | 585 | | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | 586 | | |
601 | 587 | | |
602 | 588 | | |
| |||
617 | 603 | | |
618 | 604 | | |
619 | 605 | | |
620 | | - | |
621 | 606 | | |
622 | 607 | | |
623 | 608 | | |
| |||
637 | 622 | | |
638 | 623 | | |
639 | 624 | | |
640 | | - | |
| 625 | + | |
641 | 626 | | |
642 | 627 | | |
643 | 628 | | |
644 | 629 | | |
645 | 630 | | |
646 | 631 | | |
647 | | - | |
| 632 | + | |
648 | 633 | | |
649 | 634 | | |
650 | 635 | | |
651 | 636 | | |
652 | 637 | | |
653 | 638 | | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | 639 | | |
664 | 640 | | |
665 | 641 | | |
| |||
912 | 888 | | |
913 | 889 | | |
914 | 890 | | |
915 | | - | |
| 891 | + | |
916 | 892 | | |
917 | 893 | | |
918 | 894 | | |
| |||
921 | 897 | | |
922 | 898 | | |
923 | 899 | | |
924 | | - | |
| 900 | + | |
925 | 901 | | |
926 | 902 | | |
927 | 903 | | |
| |||
931 | 907 | | |
932 | 908 | | |
933 | 909 | | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | 910 | | |
938 | 911 | | |
939 | 912 | | |
| |||
961 | 934 | | |
962 | 935 | | |
963 | 936 | | |
964 | | - | |
965 | 937 | | |
966 | 938 | | |
967 | 939 | | |
| |||
986 | 958 | | |
987 | 959 | | |
988 | 960 | | |
989 | | - | |
| 961 | + | |
990 | 962 | | |
991 | 963 | | |
992 | 964 | | |
993 | 965 | | |
994 | 966 | | |
995 | 967 | | |
996 | 968 | | |
997 | | - | |
| 969 | + | |
998 | 970 | | |
999 | 971 | | |
1000 | 972 | | |
| |||
1060 | 1032 | | |
1061 | 1033 | | |
1062 | 1034 | | |
1063 | | - | |
| 1035 | + | |
1064 | 1036 | | |
1065 | 1037 | | |
1066 | 1038 | | |
| |||
1074 | 1046 | | |
1075 | 1047 | | |
1076 | 1048 | | |
1077 | | - | |
1078 | | - | |
1079 | 1049 | | |
1080 | 1050 | | |
1081 | 1051 | | |
| |||
1092 | 1062 | | |
1093 | 1063 | | |
1094 | 1064 | | |
1095 | | - | |
| 1065 | + | |
1096 | 1066 | | |
1097 | 1067 | | |
1098 | 1068 | | |
| |||
1106 | 1076 | | |
1107 | 1077 | | |
1108 | 1078 | | |
1109 | | - | |
1110 | | - | |
1111 | 1079 | | |
1112 | 1080 | | |
1113 | 1081 | | |
| |||
1238 | 1206 | | |
1239 | 1207 | | |
1240 | 1208 | | |
1241 | | - | |
1242 | 1209 | | |
1243 | 1210 | | |
1244 | 1211 | | |
| |||
0 commit comments