Jinjie Ruan
28926daf73
fpga: Fix memory leak for fpga_region_test_class_find()
...
fpga_region_class_find() in fpga_region_test_class_find() will call
get_device() if the data is matched, which will increment refcount for
dev->kobj, so it should call put_device() to decrement refcount for
dev->kobj to free the region, because fpga_region_unregister() will call
fpga_region_dev_release() only when the refcount for dev->kobj is zero
but fpga_region_test_init() call device_register() in
fpga_region_register_full(), which also increment refcount.
So call put_device() after calling fpga_region_class_find() in
fpga_region_test_class_find(). After applying this patch, the following
memory leak is never detected.
unreferenced object 0xffff88810c8ef000 (size 1024):
comm "kunit_try_catch", pid 1875, jiffies 4294715298 (age 836.836s)
hex dump (first 32 bytes):
b8 d1 fb 05 81 88 ff ff 08 f0 8e 0c 81 88 ff ff ................
08 f0 8e 0c 81 88 ff ff 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff817ebad7>] kmalloc_trace+0x27/0xa0
[<ffffffffa02385e1>] fpga_region_register_full+0x51/0x430 [fpga_region]
[<ffffffffa0228e47>] 0xffffffffa0228e47
[<ffffffff829c479d>] kunit_try_run_case+0xdd/0x250
[<ffffffff829c9f2a>] kunit_generic_run_threadfn_adapter+0x4a/0x90
[<ffffffff81238b85>] kthread+0x2b5/0x380
[<ffffffff81097ded>] ret_from_fork+0x2d/0x70
[<ffffffff810034d1>] ret_from_fork_asm+0x11/0x20
unreferenced object 0xffff888105fbd1b8 (size 8):
comm "kunit_try_catch", pid 1875, jiffies 4294715298 (age 836.836s)
hex dump (first 8 bytes):
72 65 67 69 6f 6e 30 00 region0.
backtrace:
[<ffffffff817ec023>] __kmalloc_node_track_caller+0x53/0x150
[<ffffffff82995590>] kvasprintf+0xb0/0x130
[<ffffffff83f713b1>] kobject_set_name_vargs+0x41/0x110
[<ffffffff8304ac1b>] dev_set_name+0xab/0xe0
[<ffffffffa02388a2>] fpga_region_register_full+0x312/0x430 [fpga_region]
[<ffffffffa0228e47>] 0xffffffffa0228e47
[<ffffffff829c479d>] kunit_try_run_case+0xdd/0x250
[<ffffffff829c9f2a>] kunit_generic_run_threadfn_adapter+0x4a/0x90
[<ffffffff81238b85>] kthread+0x2b5/0x380
[<ffffffff81097ded>] ret_from_fork+0x2d/0x70
[<ffffffff810034d1>] ret_from_fork_asm+0x11/0x20
unreferenced object 0xffff88810b3b8a00 (size 256):
comm "kunit_try_catch", pid 1875, jiffies 4294715298 (age 836.836s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 08 8a 3b 0b 81 88 ff ff ..........;.....
08 8a 3b 0b 81 88 ff ff e0 ac 04 83 ff ff ff ff ..;.............
backtrace:
[<ffffffff817ebad7>] kmalloc_trace+0x27/0xa0
[<ffffffff83056d7a>] device_add+0xa2a/0x15e0
[<ffffffffa02388b1>] fpga_region_register_full+0x321/0x430 [fpga_region]
[<ffffffffa0228e47>] 0xffffffffa0228e47
[<ffffffff829c479d>] kunit_try_run_case+0xdd/0x250
[<ffffffff829c9f2a>] kunit_generic_run_threadfn_adapter+0x4a/0x90
[<ffffffff81238b85>] kthread+0x2b5/0x380
[<ffffffff81097ded>] ret_from_fork+0x2d/0x70
[<ffffffff810034d1>] ret_from_fork_asm+0x11/0x20
Fixes: 64a5f972c93d ("fpga: add an initial KUnit suite for the FPGA Region")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Marco Pagani <marpagan@redhat.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20231007094321.3447084-1-ruanjinjie@huawei.com
[yilun.xu@intel.com: slightly changes the commit message]
Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Link: https://lore.kernel.org/r/20231023032857.902699-3-yilun.xu@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-24 19:32:39 +02:00
..
2023-10-24 19:32:39 +02:00
2021-11-28 13:59:13 -08:00
2023-07-17 09:23:04 +08:00
2023-07-17 09:23:04 +08:00
2021-11-28 14:02:13 -08:00
2023-07-17 09:23:04 +08:00
2022-06-10 15:48:23 +08:00
2021-11-28 13:59:13 -08:00
2020-06-18 18:12:06 -07:00
2021-03-24 11:15:04 -07:00
2021-03-24 11:15:04 -07:00
2023-01-28 23:33:43 +08:00
2023-01-28 23:33:43 +08:00
2021-11-28 14:02:13 -08:00
2020-07-06 21:35:42 -07:00
2023-07-10 14:41:53 +08:00
2023-07-10 16:41:44 +08:00
2023-01-28 23:33:43 +08:00
2023-01-28 23:33:05 +08:00
2023-01-28 23:33:43 +08:00
2021-11-28 14:02:41 -08:00
2020-04-28 15:49:28 +02:00
2021-07-21 19:54:21 -07:00
2023-08-07 18:21:40 +08:00
2023-02-24 12:58:55 -08:00
2023-02-24 12:47:33 -08:00
2023-08-11 23:03:37 +08:00
2023-08-11 23:04:03 +08:00
2023-08-11 23:04:21 +08:00
2021-11-28 13:59:13 -08:00
2023-06-15 09:19:36 +01:00
2023-07-23 14:04:50 +08:00
2023-04-06 20:36:27 +02:00
2022-10-25 14:44:03 +08:00
2022-10-25 14:44:03 +08:00
2021-11-28 13:59:13 -08:00
2023-07-23 14:04:50 +08:00
2023-07-17 09:23:04 +08:00
2023-07-17 09:23:04 +08:00
2023-07-15 22:46:58 +08:00
2023-07-10 16:48:04 +08:00
2023-07-17 09:23:04 +08:00
2023-07-10 16:52:58 +08:00
2021-11-28 13:59:13 -08:00
2023-07-10 16:44:48 +08:00
2021-11-28 13:59:13 -08:00
2023-07-10 16:55:06 +08:00
2023-03-09 17:33:19 +01:00