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: Split parse-tree part from xbc_init

Split bootconfig data parser to build tree code from
xbc_init(). This is an internal cosmetic change.

Link: https://lkml.kernel.org/r/163187296647.2366983.15590065167920474865.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
f3668cde 115d4d08

+78 -69
+78 -69
lib/bootconfig.c
··· 801 801 return 0; 802 802 } 803 803 804 - /** 805 - * xbc_exit() - Clean up all parsed bootconfig 806 - * 807 - * This clears all data structures of parsed bootconfig on memory. 808 - * If you need to reuse xbc_init() with new boot config, you can 809 - * use this. 810 - */ 811 - void __init xbc_exit(void) 812 - { 813 - memblock_free_ptr(xbc_data, xbc_data_size); 814 - xbc_data = NULL; 815 - xbc_data_size = 0; 816 - xbc_node_num = 0; 817 - memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); 818 - xbc_nodes = NULL; 819 - brace_index = 0; 820 - } 821 - 822 - /** 823 - * xbc_init() - Parse given XBC file and build XBC internal tree 824 - * @data: The boot config text original data 825 - * @size: The size of @data 826 - * @emsg: A pointer of const char * to store the error message 827 - * @epos: A pointer of int to store the error position 828 - * 829 - * This parses the boot config text in @data. @size must be smaller 830 - * than XBC_DATA_MAX. 831 - * Return the number of stored nodes (>0) if succeeded, or -errno 832 - * if there is any error. 833 - * In error cases, @emsg will be updated with an error message and 834 - * @epos will be updated with the error position which is the byte offset 835 - * of @buf. If the error is not a parser error, @epos will be -1. 836 - */ 837 - int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) 804 + /* Need to setup xbc_data and xbc_nodes before call this. */ 805 + static int __init xbc_parse_tree(void) 838 806 { 839 807 char *p, *q; 840 808 int ret, c; 841 - 842 - if (epos) 843 - *epos = -1; 844 - 845 - if (xbc_data) { 846 - if (emsg) 847 - *emsg = "Bootconfig is already initialized"; 848 - return -EBUSY; 849 - } 850 - if (size > XBC_DATA_MAX || size == 0) { 851 - if (emsg) 852 - *emsg = size ? "Config data is too big" : 853 - "Config data is empty"; 854 - return -ERANGE; 855 - } 856 - 857 - xbc_data = memblock_alloc(size + 1, SMP_CACHE_BYTES); 858 - if (!xbc_data) { 859 - if (emsg) 860 - *emsg = "Failed to allocate bootconfig data"; 861 - return -ENOMEM; 862 - } 863 - memcpy(xbc_data, data, size); 864 - xbc_data[size] = '\0'; 865 - xbc_data_size = size + 1; 866 - 867 - xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX, 868 - SMP_CACHE_BYTES); 869 - if (!xbc_nodes) { 870 - if (emsg) 871 - *emsg = "Failed to allocate bootconfig nodes"; 872 - xbc_exit(); 873 - return -ENOMEM; 874 - } 875 - memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX); 876 809 877 810 last_parent = NULL; 878 811 p = xbc_data; ··· 850 917 } 851 918 } while (!ret); 852 919 920 + return ret; 921 + } 922 + 923 + /** 924 + * xbc_exit() - Clean up all parsed bootconfig 925 + * 926 + * This clears all data structures of parsed bootconfig on memory. 927 + * If you need to reuse xbc_init() with new boot config, you can 928 + * use this. 929 + */ 930 + void __init xbc_exit(void) 931 + { 932 + memblock_free_ptr(xbc_data, xbc_data_size); 933 + xbc_data = NULL; 934 + xbc_data_size = 0; 935 + xbc_node_num = 0; 936 + memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); 937 + xbc_nodes = NULL; 938 + brace_index = 0; 939 + } 940 + 941 + /** 942 + * xbc_init() - Parse given XBC file and build XBC internal tree 943 + * @data: The boot config text original data 944 + * @size: The size of @data 945 + * @emsg: A pointer of const char * to store the error message 946 + * @epos: A pointer of int to store the error position 947 + * 948 + * This parses the boot config text in @data. @size must be smaller 949 + * than XBC_DATA_MAX. 950 + * Return the number of stored nodes (>0) if succeeded, or -errno 951 + * if there is any error. 952 + * In error cases, @emsg will be updated with an error message and 953 + * @epos will be updated with the error position which is the byte offset 954 + * of @buf. If the error is not a parser error, @epos will be -1. 955 + */ 956 + int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) 957 + { 958 + int ret; 959 + 960 + if (epos) 961 + *epos = -1; 962 + 963 + if (xbc_data) { 964 + if (emsg) 965 + *emsg = "Bootconfig is already initialized"; 966 + return -EBUSY; 967 + } 968 + if (size > XBC_DATA_MAX || size == 0) { 969 + if (emsg) 970 + *emsg = size ? "Config data is too big" : 971 + "Config data is empty"; 972 + return -ERANGE; 973 + } 974 + 975 + xbc_data = memblock_alloc(size + 1, SMP_CACHE_BYTES); 976 + if (!xbc_data) { 977 + if (emsg) 978 + *emsg = "Failed to allocate bootconfig data"; 979 + return -ENOMEM; 980 + } 981 + memcpy(xbc_data, data, size); 982 + xbc_data[size] = '\0'; 983 + xbc_data_size = size + 1; 984 + 985 + xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX, 986 + SMP_CACHE_BYTES); 987 + if (!xbc_nodes) { 988 + if (emsg) 989 + *emsg = "Failed to allocate bootconfig nodes"; 990 + xbc_exit(); 991 + return -ENOMEM; 992 + } 993 + memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX); 994 + 995 + ret = xbc_parse_tree(); 853 996 if (!ret) 854 997 ret = xbc_verify_tree(); 855 998