Skip to content

Commit f51b17c

Browse files
Baoquan HeIngo Molnar
Baoquan He
authored and
Ingo Molnar
committed
boot/param: Move next_arg() function to lib/cmdline.c for later reuse
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 <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Gustavo Padovan <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Jessica Yu <[email protected]> Cc: Johannes Berg <[email protected]> Cc: Josh Triplett <[email protected]> Cc: Larry Finger <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Niklas Söderlund <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Petr Mladek <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: zijun_hu <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 4729277 commit f51b17c

File tree

3 files changed

+58
-52
lines changed

3 files changed

+58
-52
lines changed

include/linux/kernel.h

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ extern int get_option(char **str, int *pint);
438438
extern char *get_options(const char *str, int nints, int *ints);
439439
extern unsigned long long memparse(const char *ptr, char **retptr);
440440
extern bool parse_option_str(const char *str, const char *option);
441+
extern char *next_arg(char *args, char **param, char **val);
441442

442443
extern int core_kernel_text(unsigned long addr);
443444
extern int core_kernel_data(unsigned long addr);

kernel/params.c

-52
Original file line numberDiff line numberDiff line change
@@ -160,58 +160,6 @@ static int parse_one(char *param,
160160
return -ENOENT;
161161
}
162162

163-
/* You can use " around spaces, but can't escape ". */
164-
/* Hyphens and underscores equivalent in parameter names. */
165-
static char *next_arg(char *args, char **param, char **val)
166-
{
167-
unsigned int i, equals = 0;
168-
int in_quote = 0, quoted = 0;
169-
char *next;
170-
171-
if (*args == '"') {
172-
args++;
173-
in_quote = 1;
174-
quoted = 1;
175-
}
176-
177-
for (i = 0; args[i]; i++) {
178-
if (isspace(args[i]) && !in_quote)
179-
break;
180-
if (equals == 0) {
181-
if (args[i] == '=')
182-
equals = i;
183-
}
184-
if (args[i] == '"')
185-
in_quote = !in_quote;
186-
}
187-
188-
*param = args;
189-
if (!equals)
190-
*val = NULL;
191-
else {
192-
args[equals] = '\0';
193-
*val = args + equals + 1;
194-
195-
/* Don't include quotes in value. */
196-
if (**val == '"') {
197-
(*val)++;
198-
if (args[i-1] == '"')
199-
args[i-1] = '\0';
200-
}
201-
}
202-
if (quoted && args[i-1] == '"')
203-
args[i-1] = '\0';
204-
205-
if (args[i]) {
206-
args[i] = '\0';
207-
next = args + i + 1;
208-
} else
209-
next = args + i;
210-
211-
/* Chew up trailing spaces. */
212-
return skip_spaces(next);
213-
}
214-
215163
/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
216164
char *parse_args(const char *doing,
217165
char *args,

lib/cmdline.c

+57
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/export.h>
1616
#include <linux/kernel.h>
1717
#include <linux/string.h>
18+
#include <linux/ctype.h>
1819

1920
/*
2021
* 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)
189190

190191
return false;
191192
}
193+
194+
/*
195+
* Parse a string to get a param value pair.
196+
* You can use " around spaces, but can't escape ".
197+
* Hyphens and underscores equivalent in parameter names.
198+
*/
199+
char *next_arg(char *args, char **param, char **val)
200+
{
201+
unsigned int i, equals = 0;
202+
int in_quote = 0, quoted = 0;
203+
char *next;
204+
205+
if (*args == '"') {
206+
args++;
207+
in_quote = 1;
208+
quoted = 1;
209+
}
210+
211+
for (i = 0; args[i]; i++) {
212+
if (isspace(args[i]) && !in_quote)
213+
break;
214+
if (equals == 0) {
215+
if (args[i] == '=')
216+
equals = i;
217+
}
218+
if (args[i] == '"')
219+
in_quote = !in_quote;
220+
}
221+
222+
*param = args;
223+
if (!equals)
224+
*val = NULL;
225+
else {
226+
args[equals] = '\0';
227+
*val = args + equals + 1;
228+
229+
/* Don't include quotes in value. */
230+
if (**val == '"') {
231+
(*val)++;
232+
if (args[i-1] == '"')
233+
args[i-1] = '\0';
234+
}
235+
}
236+
if (quoted && args[i-1] == '"')
237+
args[i-1] = '\0';
238+
239+
if (args[i]) {
240+
args[i] = '\0';
241+
next = args + i + 1;
242+
} else
243+
next = args + i;
244+
245+
/* Chew up trailing spaces. */
246+
return skip_spaces(next);
247+
//return next;
248+
}

0 commit comments

Comments
 (0)