From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 1/7] commands: Move mem_parse_options() to lib/misc.c
Date: Tue, 22 Jan 2019 17:13:32 -0800 [thread overview]
Message-ID: <20190123011338.32517-2-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190123011338.32517-1-andrew.smirnov@gmail.com>
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 <andrew.smirnov@gmail.com>
---
commands/mem.c | 40 ----------------------------------------
lib/misc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 40 deletions(-)
diff --git a/commands/mem.c b/commands/mem.c
index a9e12f3e5..62488bf52 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,
diff --git a/lib/misc.c b/lib/misc.c
index 1d20e1b09..cd420a57d 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -23,6 +23,7 @@
#include <fs.h>
#include <string.h>
#include <linux/ctype.h>
+#include <getopt.h>
/*
* Like simple_strtoull() but handles an optional G, M, K or k
@@ -129,3 +130,44 @@ success:
return 0;
}
EXPORT_SYMBOL(parse_area_spec);
+
+/*
+ * 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 -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-01-23 1:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-23 1:13 [PATCH 0/7] 32-bit lseek and /dev/mem fixes/improvements Andrey Smirnov
2019-01-23 1:13 ` Andrey Smirnov [this message]
2019-01-23 1:13 ` [PATCH 2/7] commands: Get rid of mem_rw_buf Andrey Smirnov
2019-01-23 1:13 ` [PATCH 3/7] commands: Move /dev/mem driver to drivers/misc Andrey Smirnov
2019-01-23 1:13 ` [PATCH 4/7] fs: Change error checking logic for fsdrv->lseek() call Andrey Smirnov
2019-01-24 7:44 ` Sascha Hauer
2019-01-24 19:19 ` Andrey Smirnov
2019-01-23 1:13 ` [PATCH 5/7] fs: Calculate new position before validtiy check in lseek() Andrey Smirnov
2019-01-24 7:52 ` Sascha Hauer
2019-01-24 19:37 ` Andrey Smirnov
2019-01-23 1:13 ` [PATCH 6/7] fs: Add support for files larger than MAX_LFS_FILESIZE Andrey Smirnov
2019-01-24 8:48 ` Sascha Hauer
2019-01-24 19:43 ` Andrey Smirnov
2019-01-23 1:13 ` [PATCH 7/7] misc: mem: Set correct size for /dev/mem Andrey Smirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190123011338.32517-2-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox