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.

Merge tag 'bootconfig-v7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull bootconfig updates from Masami Hiramatsu:
"Minor fixes for handling errors:
- fix off-by-one in xbc_verify_tree() next node check
- increment xbc_node_num after node init succeeds
- validate child node index in xbc_verify_tree()

Code cleanups (mainly type/attribute changes):
- clean up comment typos and bracing
- drop redundant memset of xbc_nodes
- replace linux/kernel.h with specific includes
- narrow flag parameter type from uint32_t to uint16_t
- constify xbc_calc_checksum() data parameter
- fix signed comparison in xbc_node_get_data()
- use size_t for strlen result in xbc_node_match_prefix()
- use signed type for offset in xbc_init_node()
- use size_t for key length tracking in xbc_verify_tree()
- change xbc_node_index() return type to uint16_t"

* tag 'bootconfig-v7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
lib/bootconfig: change xbc_node_index() return type to uint16_t
lib/bootconfig: use size_t for key length tracking in xbc_verify_tree()
lib/bootconfig: use signed type for offset in xbc_init_node()
lib/bootconfig: use size_t for strlen result in xbc_node_match_prefix()
lib/bootconfig: fix signed comparison in xbc_node_get_data()
lib/bootconfig: validate child node index in xbc_verify_tree()
lib/bootconfig: replace linux/kernel.h with specific includes
bootconfig: constify xbc_calc_checksum() data parameter
lib/bootconfig: drop redundant memset of xbc_nodes
lib/bootconfig: increment xbc_node_num after node init succeeds
lib/bootconfig: fix off-by-one in xbc_verify_tree() next node check
lib/bootconfig: narrow flag parameter type from uint32_t to uint16_t
lib/bootconfig: clean up comment typos and bracing

