public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Peng Fan <peng.fan@nxp.com>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Tom Rini <trini@konsulko.com>,
	Jerome Forissier <jerome.forissier@linaro.org>,
	Mattijs Korpershoek <mkorpershoek@kernel.org>
Cc: u-boot@lists.denx.de, Yao Zi <me@ziyao.cc>
Subject: [PATCH 1/3] cmd: mmc: Simplify dev subcommand handling
Date: Fri, 30 Jan 2026 18:03:51 +0000	[thread overview]
Message-ID: <20260130180353.42205-2-me@ziyao.cc> (raw)
In-Reply-To: <20260130180353.42205-1-me@ziyao.cc>

Replace the big if-else block in do_mmc_dev() with switch-case and use
fallthrough to remove the duplicated code for parsing dev and part.

Signed-off-by: Yao Zi <me@ziyao.cc>
---
 cmd/mmc.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/cmd/mmc.c b/cmd/mmc.c
index 5340a58be8ee..f2a59af087cb 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -16,6 +16,7 @@
 #include <sparse_format.h>
 #include <image-sparse.h>
 #include <vsprintf.h>
+#include <linux/compiler_attributes.h>
 #include <linux/ctype.h>
 
 static int curr_device = -1;
@@ -556,37 +557,30 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 		      int argc, char *const argv[])
 {
-	int dev, part = 0, ret;
+	enum bus_mode speed_mode = MMC_MODES_END;
+	int dev = curr_device, part = 0, ret;
 	struct mmc *mmc;
 
-	if (argc == 1) {
-		dev = curr_device;
-		mmc = init_mmc_device(dev, true);
-	} else if (argc == 2) {
-		dev = (int)dectoul(argv[1], NULL);
-		mmc = init_mmc_device(dev, true);
-	} else if (argc == 3) {
-		dev = (int)dectoul(argv[1], NULL);
+	switch (argc) {
+	case 4:
+		speed_mode = (int)dectoul(argv[3], NULL);
+		fallthrough;
+	case 3:
 		part = (int)dectoul(argv[2], NULL);
 		if (part > PART_ACCESS_MASK) {
 			printf("#part_num shouldn't be larger than %d\n",
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
-		mmc = init_mmc_device(dev, true);
-	} else if (argc == 4) {
-		enum bus_mode speed_mode;
 
+		fallthrough;
+	case 2:
 		dev = (int)dectoul(argv[1], NULL);
-		part = (int)dectoul(argv[2], NULL);
-		if (part > PART_ACCESS_MASK) {
-			printf("#part_num shouldn't be larger than %d\n",
-			       PART_ACCESS_MASK);
-			return CMD_RET_FAILURE;
-		}
-		speed_mode = (int)dectoul(argv[3], NULL);
+		fallthrough;
+	case 1:
 		mmc = __init_mmc_device(dev, true, speed_mode);
-	} else {
+		break;
+	default:
 		return CMD_RET_USAGE;
 	}
 
-- 
2.52.0


  reply	other threads:[~2026-01-30 18:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30 18:03 [PATCH 0/3] Code improvements and argument checks for mmc dev subcommand Yao Zi
2026-01-30 18:03 ` Yao Zi [this message]
2026-01-30 18:03 ` [PATCH 2/3] cmd: mmc: Check whether arguments are valid numbers in " Yao Zi
2026-01-30 18:03 ` [PATCH 3/3] cmd: mmc: Return symbolic value when part switching fails in mmc dev Yao Zi
2026-02-02  7:51 ` [PATCH 0/3] Code improvements and argument checks for mmc dev subcommand Anshul Dalal
2026-02-03 11:55 ` Peng Fan
2026-02-03 14:18 ` Peng Fan (OSS)

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=20260130180353.42205-2-me@ziyao.cc \
    --to=me@ziyao.cc \
    --cc=jerome.forissier@linaro.org \
    --cc=jh80.chung@samsung.com \
    --cc=mkorpershoek@kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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