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

From: Miroslav Benes

Date: Wed Jun 03 2026 - 09:20:18 EST


On Tue, 02 Jun 2026 20:45:09 +0800, Rui Qi <qirui.001@xxxxxxxxxxxxx> wrote:
> 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