+39 -29
+3 -3
include/linux/bootconfig.h
··· 36 36 * The checksum will be used with the BOOTCONFIG_MAGIC and the size for 37 37 * embedding the bootconfig in the initrd image. 38 38 */ 39 - static inline __init uint32_t xbc_calc_checksum(void *data, uint32_t size) 39 + static inline __init uint32_t xbc_calc_checksum(const void *data, uint32_t size) 40 40 { 41 - unsigned char *p = data; 41 + const unsigned char *p = data; 42 42 uint32_t ret = 0; 43 43 44 44 while (size--) ··· 66 66 67 67 /* Node tree access raw APIs */ 68 68 struct xbc_node * __init xbc_root_node(void); 69 - int __init xbc_node_index(struct xbc_node *node); 69 + uint16_t __init xbc_node_index(struct xbc_node *node); 70 70 struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node); 71 71 struct xbc_node * __init xbc_node_get_child(struct xbc_node *node); 72 72 struct xbc_node * __init xbc_node_get_next(struct xbc_node *node);
+36 -26
lib/bootconfig.c
··· 17 17 #include <linux/bug.h> 18 18 #include <linux/ctype.h> 19 19 #include <linux/errno.h> 20 - #include <linux/kernel.h> 20 + #include <linux/cache.h> 21 + #include <linux/compiler.h> 22 + #include <linux/sprintf.h> 21 23 #include <linux/memblock.h> 22 24 #include <linux/string.h> 23 25 ··· 73 71 74 72 static inline void *xbc_alloc_mem(size_t size) 75 73 { 76 - return malloc(size); 74 + return calloc(1, size); 77 75 } 78 76 79 77 static inline void xbc_free_mem(void *addr, size_t size, bool early) ··· 81 79 free(addr); 82 80 } 83 81 #endif 82 + 84 83 /** 85 84 * xbc_get_info() - Get the information of loaded boot config 86 85 * @node_size: A pointer to store the number of nodes. ··· 115 112 * xbc_root_node() - Get the root node of extended boot config 116 113 * 117 114 * Return the address of root node of extended boot config. If the 118 - * extended boot config is not initiized, return NULL. 115 + * extended boot config is not initialized, return NULL. 119 116 */ 120 117 struct xbc_node * __init xbc_root_node(void) 121 118 { ··· 131 128 * 132 129 * Return the index number of @node in XBC node list. 133 130 */ 134 - int __init xbc_node_index(struct xbc_node *node) 131 + uint16_t __init xbc_node_index(struct xbc_node *node) 135 132 { 136 - return node - &xbc_nodes[0]; 133 + return (uint16_t)(node - &xbc_nodes[0]); 137 134 } 138 135 139 136 /** ··· 183 180 */ 184 181 const char * __init xbc_node_get_data(struct xbc_node *node) 185 182 { 186 - int offset = node->data & ~XBC_VALUE; 183 + size_t offset = node->data & ~XBC_VALUE; 187 184 188 185 if (WARN_ON(offset >= xbc_data_size)) 189 186 return NULL; ··· 195 192 xbc_node_match_prefix(struct xbc_node *node, const char **prefix) 196 193 { 197 194 const char *p = xbc_node_get_data(node); 198 - int len = strlen(p); 195 + size_t len = strlen(p); 199 196 200 197 if (strncmp(*prefix, p, len)) 201 198 return false; ··· 367 364 node = xbc_node_get_parent(node); 368 365 if (node == root) 369 366 return NULL; 370 - /* User passed a node which is not uder parent */ 367 + /* User passed a node which is not under parent */ 371 368 if (WARN_ON(!node)) 372 369 return NULL; 373 370 } ··· 410 407 411 408 /* XBC parse and tree build */ 412 409 413 - static int __init xbc_init_node(struct xbc_node *node, char *data, uint32_t flag) 410 + static int __init xbc_init_node(struct xbc_node *node, char *data, uint16_t flag) 414 411 { 415 - unsigned long offset = data - xbc_data; 412 + long offset = data - xbc_data; 416 413 417 - if (WARN_ON(offset >= XBC_DATA_MAX)) 414 + if (WARN_ON(offset < 0 || offset >= XBC_DATA_MAX)) 418 415 return -EINVAL; 419 416 420 417 node->data = (uint16_t)offset | flag; ··· 424 421 return 0; 425 422 } 426 423 427 - static struct xbc_node * __init xbc_add_node(char *data, uint32_t flag) 424 + static struct xbc_node * __init xbc_add_node(char *data, uint16_t flag) 428 425 { 429 426 struct xbc_node *node; 430 427 431 428 if (xbc_node_num == XBC_NODE_MAX) 432 429 return NULL; 433 430 434 - node = &xbc_nodes[xbc_node_num++]; 431 + node = &xbc_nodes[xbc_node_num]; 435 432 if (xbc_init_node(node, data, flag) < 0) 436 433 return NULL; 434 + xbc_node_num++; 437 435 438 436 return node; 439 437 } ··· 455 451 return node; 456 452 } 457 453 458 - static struct xbc_node * __init __xbc_add_sibling(char *data, uint32_t flag, bool head) 454 + static struct xbc_node * __init __xbc_add_sibling(char *data, uint16_t flag, bool head) 459 455 { 460 456 struct xbc_node *sib, *node = xbc_add_node(data, flag); 461 457 ··· 476 472 sib->next = xbc_node_index(node); 477 473 } 478 474 } 479 - } else 475 + } else { 480 476 xbc_parse_error("Too many nodes", data); 477 + } 481 478 482 479 return node; 483 480 } 484 481 485 - static inline struct xbc_node * __init xbc_add_sibling(char *data, uint32_t flag) 482 + static inline struct xbc_node * __init xbc_add_sibling(char *data, uint16_t flag) 486 483 { 487 484 return __xbc_add_sibling(data, flag, false); 488 485 } 489 486 490 - static inline struct xbc_node * __init xbc_add_head_sibling(char *data, uint32_t flag) 487 + static inline struct xbc_node * __init xbc_add_head_sibling(char *data, uint16_t flag) 491 488 { 492 489 return __xbc_add_sibling(data, flag, true); 493 490 } 494 491 495 - static inline __init struct xbc_node *xbc_add_child(char *data, uint32_t flag) 492 + static inline __init struct xbc_node *xbc_add_child(char *data, uint16_t flag) 496 493 { 497 494 struct xbc_node *node = xbc_add_sibling(data, flag); 498 495 ··· 660 655 if (unlikely(xbc_node_num == 0)) 661 656 goto add_node; 662 657 663 - if (!last_parent) /* the first level */ 658 + if (!last_parent) { /* the first level */ 664 659 node = find_match_node(xbc_nodes, k); 665 - else { 660 + } else { 666 661 child = xbc_node_get_child(last_parent); 667 662 /* Since the value node is the first child, skip it. */ 668 663 if (child && xbc_node_is_value(child)) ··· 670 665 node = find_match_node(child, k); 671 666 } 672 667 673 - if (node) 668 + if (node) { 674 669 last_parent = node; 675 - else { 670 + } else { 676 671 add_node: 677 672 node = xbc_add_child(k, XBC_KEY); 678 673 if (!node) ··· 803 798 804 799 static int __init xbc_verify_tree(void) 805 800 { 806 - int i, depth, len, wlen; 801 + int i, depth; 802 + size_t len, wlen; 807 803 struct xbc_node *n, *m; 808 804 809 805 /* Brace closing */ ··· 821 815 } 822 816 823 817 for (i = 0; i < xbc_node_num; i++) { 824 - if (xbc_nodes[i].next > xbc_node_num) { 818 + if (xbc_nodes[i].next >= xbc_node_num) { 825 819 return xbc_parse_error("No closing brace", 820 + xbc_node_get_data(xbc_nodes + i)); 821 + } 822 + if (xbc_nodes[i].child >= xbc_node_num) { 823 + return xbc_parse_error("Broken child node", 826 824 xbc_node_get_data(xbc_nodes + i)); 827 825 } 828 826 } ··· 990 980 _xbc_exit(true); 991 981 return -ENOMEM; 992 982 } 993 - memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX); 994 983 995 984 ret = xbc_parse_tree(); 996 985 if (!ret) ··· 1001 992 if (emsg) 1002 993 *emsg = xbc_err_msg; 1003 994 _xbc_exit(true); 1004 - } else 995 + } else { 1005 996 ret = xbc_node_num; 997 + } 1006 998 1007 999 return ret; 1008 1000 }