From: Yao Zi Date: Fri, 30 Jan 2026 18:03:51 +0000 (+0000) Subject: cmd: mmc: Simplify dev subcommand handling X-Git-Tag: v2026.04-rc2~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97cc26f6b6a85312305e5b953ef44861891936bf;p=thirdparty%2Fu-boot.git cmd: mmc: Simplify dev subcommand handling 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 Tested-by: Anshul Dalal Reviewed-by: Peng Fan Signed-off-by: Peng Fan --- diff --git a/cmd/mmc.c b/cmd/mmc.c index 5340a58be8e..f2a59af087c 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include 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; }