boot/param: Move next_arg() function to lib/cmdline.c for later reuse
authorBaoquan He <bhe@redhat.com>
Mon, 17 Apr 2017 13:34:56 +0000 (21:34 +0800)
committerIngo Molnar <mingo@kernel.org>
Tue, 18 Apr 2017 08:37:13 +0000 (10:37 +0200)
next_arg() will be used to parse boot parameters in the 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: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Cc: Jens Axboe <axboe@fb.com>
Cc: Jessica Yu <jeyu@redhat.com>
Cc: Johannes Berg <johannes.berg@intel.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dan.j.williams@intel.com
Cc: dave.jiang@intel.com
Cc: dyoung@redhat.com
Cc: keescook@chromium.org
Cc: zijun_hu <zijun_hu@htc.com>
Link: http://lkml.kernel.org/r/1492436099-4017-2-git-send-email-bhe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
include/linux/kernel.h
kernel/params.c
lib/cmdline.c

index 4c26dc3a8295a9fb2910dcb18946ee86f54ceac8..7ae256717a3243375d4c4260d3d7cfae31ce3265 100644 (file)
@@ -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);
index a6d6149c0fe60df1ca38d9a66acef281b78ee79d..60b2d8101355fedcfd8dfee99f8a2fa467ea99d9 100644 (file)
@@ -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,
index 8f13cf73c2ecf916c203ef7e963d250a113c3dee..3c6432df7e63466a24d41dead807c7ef14c0ab86 100644 (file)
@@ -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;
+}