All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chengguang Xu <cgxu519@gmx.com>
To: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net
Cc: v9fs-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Chengguang Xu <cgxu519@gmx.com>
Subject: [PATCH 2/2] fs/9p: detecting invalid options as much as possible
Date: Mon, 16 Apr 2018 15:48:29 +0800	[thread overview]
Message-ID: <1523864909-4337-2-git-send-email-cgxu519@gmx.com> (raw)
In-Reply-To: <1523864909-4337-1-git-send-email-cgxu519@gmx.com>

Currently when detecting invalid options in option parsing,
some options(e.g. debug) just set errno and allow to continusly
validate other options so that it can detect invalid options
as much as possible and give proper error messages together.

This patch apply this policy to all options and the case of memory
allocation error in option parsing.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/9p/v9fs.c | 49 ++++++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index e622f0f..29ba937 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -192,10 +192,9 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 		return 0;
 
 	tmp_options = kstrdup(opts, GFP_KERNEL);
-	if (!tmp_options) {
-		ret = -ENOMEM;
-		goto fail_option_alloc;
-	}
+	if (!tmp_options)
+		return -ENOMEM;
+
 	options = tmp_options;
 
 	while ((p = strsep(&options, ",")) != NULL) {
@@ -263,18 +262,16 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 		case Opt_uname:
 			kfree(v9ses->uname);
 			v9ses->uname = match_strdup(&args[0]);
-			if (!v9ses->uname) {
-				ret = -ENOMEM;
-				goto free_and_return;
-			}
+			if (!v9ses->uname)
+				if (!ret)
+					ret = -ENOMEM;
 			break;
 		case Opt_remotename:
 			kfree(v9ses->aname);
 			v9ses->aname = match_strdup(&args[0]);
-			if (!v9ses->aname) {
-				ret = -ENOMEM;
-				goto free_and_return;
-			}
+			if (!v9ses->aname)
+				if (!ret)
+					ret = -ENOMEM;
 			break;
 		case Opt_nodevmap:
 			v9ses->nodev = 1;
@@ -292,24 +289,24 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 #ifdef CONFIG_9P_FSCACHE
 			kfree(v9ses->cachetag);
 			v9ses->cachetag = match_strdup(&args[0]);
-			if (!v9ses->cachetag) {
-				ret = -ENOMEM;
-				goto free_and_return;
-			}
+			if (!v9ses->cachetag)
+				if (!ret)
+					ret = -ENOMEM;
 #endif
 			break;
 		case Opt_cache:
 			s = match_strdup(&args[0]);
 			if (!s) {
-				ret = -ENOMEM;
+				if (!ret)
+					ret = -ENOMEM;
 				p9_debug(P9_DEBUG_ERROR,
 					 "problem allocating copy of cache arg\n");
-				goto free_and_return;
+				continue;
 			}
 			ret = get_cache_mode(s);
 			if (ret == -EINVAL) {
 				kfree(s);
-				goto free_and_return;
+				continue;
 			}
 
 			v9ses->cache = ret;
@@ -319,10 +316,11 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 		case Opt_access:
 			s = match_strdup(&args[0]);
 			if (!s) {
-				ret = -ENOMEM;
+				if (!ret)
+					ret = -ENOMEM;
 				p9_debug(P9_DEBUG_ERROR,
 					 "problem allocating copy of access arg\n");
-				goto free_and_return;
+				continue;
 			}
 
 			v9ses->flags &= ~V9FS_ACCESS_MASK;
@@ -341,14 +339,14 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 					pr_info("Unknown access argument %s\n",
 						s);
 					kfree(s);
-					goto free_and_return;
+					continue;
 				}
 				v9ses->uid = make_kuid(current_user_ns(), uid);
 				if (!uid_valid(v9ses->uid)) {
 					ret = -EINVAL;
 					pr_info("Uknown uid %s\n", s);
 					kfree(s);
-					goto free_and_return;
+					continue;
 				}
 			}
 
@@ -365,13 +363,14 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 			break;
 
 		default:
+			p9_debug(P9_DEBUG_ERROR,
+				"unrecognized mount option \"%s\" or missing value\n",
+					p);
 			continue;
 		}
 	}
 
-free_and_return:
 	kfree(tmp_options);
-fail_option_alloc:
 	return ret;
 }
 
-- 
1.8.3.1

  reply	other threads:[~2018-04-16  7:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16  7:48 [PATCH 1/2] net/9p: detecting invalid options as much as possible Chengguang Xu
2018-04-16  7:48 ` Chengguang Xu [this message]
2018-04-16  7:56   ` [V9fs-developer] [PATCH 2/2] fs/9p: " Dominique Martinet
2018-04-16 11:37     ` cgxu519

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523864909-4337-2-git-send-email-cgxu519@gmx.com \
    --to=cgxu519@gmx.com \
    --cc=ericvh@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucho@ionkov.net \
    --cc=rminnich@sandia.gov \
    --cc=v9fs-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.