In livepatch_init(), if klp_enable_patch() fails, the previously created kobject and sysfs file are never cleaned up, causing a resource leak. Capture the return value and add proper cleanup on the error path.
Signed-off-by: Rui Qi <[email protected]> --- .../selftests/livepatch/test_modules/test_klp_syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c b/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c index 0630ffd9d9a1..d631acae48b9 100644 --- a/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c @@ -109,7 +109,12 @@ static int livepatch_init(void) */ npids = npids_pending; - return klp_enable_patch(&patch); + ret = klp_enable_patch(&patch); + if (ret) { + sysfs_remove_file(klp_kobj, &klp_attr.attr); + kobject_put(klp_kobj); + } + return ret; } static void livepatch_exit(void) -- 2.20.1

