diff mbox series

[02/10] command: Add constants for cmd_get_data_size string / error

Message ID 20201101211544.3579850-3-sjg@chromium.org
State Accepted
Commit 7526deec7e52da92dee25aaf3a47514e639c2bb0
Delegated to: Tom Rini
Headers show
Series setexpr: Correct various bugs and add tests plus string support | expand

Commit Message

Simon Glass Nov. 1, 2020, 9:15 p.m. UTC
At present these values are open-coded in a few places. Add constants so
the meaning is clear.

Also add a comment to cmd_get_data_size()

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/itest.c       |  4 ++--
 cmd/mem.c         |  2 +-
 common/command.c  |  4 ++--
 include/command.h | 26 +++++++++++++++++++++++++-
 4 files changed, 30 insertions(+), 6 deletions(-)

Comments

Tom Rini Dec. 2, 2020, 9:22 p.m. UTC | #1
On Sun, Nov 01, 2020 at 02:15:36PM -0700, Simon Glass wrote:

> At present these values are open-coded in a few places. Add constants so
> the meaning is clear.
> 
> Also add a comment to cmd_get_data_size()
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/cmd/itest.c b/cmd/itest.c
index a0cf4bee041..9a441ce9b8a 100644
--- a/cmd/itest.c
+++ b/cmd/itest.c
@@ -197,10 +197,10 @@  static int do_itest(struct cmd_tbl *cmdtp, int flag, int argc,
 #endif
 		value = binary_test (argv[2], argv[1], argv[3], w);
 		break;
-	case -2:
+	case CMD_DATA_SIZE_STR:
 		value = binary_test (argv[2], argv[1], argv[3], 0);
 		break;
-	case -1:
+	case CMD_DATA_SIZE_ERR:
 	default:
 		puts("Invalid data width specifier\n");
 		value = 0;
diff --git a/cmd/mem.c b/cmd/mem.c
index 56e1d0755b6..1d4f2bab2f9 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -393,7 +393,7 @@  static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
 		 * Defaults to long if no or incorrect specification.
 		 */
 		size = cmd_get_data_size(argv[0], 4);
-		if (size < 0 && size != -2 /* string */)
+		if (size < 0 && size != CMD_DATA_SIZE_STR)
 			return 1;
 
 		argc--;
diff --git a/common/command.c b/common/command.c
index 2c491e20a74..068cb55b4cd 100644
--- a/common/command.c
+++ b/common/command.c
@@ -475,13 +475,13 @@  int cmd_get_data_size(char* arg, int default_size)
 		case 'l':
 			return 4;
 		case 's':
-			return -2;
+			return CMD_DATA_SIZE_STR;
 		case 'q':
 			if (MEM_SUPPORT_64BIT_DATA)
 				return 8;
 			/* no break */
 		default:
-			return -1;
+			return CMD_DATA_SIZE_ERR;
 		}
 	}
 	return default_size;
diff --git a/include/command.h b/include/command.h
index b9b5ec1afa0..e900f97df33 100644
--- a/include/command.h
+++ b/include/command.h
@@ -117,7 +117,31 @@  int cmd_process_error(struct cmd_tbl *cmdtp, int err);
 	defined(CONFIG_CMD_PCI) || \
 	defined(CONFIG_CMD_SETEXPR)
 #define CMD_DATA_SIZE
-extern int cmd_get_data_size(char* arg, int default_size);
+#define CMD_DATA_SIZE_ERR	(-1)
+#define CMD_DATA_SIZE_STR	(-2)
+
+/**
+ * cmd_get_data_size() - Get the data-size specifier from a command
+ *
+ * This reads a '.x' size specifier appended to a command. For example 'md.b'
+ * is the 'md' command with a '.b' specifier, meaning that the command should
+ * use bytes.
+ *
+ * Valid characters are:
+ *
+ *	b - byte
+ *	w - word (16 bits)
+ *	l - long (32 bits)
+ *	q - quad (64 bits)
+ *	s - string
+ *
+ * @arg: Pointers to the command to check. If a valid specifier is present it
+ *	will be the last character of the string, following a '.'
+ * @default_size: Default size to return if there is no specifier
+ * @return data size in bytes (1, 2, 4, 8) or CMD_DATA_SIZE_ERR for an invalid
+ *	character, or CMD_DATA_SIZE_STR for a string
+ */
+int cmd_get_data_size(char *arg, int default_size);
 #endif
 
 #ifdef CONFIG_CMD_BOOTD