Skip to content

Commit b635f2e

Browse files
lgs2513Jaegeuk Kim
authored andcommitted
f2fs: fix uninitialized kobject put in f2fs_init_sysfs()
In f2fs_init_sysfs(), all failure paths after kset_register() jump to put_kobject, which unconditionally releases both f2fs_tune and f2fs_feat. If kobject_init_and_add(&f2fs_feat, ...) fails, f2fs_tune has not been initialized yet, so calling kobject_put(&f2fs_tune) is invalid. Fix this by splitting the unwind path so each error path only releases objects that were successfully initialized. Fixes: a907f3a ("f2fs: add a sysfs entry to reclaim POSIX_FADV_NOREUSE pages") Cc: [email protected] Signed-off-by: Guangshuo Li <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 5909bed commit b635f2e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

fs/f2fs/sysfs.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,24 +1997,26 @@ int __init f2fs_init_sysfs(void)
19971997
ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
19981998
NULL, "features");
19991999
if (ret)
2000-
goto put_kobject;
2000+
goto unregister_kset;
20012001

20022002
ret = kobject_init_and_add(&f2fs_tune, &f2fs_tune_ktype,
20032003
NULL, "tuning");
20042004
if (ret)
2005-
goto put_kobject;
2005+
goto put_feat;
20062006

20072007
f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
20082008
if (!f2fs_proc_root) {
20092009
ret = -ENOMEM;
2010-
goto put_kobject;
2010+
goto put_tune;
20112011
}
20122012

20132013
return 0;
20142014

2015-
put_kobject:
2015+
put_tune:
20162016
kobject_put(&f2fs_tune);
2017+
put_feat:
20172018
kobject_put(&f2fs_feat);
2019+
unregister_kset:
20182020
kset_unregister(&f2fs_kset);
20192021
return ret;
20202022
}

0 commit comments

Comments
 (0)