Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: a907f3a68ee26ba4 ("f2fs: add a sysfs entry to reclaim POSIX_FADV_NOREUSE pages")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Guangshuo Li and committed by
Jaegeuk Kim
b635f2ec 5909bedb

+6 -4
+6 -4
fs/f2fs/sysfs.c
··· 1997 1997 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, 1998 1998 NULL, "features"); 1999 1999 if (ret) 2000 - goto put_kobject; 2000 + goto unregister_kset; 2001 2001 2002 2002 ret = kobject_init_and_add(&f2fs_tune, &f2fs_tune_ktype, 2003 2003 NULL, "tuning"); 2004 2004 if (ret) 2005 - goto put_kobject; 2005 + goto put_feat; 2006 2006 2007 2007 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 2008 2008 if (!f2fs_proc_root) { 2009 2009 ret = -ENOMEM; 2010 - goto put_kobject; 2010 + goto put_tune; 2011 2011 } 2012 2012 2013 2013 return 0; 2014 2014 2015 - put_kobject: 2015 + put_tune: 2016 2016 kobject_put(&f2fs_tune); 2017 + put_feat: 2017 2018 kobject_put(&f2fs_feat); 2019 + unregister_kset: 2018 2020 kset_unregister(&f2fs_kset); 2019 2021 return ret; 2020 2022 }