linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Panteleev <git@thecybershadow.net>
To: linux-btrfs@vger.kernel.org
Cc: Vladimir Panteleev <git@thecybershadow.net>
Subject: [PATCH 1/1] btrfs: Simplify parsing max_inline mount option
Date: Thu, 15 Aug 2019 02:04:53 +0000	[thread overview]
Message-ID: <20190815020453.25150-2-git@thecybershadow.net> (raw)
In-Reply-To: <20190815020453.25150-1-git@thecybershadow.net>

- Avoid an allocation;
- Properly handle non-numerical argument and garbage after numerical
  argument.

Signed-off-by: Vladimir Panteleev <git@thecybershadow.net>
---
 fs/btrfs/super.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index f56617dfb3cf..6fe8ef6667f3 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -426,7 +426,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 			unsigned long new_flags)
 {
 	substring_t args[MAX_OPT_ARGS];
-	char *p, *num;
+	char *p, *retptr;
 	u64 cache_gen;
 	int intarg;
 	int ret = 0;
@@ -630,22 +630,16 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 			info->thread_pool_size = intarg;
 			break;
 		case Opt_max_inline:
-			num = match_strdup(&args[0]);
-			if (num) {
-				info->max_inline = memparse(num, NULL);
-				kfree(num);
-
-				if (info->max_inline) {
-					info->max_inline = min_t(u64,
-						info->max_inline,
-						info->sectorsize);
-				}
-				btrfs_info(info, "max_inline at %llu",
-					   info->max_inline);
-			} else {
-				ret = -ENOMEM;
+			info->max_inline = memparse(args[0].from, &retptr);
+			if (retptr != args[0].to || info->max_inline == 0) {
+				ret = -EINVAL;
 				goto out;
 			}
+			info->max_inline = min_t(u64,
+				info->max_inline,
+				info->sectorsize);
+			btrfs_info(info, "max_inline at %llu",
+				   info->max_inline);
 			break;
 		case Opt_alloc_start:
 			btrfs_info(info,
-- 
2.22.0


  reply	other threads:[~2019-08-15  2:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-15  2:04 [PATCH 0/1] btrfs: Simplify parsing max_inline mount option Vladimir Panteleev
2019-08-15  2:04 ` Vladimir Panteleev [this message]
2019-08-15  4:54   ` [PATCH 1/1] " Anand Jain
2019-08-15 14:54     ` Vladimir Panteleev
2019-08-21 14:35   ` David Sterba
2019-08-21 15:16     ` Vladimir Panteleev
2019-08-21 16:08       ` David Sterba

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=20190815020453.25150-2-git@thecybershadow.net \
    --to=git@thecybershadow.net \
    --cc=linux-btrfs@vger.kernel.org \
    /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 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).