Live Patching
 help / color / mirror / Atom feed
* [PATCH] selftests/livepatch: fix resource leak in test_klp_syscall init error path
@ 2026-06-02 12:45 Rui Qi
  2026-06-03 13:09 ` Miroslav Benes
  2026-06-04  8:32 ` [PATCH v2] " Rui Qi
  0 siblings, 2 replies; 9+ messages in thread
From: Rui Qi @ 2026-06-02 12:45 UTC (permalink / raw)
  To: jpoimboe, jikos, mbenes, pmladek
  Cc: joe.lawrence, shuah, live-patching, linux-kselftest, linux-kernel,
	Rui Qi

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 <qirui.001@bytedance.com>
---
 .../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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-06-09 11:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 12:45 [PATCH] selftests/livepatch: fix resource leak in test_klp_syscall init error path Rui Qi
2026-06-03 13:09 ` Miroslav Benes
2026-06-04  8:10   ` Rui Qi
2026-06-04  8:32 ` [PATCH v2] " Rui Qi
2026-06-04  8:42   ` sashiko-bot
2026-06-04 13:09     ` Petr Mladek
2026-06-04 13:12   ` Petr Mladek
2026-06-05  6:51   ` Miroslav Benes
2026-06-09 11:04   ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox