Commit c9c9e6a4 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'trace-v5.9-rc5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace

Pull bootconfig fixes from Steven Rostedt:
 "A couple of fixes for bootconfig.

  Masami discovered two bugs which this fixes and he added tests to
  cover these issues.

   - Fix a bug that breaks bootconfig tree nodes

   - Fix a bug that does not truncate whitespace properly

   - Add tests to cover the above two cases"

* tag 'trace-v5.9-rc5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
  tools/bootconfig: Add testcase for tailing space
  tools/bootconfig: Add testcases for repeated key with brace
  lib/bootconfig: Fix to remove tailing spaces after value
  lib/bootconfig: Fix a bug of breaking existing tree nodes
parents a969324f 2f5fb555
...@@ -31,6 +31,8 @@ static size_t xbc_data_size __initdata; ...@@ -31,6 +31,8 @@ static size_t xbc_data_size __initdata;
static struct xbc_node *last_parent __initdata; static struct xbc_node *last_parent __initdata;
static const char *xbc_err_msg __initdata; static const char *xbc_err_msg __initdata;
static int xbc_err_pos __initdata; static int xbc_err_pos __initdata;
static int open_brace[XBC_DEPTH_MAX] __initdata;
static int brace_index __initdata;
static int __init xbc_parse_error(const char *msg, const char *p) static int __init xbc_parse_error(const char *msg, const char *p)
{ {
...@@ -431,27 +433,27 @@ static char *skip_spaces_until_newline(char *p) ...@@ -431,27 +433,27 @@ static char *skip_spaces_until_newline(char *p)
return p; return p;
} }
static int __init __xbc_open_brace(void) static int __init __xbc_open_brace(char *p)
{ {
/* Mark the last key as open brace */ /* Push the last key as open brace */
last_parent->next = XBC_NODE_MAX; open_brace[brace_index++] = xbc_node_index(last_parent);
if (brace_index >= XBC_DEPTH_MAX)
return xbc_parse_error("Exceed max depth of braces", p);
return 0; return 0;
} }
static int __init __xbc_close_brace(char *p) static int __init __xbc_close_brace(char *p)
{ {
struct xbc_node *node; brace_index--;
if (!last_parent || brace_index < 0 ||
if (!last_parent || last_parent->next != XBC_NODE_MAX) (open_brace[brace_index] != xbc_node_index(last_parent)))
return xbc_parse_error("Unexpected closing brace", p); return xbc_parse_error("Unexpected closing brace", p);
node = last_parent; if (brace_index == 0)
node->next = 0; last_parent = NULL;
do { else
node = xbc_node_get_parent(node); last_parent = &xbc_nodes[open_brace[brace_index - 1]];
} while (node && node->next != XBC_NODE_MAX);
last_parent = node;
return 0; return 0;
} }
...@@ -492,8 +494,8 @@ static int __init __xbc_parse_value(char **__v, char **__n) ...@@ -492,8 +494,8 @@ static int __init __xbc_parse_value(char **__v, char **__n)
break; break;
} }
if (strchr(",;\n#}", c)) { if (strchr(",;\n#}", c)) {
v = strim(v);
*p++ = '\0'; *p++ = '\0';
v = strim(v);
break; break;
} }
} }
...@@ -661,7 +663,7 @@ static int __init xbc_open_brace(char **k, char *n) ...@@ -661,7 +663,7 @@ static int __init xbc_open_brace(char **k, char *n)
return ret; return ret;
*k = n; *k = n;
return __xbc_open_brace(); return __xbc_open_brace(n - 1);
} }
static int __init xbc_close_brace(char **k, char *n) static int __init xbc_close_brace(char **k, char *n)
...@@ -681,6 +683,13 @@ static int __init xbc_verify_tree(void) ...@@ -681,6 +683,13 @@ static int __init xbc_verify_tree(void)
int i, depth, len, wlen; int i, depth, len, wlen;
struct xbc_node *n, *m; struct xbc_node *n, *m;
/* Brace closing */
if (brace_index) {
n = &xbc_nodes[open_brace[brace_index]];
return xbc_parse_error("Brace is not closed",
xbc_node_get_data(n));
}
/* Empty tree */ /* Empty tree */
if (xbc_node_num == 0) { if (xbc_node_num == 0) {
xbc_parse_error("Empty config", xbc_data); xbc_parse_error("Empty config", xbc_data);
...@@ -745,6 +754,7 @@ void __init xbc_destroy_all(void) ...@@ -745,6 +754,7 @@ void __init xbc_destroy_all(void)
xbc_node_num = 0; xbc_node_num = 0;
memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX); memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX);
xbc_nodes = NULL; xbc_nodes = NULL;
brace_index = 0;
} }
/** /**
......
...@@ -137,6 +137,31 @@ $BOOTCONF $INITRD > $TEMPCONF ...@@ -137,6 +137,31 @@ $BOOTCONF $INITRD > $TEMPCONF
cat $TEMPCONF cat $TEMPCONF
xpass grep \'\"string\"\' $TEMPCONF xpass grep \'\"string\"\' $TEMPCONF
echo "Repeat same-key tree"
cat > $TEMPCONF << EOF
foo
bar
foo { buz }
EOF
echo > $INITRD
xpass $BOOTCONF -a $TEMPCONF $INITRD
$BOOTCONF $INITRD > $OUTFILE
xpass grep -q "bar" $OUTFILE
echo "Remove/keep tailing spaces"
cat > $TEMPCONF << EOF
foo = val # comment
bar = "val2 " # comment
EOF
echo > $INITRD
xpass $BOOTCONF -a $TEMPCONF $INITRD
$BOOTCONF $INITRD > $OUTFILE
xfail grep -q val[[:space:]] $OUTFILE
xpass grep -q val2[[:space:]] $OUTFILE
echo "=== expected failure cases ===" echo "=== expected failure cases ==="
for i in samples/bad-* ; do for i in samples/bad-* ; do
xfail $BOOTCONF -a $i $INITRD xfail $BOOTCONF -a $i $INITRD
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment