From 60aaeb8be019c75d86cd0aa9615d1ef470983418 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 28 Jan 2019 22:55:31 -0800 Subject: commands: Move mem_parse_options() to lib/misc.c As a first step of de-cluttering /dev/mem related code, move mem_parse_options() out of commands/mem.c into lib/misc.c where it seem to fit better. With this change we no longer explicitly turn this code off using CONFIG_COMPILE_MEMORY and instead rely on LTO to get rid of it when it's not being used. While at it, also fix return value by replacing COMMAND_ERROR_USAGE with -EINVAL. All of the callers of mem_parse_options() expect negative error code as a sign of failure and COMMAND_ERROR_USAGE is not negative. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/mem.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'commands/mem.c') diff --git a/commands/mem.c b/commands/mem.c index a9e12f3e55..62488bf525 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -41,46 +41,6 @@ char *mem_rw_buf; -/* - * Common function for parsing options for the 'md', 'mw', 'memcpy', 'memcmp' - * commands. - */ -int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, - char **sourcefile, char **destfile, int *swab) -{ - int opt; - - while((opt = getopt(argc, argv, optstr)) > 0) { - switch(opt) { - case 'b': - *mode = O_RWSIZE_1; - break; - case 'w': - *mode = O_RWSIZE_2; - break; - case 'l': - *mode = O_RWSIZE_4; - break; - case 'q': - *mode = O_RWSIZE_8; - break; - case 's': - *sourcefile = optarg; - break; - case 'd': - *destfile = optarg; - break; - case 'x': - *swab = 1; - break; - default: - return COMMAND_ERROR_USAGE; - } - } - - return 0; -} - static struct cdev_operations memops = { .read = mem_read, .write = mem_write, -- cgit v1.2.3