All of lore.kernel.org
 help / color / mirror / Atom feed
From: Integral <integral@archlinuxcn.org>
To: Kent Overstreet <kent.overstreet@linux.dev>,
	Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Integral <integral@archlinuxcn.org>
Subject: [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse()
Date: Sun,  6 Apr 2025 23:27:00 +0800	[thread overview]
Message-ID: <20250406152659.205997-3-integral@archlinuxcn.org> (raw)
In-Reply-To: <20250406152659.205997-2-integral@archlinuxcn.org>

Refactor if statements in bch2_opt_compression_parse() to make it
simpler & clearer.

Signed-off-by: Integral <integral@archlinuxcn.org>
---
 fs/bcachefs/compress.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index d68c3c7896a3..adf939b47107 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -713,10 +713,11 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
 	level_str = p;
 
 	ret = match_string(bch2_compression_opts, -1, type_str);
-	if (ret < 0 && err)
-		prt_str(err, "invalid compression type\n");
-	if (ret < 0)
+	if (ret < 0) {
+		if (err)
+			prt_str(err, "invalid compression type\n");
 		goto err;
+	}
 
 	opt.type = ret;
 
@@ -724,14 +725,13 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
 		unsigned level;
 
 		ret = kstrtouint(level_str, 10, &level);
-		if (!ret && !opt.type && level)
-			ret = -EINVAL;
-		if (!ret && level > 15)
+		if (!ret && ((!opt.type && level) || level > 15))
 			ret = -EINVAL;
-		if (ret < 0 && err)
-			prt_str(err, "invalid compression level\n");
-		if (ret < 0)
+		if (ret < 0) {
+			if (err)
+				prt_str(err, "invalid compression level\n");
 			goto err;
+		}
 
 		opt.level = level;
 	}
-- 
2.49.0


  reply	other threads:[~2025-04-06 15:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-06 15:26 [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Integral
2025-04-06 15:27 ` Integral [this message]
2025-04-06 17:37   ` [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse() Kent Overstreet
2025-04-06 17:35 ` [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Kent Overstreet

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=20250406152659.205997-3-integral@archlinuxcn.org \
    --to=integral@archlinuxcn.org \
    --cc=kent.overstreet@gmail.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-kernel@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 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.