Commit 888ca6ed authored by Yangtao Li's avatar Yangtao Li Committed by Jaegeuk Kim

f2fs: add sanity check for proc_mkdir

Return -ENOMEM when proc_mkdir failed.
Signed-off-by: default avatarYangtao Li <frank.li@vivo.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent b62e71be
...@@ -1386,12 +1386,19 @@ int __init f2fs_init_sysfs(void) ...@@ -1386,12 +1386,19 @@ int __init f2fs_init_sysfs(void)
ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
NULL, "features"); NULL, "features");
if (ret) { if (ret)
kobject_put(&f2fs_feat); goto put_kobject;
kset_unregister(&f2fs_kset);
} else { f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); if (!f2fs_proc_root) {
ret = -ENOMEM;
goto put_kobject;
} }
return 0;
put_kobject:
kobject_put(&f2fs_feat);
kset_unregister(&f2fs_kset);
return ret; return ret;
} }
...@@ -1430,23 +1437,24 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) ...@@ -1430,23 +1437,24 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
if (err) if (err)
goto put_feature_list_kobj; goto put_feature_list_kobj;
if (f2fs_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); if (!sbi->s_proc) {
err = -ENOMEM;
goto put_feature_list_kobj;
}
if (sbi->s_proc) { proc_create_single_data("segment_info", 0444, sbi->s_proc,
proc_create_single_data("segment_info", 0444, sbi->s_proc,
segment_info_seq_show, sb); segment_info_seq_show, sb);
proc_create_single_data("segment_bits", 0444, sbi->s_proc, proc_create_single_data("segment_bits", 0444, sbi->s_proc,
segment_bits_seq_show, sb); segment_bits_seq_show, sb);
#ifdef CONFIG_F2FS_IOSTAT #ifdef CONFIG_F2FS_IOSTAT
proc_create_single_data("iostat_info", 0444, sbi->s_proc, proc_create_single_data("iostat_info", 0444, sbi->s_proc,
iostat_info_seq_show, sb); iostat_info_seq_show, sb);
#endif #endif
proc_create_single_data("victim_bits", 0444, sbi->s_proc, proc_create_single_data("victim_bits", 0444, sbi->s_proc,
victim_bits_seq_show, sb); victim_bits_seq_show, sb);
proc_create_single_data("discard_plist_info", 0444, sbi->s_proc, proc_create_single_data("discard_plist_info", 0444, sbi->s_proc,
discard_plist_seq_show, sb); discard_plist_seq_show, sb);
}
return 0; return 0;
put_feature_list_kobj: put_feature_list_kobj:
kobject_put(&sbi->s_feature_list_kobj); kobject_put(&sbi->s_feature_list_kobj);
...@@ -1462,8 +1470,7 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) ...@@ -1462,8 +1470,7 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
{ {
if (sbi->s_proc) remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root);
remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root);
kobject_put(&sbi->s_stat_kobj); kobject_put(&sbi->s_stat_kobj);
wait_for_completion(&sbi->s_stat_kobj_unregister); wait_for_completion(&sbi->s_stat_kobj_unregister);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment