Commit ca24306d authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

bootconfig: Change array value to use child node

It is not possible to put an array value with subkeys under
a key node, because both of subkeys and the array elements
are using "next" field of the xbc_node.

Thus this changes the array values to use "child" field in
the array case. The reason why split this change is to
test it easily.

Link: https://lkml.kernel.org/r/162262193838.264090.16044473274501498656.stgit@devnote2Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent ee0a0701
...@@ -49,7 +49,7 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) ...@@ -49,7 +49,7 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size)
else else
q = '"'; q = '"';
ret = snprintf(dst, rest(dst, end), "%c%s%c%s", ret = snprintf(dst, rest(dst, end), "%c%s%c%s",
q, val, q, vnode->next ? ", " : "\n"); q, val, q, xbc_node_is_array(vnode) ? ", " : "\n");
if (ret < 0) if (ret < 0)
goto out; goto out;
dst += ret; dst += ret;
......
...@@ -71,7 +71,7 @@ static inline __init bool xbc_node_is_key(struct xbc_node *node) ...@@ -71,7 +71,7 @@ static inline __init bool xbc_node_is_key(struct xbc_node *node)
*/ */
static inline __init bool xbc_node_is_array(struct xbc_node *node) static inline __init bool xbc_node_is_array(struct xbc_node *node)
{ {
return xbc_node_is_value(node) && node->next != 0; return xbc_node_is_value(node) && node->child != 0;
} }
/** /**
...@@ -140,7 +140,7 @@ static inline struct xbc_node * __init xbc_find_node(const char *key) ...@@ -140,7 +140,7 @@ static inline struct xbc_node * __init xbc_find_node(const char *key)
*/ */
#define xbc_array_for_each_value(anode, value) \ #define xbc_array_for_each_value(anode, value) \
for (value = xbc_node_get_data(anode); anode != NULL ; \ for (value = xbc_node_get_data(anode); anode != NULL ; \
anode = xbc_node_get_next(anode), \ anode = xbc_node_get_child(anode), \
value = anode ? xbc_node_get_data(anode) : NULL) value = anode ? xbc_node_get_data(anode) : NULL)
/** /**
...@@ -171,7 +171,7 @@ static inline struct xbc_node * __init xbc_find_node(const char *key) ...@@ -171,7 +171,7 @@ static inline struct xbc_node * __init xbc_find_node(const char *key)
*/ */
#define xbc_node_for_each_array_value(node, key, anode, value) \ #define xbc_node_for_each_array_value(node, key, anode, value) \
for (value = xbc_node_find_value(node, key, &anode); value != NULL; \ for (value = xbc_node_find_value(node, key, &anode); value != NULL; \
anode = xbc_node_get_next(anode), \ anode = xbc_node_get_child(anode), \
value = anode ? xbc_node_get_data(anode) : NULL) value = anode ? xbc_node_get_data(anode) : NULL)
/** /**
......
...@@ -367,6 +367,14 @@ static inline __init struct xbc_node *xbc_last_sibling(struct xbc_node *node) ...@@ -367,6 +367,14 @@ static inline __init struct xbc_node *xbc_last_sibling(struct xbc_node *node)
return node; return node;
} }
static inline __init struct xbc_node *xbc_last_child(struct xbc_node *node)
{
while (node->child)
node = xbc_node_get_child(node);
return node;
}
static struct xbc_node * __init xbc_add_sibling(char *data, u32 flag) static struct xbc_node * __init xbc_add_sibling(char *data, u32 flag)
{ {
struct xbc_node *sib, *node = xbc_add_node(data, flag); struct xbc_node *sib, *node = xbc_add_node(data, flag);
...@@ -517,17 +525,20 @@ static int __init xbc_parse_array(char **__v) ...@@ -517,17 +525,20 @@ static int __init xbc_parse_array(char **__v)
char *next; char *next;
int c = 0; int c = 0;
if (last_parent->child)
last_parent = xbc_node_get_child(last_parent);
do { do {
c = __xbc_parse_value(__v, &next); c = __xbc_parse_value(__v, &next);
if (c < 0) if (c < 0)
return c; return c;
node = xbc_add_sibling(*__v, XBC_VALUE); node = xbc_add_child(*__v, XBC_VALUE);
if (!node) if (!node)
return -ENOMEM; return -ENOMEM;
*__v = next; *__v = next;
} while (c == ','); } while (c == ',');
node->next = 0; node->child = 0;
return c; return c;
} }
...@@ -615,8 +626,12 @@ static int __init xbc_parse_kv(char **k, char *v, int op) ...@@ -615,8 +626,12 @@ static int __init xbc_parse_kv(char **k, char *v, int op)
if (op == ':' && child) { if (op == ':' && child) {
xbc_init_node(child, v, XBC_VALUE); xbc_init_node(child, v, XBC_VALUE);
} else if (!xbc_add_sibling(v, XBC_VALUE)) } else {
if (op == '+' && child)
last_parent = xbc_last_child(child);
if (!xbc_add_sibling(v, XBC_VALUE))
return -ENOMEM; return -ENOMEM;
}
if (c == ',') { /* Array */ if (c == ',') { /* Array */
c = xbc_parse_array(&next); c = xbc_parse_array(&next);
......
...@@ -27,7 +27,7 @@ static int xbc_show_value(struct xbc_node *node, bool semicolon) ...@@ -27,7 +27,7 @@ static int xbc_show_value(struct xbc_node *node, bool semicolon)
q = '\''; q = '\'';
else else
q = '"'; q = '"';
printf("%c%s%c%s", q, val, q, node->next ? ", " : eol); printf("%c%s%c%s", q, val, q, xbc_node_is_array(node) ? ", " : eol);
i++; i++;
} }
return i; return i;
......
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