]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: eeprom: Deduplicate parse_i2c_bus_addr() calls
authorMarek Behún <kabel@kernel.org>
Tue, 21 May 2024 07:13:31 +0000 (09:13 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 7 Jun 2024 16:47:59 +0000 (10:47 -0600)
Deduplicate the calls to parse_i2c_bus_addr().

Signed-off-by: Marek Behún <kabel@kernel.org>
cmd/eeprom.c

index d610dc99317c0e0176cee3a77e573b9aac10c833..12902e812e453cfde8402a22a9572072fc8c2034 100644 (file)
@@ -339,6 +339,21 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus,
        return rcode;
 }
 
+static int eeprom_action_expected_argc(enum eeprom_action action)
+{
+       switch (action) {
+       case EEPROM_READ:
+       case EEPROM_WRITE:
+               return 3;
+       case EEPROM_PRINT:
+               return 0;
+       case EEPROM_UPDATE:
+               return 2;
+       default:
+               return CMD_RET_USAGE;
+       }
+}
+
 #define NEXT_PARAM(argc, index)        { (argc)--; (index)++; }
 int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
@@ -371,25 +386,8 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
        }
 #endif
 
-       switch (action) {
-       case EEPROM_READ:
-       case EEPROM_WRITE:
-               ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
-                                        argv + index, 3);
-               break;
-       case EEPROM_PRINT:
-               ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
-                                        argv + index, 0);
-               break;
-       case EEPROM_UPDATE:
-               ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
-                                        argv + index, 2);
-               break;
-       default:
-               /* Get compiler to stop whining */
-               return CMD_RET_USAGE;
-       }
-
+       ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc, argv + index,
+                                eeprom_action_expected_argc(action));
        if (ret == CMD_RET_USAGE)
                return ret;