From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: keescook@chromium.org, dave.jiang@intel.com,
dan.j.williams@intel.com, hpa@zytor.com, tglx@linutronix.de,
mingo@kernel.org, dyoung@redhat.com,
"Baoquan He" <bhe@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jessica Yu" <jeyu@redhat.com>, "Petr Mladek" <pmladek@suse.com>,
"Jens Axboe" <axboe@fb.com>,
"Josh Triplett" <josh@joshtriplett.org>,
zijun_hu <zijun_hu@htc.com>,
"Larry Finger" <Larry.Finger@lwfinger.net>,
"Johannes Berg" <johannes.berg@intel.com>,
"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
"Gustavo Padovan" <gustavo.padovan@collabora.co.uk>,
"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
"Peter Zijlstra" <peterz@infradead.org>
Subject: [PATCH 1/4] param: Move function next_arg to lib/cmdline.c for later reuse
Date: Mon, 17 Apr 2017 21:34:56 +0800 [thread overview]
Message-ID: <1492436099-4017-2-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1492436099-4017-1-git-send-email-bhe@redhat.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=n, Size: 4299 bytes --]
next_arg will be used to parse cmdline in x86/boot/compressed code,
so move it to lib/cmdline.c for better code reuse.
No change in functionality.
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jessica Yu <jeyu@redhat.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Jens Axboe <axboe@fb.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: zijun_hu <zijun_hu@htc.com>
Cc: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Johannes Berg <johannes.berg@intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Cc: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: Peter Zijlstra <peterz@infradead.org>
---
include/linux/kernel.h | 1 +
kernel/params.c | 52 ---------------------------------------------
lib/cmdline.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 52 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4c26dc3..7ae2567 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -438,6 +438,7 @@ extern int get_option(char **str, int *pint);
extern char *get_options(const char *str, int nints, int *ints);
extern unsigned long long memparse(const char *ptr, char **retptr);
extern bool parse_option_str(const char *str, const char *option);
+extern char *next_arg(char *args, char **param, char **val);
extern int core_kernel_text(unsigned long addr);
extern int core_kernel_data(unsigned long addr);
diff --git a/kernel/params.c b/kernel/params.c
index a6d6149..60b2d81 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -160,58 +160,6 @@ static int parse_one(char *param,
return -ENOENT;
}
-/* You can use " around spaces, but can't escape ". */
-/* Hyphens and underscores equivalent in parameter names. */
-static char *next_arg(char *args, char **param, char **val)
-{
- unsigned int i, equals = 0;
- int in_quote = 0, quoted = 0;
- char *next;
-
- if (*args == '"') {
- args++;
- in_quote = 1;
- quoted = 1;
- }
-
- for (i = 0; args[i]; i++) {
- if (isspace(args[i]) && !in_quote)
- break;
- if (equals == 0) {
- if (args[i] == '=')
- equals = i;
- }
- if (args[i] == '"')
- in_quote = !in_quote;
- }
-
- *param = args;
- if (!equals)
- *val = NULL;
- else {
- args[equals] = '\0';
- *val = args + equals + 1;
-
- /* Don't include quotes in value. */
- if (**val == '"') {
- (*val)++;
- if (args[i-1] == '"')
- args[i-1] = '\0';
- }
- }
- if (quoted && args[i-1] == '"')
- args[i-1] = '\0';
-
- if (args[i]) {
- args[i] = '\0';
- next = args + i + 1;
- } else
- next = args + i;
-
- /* Chew up trailing spaces. */
- return skip_spaces(next);
-}
-
/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
char *parse_args(const char *doing,
char *args,
diff --git a/lib/cmdline.c b/lib/cmdline.c
index 8f13cf7..6e3abfb 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -15,6 +15,7 @@
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/string.h>
+#include <linux/ctype.h>
/*
* If a hyphen was found in get_option, this will handle the
@@ -189,3 +190,59 @@ bool parse_option_str(const char *str, const char *option)
return false;
}
+
+/*
+ * Parse a string to get a param value pair.
+ * You can use " around spaces, but can't escape ".
+ * Hyphens and underscores equivalent in parameter names.
+ */
+char *next_arg(char *args, char **param, char **val)
+{
+ unsigned int i, equals = 0;
+ int in_quote = 0, quoted = 0;
+ char *next;
+
+ if (*args == '"') {
+ args++;
+ in_quote = 1;
+ quoted = 1;
+ }
+
+ for (i = 0; args[i]; i++) {
+ if (isspace(args[i]) && !in_quote)
+ break;
+ if (equals == 0) {
+ if (args[i] == '=')
+ equals = i;
+ }
+ if (args[i] == '"')
+ in_quote = !in_quote;
+ }
+
+ *param = args;
+ if (!equals)
+ *val = NULL;
+ else {
+ args[equals] = '\0';
+ *val = args + equals + 1;
+
+ /* Don't include quotes in value. */
+ if (**val == '"') {
+ (*val)++;
+ if (args[i-1] == '"')
+ args[i-1] = '\0';
+ }
+ }
+ if (quoted && args[i-1] == '"')
+ args[i-1] = '\0';
+
+ if (args[i]) {
+ args[i] = '\0';
+ next = args + i + 1;
+ } else
+ next = args + i;
+
+ /* Chew up trailing spaces. */
+ return skip_spaces(next);
+ //return next;
+}
--
2.5.5
next prev parent reply other threads:[~2017-04-17 13:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-17 13:34 [PATCH 0/4] Handle memmap and mem kernel options in boot stage kaslr Baoquan He
2017-04-17 13:34 ` Baoquan He [this message]
2017-04-18 12:51 ` [tip:x86/boot] boot/param: Move next_arg() function to lib/cmdline.c for later reuse tip-bot for Baoquan He
2017-04-18 20:17 ` [PATCH 1/4] param: Move function next_arg " Kees Cook
2017-04-17 13:34 ` [PATCH 2/4] KASLR: Parse all memmap entries in cmdline Baoquan He
2017-04-18 20:22 ` Kees Cook
2017-04-18 22:52 ` Baoquan He
2017-04-18 23:32 ` Kees Cook
2017-04-19 0:07 ` Baoquan He
2017-04-17 13:34 ` [PATCH 3/4] KASLR: Handle memory limit specified by memmap and mem option Baoquan He
2017-04-18 20:36 ` Kees Cook
2017-04-18 23:12 ` Baoquan He
2017-04-19 0:50 ` Baoquan He
2017-04-19 0:59 ` Baoquan He
2017-04-17 13:34 ` [PATCH 4/4] doc: Update description about memmap option in kernel-parameter.txt Baoquan He
2017-04-18 9:47 ` [PATCH 0/4] Handle memmap and mem kernel options in boot stage kaslr Ingo Molnar
2017-04-18 11:38 ` Baoquan He
2017-04-18 12:51 ` Ingo Molnar
2017-04-19 0:09 ` Baoquan He
2017-04-20 13:59 ` Baoquan He
2017-04-24 2:46 ` Baoquan He
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=1492436099-4017-2-git-send-email-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=Larry.Finger@lwfinger.net \
--cc=akpm@linux-foundation.org \
--cc=axboe@fb.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dyoung@redhat.com \
--cc=gustavo.padovan@collabora.co.uk \
--cc=hpa@zytor.com \
--cc=jeyu@redhat.com \
--cc=johannes.berg@intel.com \
--cc=josh@joshtriplett.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mingo@kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=tglx@linutronix.de \
--cc=zijun_hu@htc.com \
/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