Skip to content

Commit 770aaed

Browse files
committed
Merge tag 'bootconfig-v7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull bootconfig updates from Masami Hiramatsu: - Update the bootconfig parser to stop searching for a value when it encounters a newline character - Update the tests for bootconfig parser to ensure the good examples to be parsed correctly by comparing the expected results * tag 'bootconfig-v7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: bootconfig: Check the parsed output of the good examples bootconfig: Terminate value search if it hits a newline
2 parents 3c6e577 + 8c5d862 commit 770aaed

19 files changed

Lines changed: 88 additions & 18 deletions

Documentation/admin-guide/bootconfig.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@ Config File Syntax
2020

2121
The boot config syntax is a simple structured key-value. Each key consists
2222
of dot-connected-words, and key and value are connected by ``=``. The value
23-
has to be terminated by semi-colon (``;``) or newline (``\n``).
24-
For array value, array entries are separated by comma (``,``). ::
25-
26-
KEY[.WORD[...]] = VALUE[, VALUE2[...]][;]
27-
28-
Unlike the kernel command line syntax, spaces are OK around the comma and ``=``.
23+
string has to be terminated by the following delimiters described below.
2924

3025
Each key word must contain only alphabets, numbers, dash (``-``) or underscore
3126
(``_``). And each value only contains printable characters or spaces except
3227
for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``),
3328
hash (``#``) and closing brace (``}``).
3429

30+
If the ``=`` is followed by whitespace up to one of these delimiters, the
31+
key is assigned an empty value.
32+
33+
For arrays, the array values are comma (``,``) separated, and comments and
34+
line breaks with newline (``\n``) are allowed between array values for
35+
readability. Thus the first entry of the array must be on the same line as
36+
the key.::
37+
38+
KEY[.WORD[...]] = VALUE[, VALUE2[...]][;]
39+
40+
Unlike the kernel command line syntax, white spaces (including tabs) are
41+
ignored around the comma and ``=``.
42+
3543
If you want to use those delimiters in a value, you can use either double-
3644
quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that
3745
you can not escape these quotes.
@@ -138,8 +146,8 @@ This is parsed as below::
138146
foo = value
139147
bar = 1, 2, 3
140148

141-
Note that you can not put a comment between value and delimiter(``,`` or
142-
``;``). This means following config has a syntax error ::
149+
Note that you can NOT put a comment or a newline between value and delimiter
150+
(``,`` or ``;``). This means following config has a syntax error ::
143151

144152
key = 1 # comment
145153
,2

lib/bootconfig.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,13 @@ static int __init __xbc_close_brace(char *p)
557557
/*
558558
* Return delimiter or error, no node added. As same as lib/cmdline.c,
559559
* you can use " around spaces, but can't escape " for value.
560+
* *@__v must point real value string. (not including spaces before value.)
560561
*/
561562
static int __init __xbc_parse_value(char **__v, char **__n)
562563
{
563564
char *p, *v = *__v;
564565
int c, quotes = 0;
565566

566-
v = skip_spaces(v);
567-
while (*v == '#') {
568-
v = skip_comment(v);
569-
v = skip_spaces(v);
570-
}
571567
if (*v == '"' || *v == '\'') {
572568
quotes = *v;
573569
v++;
@@ -617,6 +613,13 @@ static int __init xbc_parse_array(char **__v)
617613
last_parent = xbc_node_get_child(last_parent);
618614

619615
do {
616+
/* Search the next array value beyond comments and empty lines */
617+
next = skip_spaces(*__v);
618+
while (*next == '#') {
619+
next = skip_comment(next);
620+
next = skip_spaces(next);
621+
}
622+
*__v = next;
620623
c = __xbc_parse_value(__v, &next);
621624
if (c < 0)
622625
return c;
@@ -701,9 +704,17 @@ static int __init xbc_parse_kv(char **k, char *v, int op)
701704
if (ret)
702705
return ret;
703706

704-
c = __xbc_parse_value(&v, &next);
705-
if (c < 0)
706-
return c;
707+
v = skip_spaces_until_newline(v);
708+
/* If there is a comment, this has an empty value. */
709+
if (*v == '#') {
710+
next = skip_comment(v);
711+
*v = '\0';
712+
c = '\n';
713+
} else {
714+
c = __xbc_parse_value(&v, &next);
715+
if (c < 0)
716+
return c;
717+
}
707718

708719
child = xbc_node_get_child(last_parent);
709720
if (child && xbc_node_is_value(child)) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# the first array value must be on the same line as the key
2+
key = # comment
3+
value1,
4+
value2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# the first array value must be on the same line as the key
2+
key =
3+
value1,
4+
value2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key = "value1", "value2", "value3";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key = "value";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
key = "foo", "bar";
2+
keyx.subkey = "value";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
key = "value";
2+
key.subkey = "another-value";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
key = "another-value";
2+
key.subkey = "value";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
key = "value";
2+
key {
3+
subkey1;
4+
subkey2 = "foo";
5+
}

0 commit comments

Comments
 (0)