linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix return value of f2fs_set_qf_name and parse_options
@ 2018-08-11  6:49 Tiezhu Yang
  2018-08-13  2:55 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Tiezhu Yang @ 2018-08-11  6:49 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

match_strdup() returns NULL when kmalloc failed, so the caller
function f2fs_set_qf_name() should return -ENOMEM in this case;
match_int() returns -ENOMEM, -EINVAL, or -ERANGE on failure,
so the caller function parse_options() should not always return
-EINVAL in this case.

Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
---
 fs/f2fs/super.c | 60 +++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 19 deletions(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 53d70b6..bf6505e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -269,7 +269,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
 	if (!qname) {
 		f2fs_msg(sb, KERN_ERR,
 			"Not enough memory for storing quotafile name");
-		return -EINVAL;
+		return -ENOMEM;
 	}
 	if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
 		if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
@@ -366,9 +366,7 @@ static int parse_options(struct super_block *sb, char *options)
 	int arg = 0;
 	kuid_t uid;
 	kgid_t gid;
-#ifdef CONFIG_QUOTA
 	int ret;
-#endif
 
 	if (!options)
 		return 0;
@@ -452,8 +450,11 @@ static int parse_options(struct super_block *sb, char *options)
 			clear_opt(sbi, INLINE_XATTR);
 			break;
 		case Opt_inline_xattr_size:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 			set_opt(sbi, INLINE_XATTR_SIZE);
 			F2FS_OPTION(sbi).inline_xattr_size = arg;
 			break;
@@ -491,8 +492,11 @@ static int parse_options(struct super_block *sb, char *options)
 			break;
 #endif
 		case Opt_active_logs:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 			if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
 				return -EINVAL;
 			F2FS_OPTION(sbi).active_logs = arg;
@@ -534,8 +538,11 @@ static int parse_options(struct super_block *sb, char *options)
 			set_opt(sbi, DATA_FLUSH);
 			break;
 		case Opt_reserve_root:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 			if (test_opt(sbi, RESERVE_ROOT)) {
 				f2fs_msg(sb, KERN_INFO,
 					"Preserve previous reserve_root=%u",
@@ -546,8 +553,11 @@ static int parse_options(struct super_block *sb, char *options)
 			}
 			break;
 		case Opt_resuid:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 			uid = make_kuid(current_user_ns(), arg);
 			if (!uid_valid(uid)) {
 				f2fs_msg(sb, KERN_ERR,
@@ -557,8 +567,11 @@ static int parse_options(struct super_block *sb, char *options)
 			F2FS_OPTION(sbi).s_resuid = uid;
 			break;
 		case Opt_resgid:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 			gid = make_kgid(current_user_ns(), arg);
 			if (!gid_valid(gid)) {
 				f2fs_msg(sb, KERN_ERR,
@@ -592,8 +605,11 @@ static int parse_options(struct super_block *sb, char *options)
 			kfree(name);
 			break;
 		case Opt_io_size_bits:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 			if (arg > __ilog2_u32(BIO_MAX_PAGES)) {
 				f2fs_msg(sb, KERN_WARNING,
 					"Not support %d, larger than %d",
@@ -603,8 +619,11 @@ static int parse_options(struct super_block *sb, char *options)
 			F2FS_OPTION(sbi).write_io_size_bits = arg;
 			break;
 		case Opt_fault_injection:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 			f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE);
 			set_opt(sbi, FAULT_INJECTION);
@@ -614,8 +633,11 @@ static int parse_options(struct super_block *sb, char *options)
 #endif
 			break;
 		case Opt_fault_type:
-			if (args->from && match_int(args, &arg))
-				return -EINVAL;
+			if (args->from) {
+				ret = match_int(args, &arg);
+				if (ret)
+					return ret;
+			}
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 			f2fs_build_fault_attr(sbi, 0, arg);
 			set_opt(sbi, FAULT_INJECTION);
-- 
1.8.3.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] f2fs: fix return value of f2fs_set_qf_name and parse_options
  2018-08-11  6:49 [PATCH] f2fs: fix return value of f2fs_set_qf_name and parse_options Tiezhu Yang
@ 2018-08-13  2:55 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2018-08-13  2:55 UTC (permalink / raw)
  To: Tiezhu Yang, jaegeuk; +Cc: linux-f2fs-devel

On 2018/8/11 14:49, Tiezhu Yang wrote:
> match_strdup() returns NULL when kmalloc failed, so the caller
> function f2fs_set_qf_name() should return -ENOMEM in this case;
> match_int() returns -ENOMEM, -EINVAL, or -ERANGE on failure,
> so the caller function parse_options() should not always return
> -EINVAL in this case.
> 
> Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
> ---
>  fs/f2fs/super.c | 60 +++++++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 41 insertions(+), 19 deletions(-)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 53d70b6..bf6505e 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -269,7 +269,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
>  	if (!qname) {
>  		f2fs_msg(sb, KERN_ERR,
>  			"Not enough memory for storing quotafile name");
> -		return -EINVAL;
> +		return -ENOMEM;
>  	}
>  	if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
>  		if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
> @@ -366,9 +366,7 @@ static int parse_options(struct super_block *sb, char *options)
>  	int arg = 0;
>  	kuid_t uid;
>  	kgid_t gid;
> -#ifdef CONFIG_QUOTA
>  	int ret;
> -#endif
>  
>  	if (!options)
>  		return 0;
> @@ -452,8 +450,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			clear_opt(sbi, INLINE_XATTR);
>  			break;
>  		case Opt_inline_xattr_size:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;> +			}

if (args->from)
	return -EINVAL;
ret = match_init();
if (ret)
	return ret;

The same as below.

Thanks,

>  			set_opt(sbi, INLINE_XATTR_SIZE);
>  			F2FS_OPTION(sbi).inline_xattr_size = arg;
>  			break;
> @@ -491,8 +492,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			break;
>  #endif
>  		case Opt_active_logs:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  			if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
>  				return -EINVAL;
>  			F2FS_OPTION(sbi).active_logs = arg;
> @@ -534,8 +538,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			set_opt(sbi, DATA_FLUSH);
>  			break;
>  		case Opt_reserve_root:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  			if (test_opt(sbi, RESERVE_ROOT)) {
>  				f2fs_msg(sb, KERN_INFO,
>  					"Preserve previous reserve_root=%u",
> @@ -546,8 +553,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			}
>  			break;
>  		case Opt_resuid:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  			uid = make_kuid(current_user_ns(), arg);
>  			if (!uid_valid(uid)) {
>  				f2fs_msg(sb, KERN_ERR,
> @@ -557,8 +567,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			F2FS_OPTION(sbi).s_resuid = uid;
>  			break;
>  		case Opt_resgid:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  			gid = make_kgid(current_user_ns(), arg);
>  			if (!gid_valid(gid)) {
>  				f2fs_msg(sb, KERN_ERR,
> @@ -592,8 +605,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			kfree(name);
>  			break;
>  		case Opt_io_size_bits:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  			if (arg > __ilog2_u32(BIO_MAX_PAGES)) {
>  				f2fs_msg(sb, KERN_WARNING,
>  					"Not support %d, larger than %d",
> @@ -603,8 +619,11 @@ static int parse_options(struct super_block *sb, char *options)
>  			F2FS_OPTION(sbi).write_io_size_bits = arg;
>  			break;
>  		case Opt_fault_injection:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  #ifdef CONFIG_F2FS_FAULT_INJECTION
>  			f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE);
>  			set_opt(sbi, FAULT_INJECTION);
> @@ -614,8 +633,11 @@ static int parse_options(struct super_block *sb, char *options)
>  #endif
>  			break;
>  		case Opt_fault_type:
> -			if (args->from && match_int(args, &arg))
> -				return -EINVAL;
> +			if (args->from) {
> +				ret = match_int(args, &arg);
> +				if (ret)
> +					return ret;
> +			}
>  #ifdef CONFIG_F2FS_FAULT_INJECTION
>  			f2fs_build_fault_attr(sbi, 0, arg);
>  			set_opt(sbi, FAULT_INJECTION);
> 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-13  2:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-11  6:49 [PATCH] f2fs: fix return value of f2fs_set_qf_name and parse_options Tiezhu Yang
2018-08-13  2:55 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).