f2fs: add sanity check for proc_mkdir

Message ID 20230406193716.70796-1-frank.li@vivo.com
State New
Headers
Series f2fs: add sanity check for proc_mkdir |

Commit Message

李扬韬 April 6, 2023, 7:37 p.m. UTC
  Return -ENOMEM when proc_mkdir failed.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/sysfs.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
  

Comments

Chao Yu April 23, 2023, 4:03 p.m. UTC | #1
On 2023/4/7 3:37, Yangtao Li wrote:
> Return -ENOMEM when proc_mkdir failed.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>   fs/f2fs/sysfs.c | 17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 3aad3500a701..dcd497e0920a 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -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) {

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,

> +		ret = -ENOMEM;
> +		goto put_kobject;
>   	}
> +
> +	return 0;
> +put_kobject:
> +	kobject_put(&f2fs_feat);
> +	kset_unregister(&f2fs_kset);
>   	return ret;
>   }
>
  

Patch

diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 3aad3500a701..dcd497e0920a 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -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;
 }