Re: [PATCH] selftests/livepatch: fix resource leak in test_klp_syscall init error path

From
Miroslav Benes <mbenes@suse.cz>
Date
2026-06-03 13:09:45
Also in
linux-kselftest, lkml
Reply to
Rui Qi, 2026-06-02
On Tue, 02 Jun 2026 20:45:09 +0800, Rui Qi [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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;
Is sysfs_remove_file() needed? I think that kobject_put() should remove
it automatically since the object is bound to sysfs.

-- 
Miroslav
Thread (9 messages) 9 messages, 4 authors, last reply 2026-06-09
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help