Skip to contentSkip to conversation

f2fs: add sanity check for proc_mkdir

PATCH Superseded Yangtao Li 3 participants 3 messages Apr 6, 2023 – Apr 23, 2023 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 f2fs: add sanity check for proc_mkdir

Return -ENOMEM when proc_mkdir failed.

---
 fs/f2fs/sysfs.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/sysfs.c +12 -5
index 3aad3500a701..dcd497e0920a 100644
@@ -1385,12 +1385,19 @@ int __init f2fs_init_sysfs(void)
 
 	ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
 				   NULL, "features");
-	if (ret) {
-		kobject_put(&f2fs_feat);
-		kset_unregister(&f2fs_kset);
-	} else {
-		f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
+	if (ret)
+		goto put_kobject;
+
+	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;
 }
 
Signature · 1 line
2.35.1
#1 lore raw
Quoted 1 line · Yangtao Li

Return -ENOMEM when proc_mkdir failed.

When out of memory (memory allocation fail)?

Signature · 1 line
An old man doll... just what I always wanted! - Clara
maintainer
#2 lore raw
In reply to Yangtao Li
Quoted 15 lines · Yangtao Li

Return -ENOMEM when proc_mkdir failed.

---
  fs/f2fs/sysfs.c | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/sysfs.c +0 -0
index 3aad3500a701..dcd497e0920a 100644
@@ -1385,12 +1385,19 @@ int __init f2fs_init_sysfs(void)
 
  	ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
  				   NULL, "features");

fs/f2fs/sysfs.c int __init f2fs_init_sysfs(void) · line 1392

Quoted 10 lines
fs/f2fs/sysfs.c +5 -5
-	if (ret) {
-		kobject_put(&f2fs_feat);
-		kset_unregister(&f2fs_kset);
-	} else {
-		f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
+	if (ret)
+		goto put_kobject;
+
+	f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
+	if (!f2fs_proc_root) {

How about removing below check for f2fs_proc_root in f2fs_register_sysfs()?

	if (f2fs_proc_root)
		sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);

Thanks,

fs/f2fs/sysfs.c int __init f2fs_init_sysfs(void) · line 1403

Quoted 11 lines
fs/f2fs/sysfs.c +7 -0
+		ret = -ENOMEM;
+		goto put_kobject;
  	}
+
+	return 0;
+put_kobject:
+	kobject_put(&f2fs_feat);
+	kset_unregister(&f2fs_kset);
  	return ret;
  }
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel