From: Rui Qi Date: Thu, 4 Jun 2026 08:32:08 +0000 (+0800) Subject: selftests/livepatch: fix resource leak in test_klp_syscall init error path X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7203abb3f8bd61e021cce076dafdda7bcfd9f2c2;p=thirdparty%2Flinux.git selftests/livepatch: fix resource leak in test_klp_syscall init error path 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 Acked-by: Miroslav Benes Reviewed-by: Petr Mladek Link: https://patch.msgid.link/20260604083208.1071428-1-qirui.001@bytedance.com Signed-off-by: Petr Mladek --- 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..08aacc0e14de 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,11 @@ static int livepatch_init(void) */ npids = npids_pending; - return klp_enable_patch(&patch); + ret = klp_enable_patch(&patch); + if (ret) + kobject_put(klp_kobj); + + return ret; } static void livepatch_exit(void)