Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bootconfig: Terminate value search if it hits a newline

Terminate the value search for a key if it hits a newline and make
the value empty.

When we pass a bootconfig with an empty value terminated by the
newline, like below::

foo =
bar = value

Current bootconfig interprets it as a single entry::

foo = "bar = value";

The Documentation/admin-guide/bootconfig.rst defines the value
itself is terminated by newline:

The value has to be terminated by semi-colon (``;``) or newline (``\n``).

but it does not define when the value search is terminated.
This changes the behavior to be more line-oriented, so that it is
clearer in how it works.

- The value search of key-value pair will be terminated by a comment
or newline.
- The value search of an array will continue beyond comments and
newlines.

Thus, with this update, the above example is interpreted as::

foo = "";
bar = "value";

And the below example will cause a syntax error because "bar" is expected
as a key but it has ','.

foo =
bar, buz

According to this change, one wrong example config is updated.

Link: https://lore.kernel.org/all/177025238503.14982.17059549076175612447.stgit@devnote2/

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>

+44 -18
+16 -8
Documentation/admin-guide/bootconfig.rst
··· 20 20 21 21 The boot config syntax is a simple structured key-value. Each key consists 22 22 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. 29 24 30 25 Each key word must contain only alphabets, numbers, dash (``-``) or underscore 31 26 (``_``). And each value only contains printable characters or spaces except 32 27 for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``), 33 28 hash (``#``) and closing brace (``}``). 29 + 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 ``=``. 34 42 35 43 If you want to use those delimiters in a value, you can use either double- 36 44 quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that ··· 146 138 foo = value 147 139 bar = 1, 2, 3 148 140 149 - Note that you can not put a comment between value and delimiter(``,`` or 150 - ``;``). This means following config has a syntax error :: 141 + Note that you can NOT put a comment or a newline between value and delimiter 142 + (``,`` or ``;``). This means following config has a syntax error :: 151 143 152 144 key = 1 # comment 153 145 ,2
+19 -8
lib/bootconfig.c
··· 557 557 /* 558 558 * Return delimiter or error, no node added. As same as lib/cmdline.c, 559 559 * you can use " around spaces, but can't escape " for value. 560 + * *@__v must point real value string. (not including spaces before value.) 560 561 */ 561 562 static int __init __xbc_parse_value(char **__v, char **__n) 562 563 { 563 564 char *p, *v = *__v; 564 565 int c, quotes = 0; 565 566 566 - v = skip_spaces(v); 567 - while (*v == '#') { 568 - v = skip_comment(v); 569 - v = skip_spaces(v); 570 - } 571 567 if (*v == '"' || *v == '\'') { 572 568 quotes = *v; 573 569 v++; ··· 613 617 last_parent = xbc_node_get_child(last_parent); 614 618 615 619 do { 620 + /* Search the next array value beyond comments and empty lines */ 621 + next = skip_spaces(*__v); 622 + while (*next == '#') { 623 + next = skip_comment(next); 624 + next = skip_spaces(next); 625 + } 626 + *__v = next; 616 627 c = __xbc_parse_value(__v, &next); 617 628 if (c < 0) 618 629 return c; ··· 704 701 if (ret) 705 702 return ret; 706 703 707 - c = __xbc_parse_value(&v, &next); 708 - if (c < 0) 709 - return c; 704 + v = skip_spaces_until_newline(v); 705 + /* If there is a comment, this has an empty value. */ 706 + if (*v == '#') { 707 + next = skip_comment(v); 708 + *v = '\0'; 709 + c = '\n'; 710 + } else { 711 + c = __xbc_parse_value(&v, &next); 712 + if (c < 0) 713 + return c; 714 + } 710 715 711 716 child = xbc_node_get_child(last_parent); 712 717 if (child && xbc_node_is_value(child)) {
+4
tools/bootconfig/samples/bad-array-after-comment.bconf
··· 1 + # the first array value must be on the same line as the key 2 + key = # comment 3 + value1, 4 + value2
+4
tools/bootconfig/samples/bad-array-in-next-line.bconf
··· 1 + # the first array value must be on the same line as the key 2 + key = 3 + value1, 4 + value2
+1 -2
tools/bootconfig/samples/good-array-space-comment.bconf
··· 1 - key = # comment 2 - "value1", # comment1 1 + key = "value1", # comment1 3 2 "value2" , # comment2 4 3 "value3"