diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-03-15 13:02:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-03-15 13:02:25 -0400 |
commit | 42576bee6eacda29a3193e97961ab3583a324850 (patch) | |
tree | 850f5f50941e800bd457cda268d650565ac746d6 /arch/x86/lib | |
parent | ba33ea811e1ff6726abb7f8f96df38c2d7b50304 (diff) | |
parent | 25b4caf7c50e8c501310e8c515d8518b1850c948 (diff) |
Merge branch 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 boot updates from Ingo Molnar:
"Early command line options parsing enhancements from Dave Hansen, plus
minor cleanups and enhancements"
* 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/boot: Remove unused 'is_big_kernel' variable
x86/boot: Use proper array element type in memset() size calculation
x86/boot: Pass in size to early cmdline parsing
x86/boot: Simplify early command line parsing
x86/boot: Fix early command-line parsing when partial word matches
x86/boot: Fix early command-line parsing when matching at end
x86/boot: Simplify kernel load address alignment check
x86/boot: Micro-optimize reset_early_page_tables()
Diffstat (limited to 'arch/x86/lib')
-rw-r--r-- | arch/x86/lib/cmdline.c | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/arch/x86/lib/cmdline.c b/arch/x86/lib/cmdline.c index 422db000d727..5cc78bf57232 100644 --- a/arch/x86/lib/cmdline.c +++ b/arch/x86/lib/cmdline.c | |||
@@ -21,12 +21,16 @@ static inline int myisspace(u8 c) | |||
21 | * @option: option string to look for | 21 | * @option: option string to look for |
22 | * | 22 | * |
23 | * Returns the position of that @option (starts counting with 1) | 23 | * Returns the position of that @option (starts counting with 1) |
24 | * or 0 on not found. | 24 | * or 0 on not found. @option will only be found if it is found |
25 | * as an entire word in @cmdline. For instance, if @option="car" | ||
26 | * then a cmdline which contains "cart" will not match. | ||
25 | */ | 27 | */ |
26 | int cmdline_find_option_bool(const char *cmdline, const char *option) | 28 | static int |
29 | __cmdline_find_option_bool(const char *cmdline, int max_cmdline_size, | ||
30 | const char *option) | ||
27 | { | 31 | { |
28 | char c; | 32 | char c; |
29 | int len, pos = 0, wstart = 0; | 33 | int pos = 0, wstart = 0; |
30 | const char *opptr = NULL; | 34 | const char *opptr = NULL; |
31 | enum { | 35 | enum { |
32 | st_wordstart = 0, /* Start of word/after whitespace */ | 36 | st_wordstart = 0, /* Start of word/after whitespace */ |
@@ -37,11 +41,11 @@ int cmdline_find_option_bool(const char *cmdline, const char *option) | |||
37 | if (!cmdline) | 41 | if (!cmdline) |
38 | return -1; /* No command line */ | 42 | return -1; /* No command line */ |
39 | 43 | ||
40 | len = min_t(int, strlen(cmdline), COMMAND_LINE_SIZE); | 44 | /* |
41 | if (!len) | 45 | * This 'pos' check ensures we do not overrun |
42 | return 0; | 46 | * a non-NULL-terminated 'cmdline' |
43 | 47 | */ | |
44 | while (len--) { | 48 | while (pos < max_cmdline_size) { |
45 | c = *(char *)cmdline++; | 49 | c = *(char *)cmdline++; |
46 | pos++; | 50 | pos++; |
47 | 51 | ||
@@ -58,18 +62,35 @@ int cmdline_find_option_bool(const char *cmdline, const char *option) | |||
58 | /* fall through */ | 62 | /* fall through */ |
59 | 63 | ||
60 | case st_wordcmp: | 64 | case st_wordcmp: |
61 | if (!*opptr) | 65 | if (!*opptr) { |
66 | /* | ||
67 | * We matched all the way to the end of the | ||
68 | * option we were looking for. If the | ||
69 | * command-line has a space _or_ ends, then | ||
70 | * we matched! | ||
71 | */ | ||
62 | if (!c || myisspace(c)) | 72 | if (!c || myisspace(c)) |
63 | return wstart; | 73 | return wstart; |
64 | else | 74 | /* |
65 | state = st_wordskip; | 75 | * We hit the end of the option, but _not_ |
66 | else if (!c) | 76 | * the end of a word on the cmdline. Not |
77 | * a match. | ||
78 | */ | ||
79 | } else if (!c) { | ||
80 | /* | ||
81 | * Hit the NULL terminator on the end of | ||
82 | * cmdline. | ||
83 | */ | ||
67 | return 0; | 84 | return 0; |
68 | else if (c != *opptr++) | 85 | } else if (c == *opptr++) { |
69 | state = st_wordskip; | 86 | /* |
70 | else if (!len) /* last word and is matching */ | 87 | * We are currently matching, so continue |
71 | return wstart; | 88 | * to the next character on the cmdline. |
72 | break; | 89 | */ |
90 | break; | ||
91 | } | ||
92 | state = st_wordskip; | ||
93 | /* fall through */ | ||
73 | 94 | ||
74 | case st_wordskip: | 95 | case st_wordskip: |
75 | if (!c) | 96 | if (!c) |
@@ -82,3 +103,8 @@ int cmdline_find_option_bool(const char *cmdline, const char *option) | |||
82 | 103 | ||
83 | return 0; /* Buffer overrun */ | 104 | return 0; /* Buffer overrun */ |
84 | } | 105 | } |
106 | |||
107 | int cmdline_find_option_bool(const char *cmdline, const char *option) | ||
108 | { | ||
109 | return __cmdline_find_option_bool(cmdline, COMMAND_LINE_SIZE, option); | ||
110 | } | ||