diff options
| author | Yao Zi <[email protected]> | 2026-01-30 18:03:51 +0000 |
|---|---|---|
| committer | Peng Fan <[email protected]> | 2026-02-03 22:11:45 +0800 |
| commit | 97cc26f6b6a85312305e5b953ef44861891936bf (patch) | |
| tree | 3f870b908ba98b317647e86ca05a6653caeada79 /cmd | |
| parent | 7f9e9b50336777ce07ca7d7bc40bd82856d12468 (diff) | |
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 <[email protected]>
Tested-by: Anshul Dalal <[email protected]>
Reviewed-by: Peng Fan <[email protected]>
Signed-off-by: Peng Fan <[email protected]>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/mmc.c | 34 |
1 files changed, 14 insertions, 20 deletions
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 <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; } |
