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: Cleanup dummy headers in tools/bootconfig

Cleanup dummy headers in tools/bootconfig/include except
for tools/bootconfig/include/linux/bootconfig.h.
For this change, I use __KERNEL__ macro to split kernel
header #include and introduce xbc_alloc_mem() and
xbc_free_mem().

Link: https://lkml.kernel.org/r/163187299574.2366983.18371329724128746091.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)
4ee1b4ca 4f292c48

+93 -91
+10
include/linux/bootconfig.h
··· 7 7 * Author: Masami Hiramatsu <mhiramat@kernel.org> 8 8 */ 9 9 10 + #ifdef __KERNEL__ 10 11 #include <linux/kernel.h> 11 12 #include <linux/types.h> 13 + #else /* !__KERNEL__ */ 14 + /* 15 + * NOTE: This is only for tools/bootconfig, because tools/bootconfig will 16 + * run the parser sanity test. 17 + * This does NOT mean linux/bootconfig.h is available in the user space. 18 + * However, if you change this file, please make sure the tools/bootconfig 19 + * has no issue on building and running. 20 + */ 21 + #endif 12 22 13 23 #define BOOTCONFIG_MAGIC "#BOOTCONFIG\n" 14 24 #define BOOTCONFIG_MAGIC_LEN 12
+38 -5
lib/bootconfig.c
··· 4 4 * Masami Hiramatsu <mhiramat@kernel.org> 5 5 */ 6 6 7 + #ifdef __KERNEL__ 7 8 #include <linux/bootconfig.h> 8 9 #include <linux/bug.h> 9 10 #include <linux/ctype.h> ··· 12 11 #include <linux/kernel.h> 13 12 #include <linux/memblock.h> 14 13 #include <linux/string.h> 14 + #else /* !__KERNEL__ */ 15 + /* 16 + * NOTE: This is only for tools/bootconfig, because tools/bootconfig will 17 + * run the parser sanity test. 18 + * This does NOT mean lib/bootconfig.c is available in the user space. 19 + * However, if you change this file, please make sure the tools/bootconfig 20 + * has no issue on building and running. 21 + */ 22 + #include <linux/bootconfig.h> 23 + #endif 15 24 16 25 /* 17 26 * Extra Boot Config (XBC) is given as tree-structured ascii text of ··· 42 31 static int open_brace[XBC_DEPTH_MAX] __initdata; 43 32 static int brace_index __initdata; 44 33 34 + #ifdef __KERNEL__ 35 + static inline void *xbc_alloc_mem(size_t size) 36 + { 37 + return memblock_alloc(size, SMP_CACHE_BYTES); 38 + } 39 + 40 + static inline void xbc_free_mem(void *addr, size_t size) 41 + { 42 + memblock_free_ptr(addr, size); 43 + } 44 + 45 + #else /* !__KERNEL__ */ 46 + 47 + static inline void *xbc_alloc_mem(size_t size) 48 + { 49 + return malloc(size); 50 + } 51 + 52 + static inline void xbc_free_mem(void *addr, size_t size) 53 + { 54 + free(addr); 55 + } 56 + #endif 45 57 /** 46 58 * xbc_get_info() - Get the information of loaded boot config 47 59 * node_size: A pointer to store the number of nodes. ··· 893 859 */ 894 860 void __init xbc_exit(void) 895 861 { 896 - memblock_free_ptr(xbc_data, xbc_data_size); 862 + xbc_free_mem(xbc_data, xbc_data_size); 897 863 xbc_data = NULL; 898 864 xbc_data_size = 0; 899 865 xbc_node_num = 0; 900 - memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); 866 + xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); 901 867 xbc_nodes = NULL; 902 868 brace_index = 0; 903 869 } ··· 936 902 return -ERANGE; 937 903 } 938 904 939 - xbc_data = memblock_alloc(size + 1, SMP_CACHE_BYTES); 905 + xbc_data = xbc_alloc_mem(size + 1); 940 906 if (!xbc_data) { 941 907 if (emsg) 942 908 *emsg = "Failed to allocate bootconfig data"; ··· 946 912 xbc_data[size] = '\0'; 947 913 xbc_data_size = size + 1; 948 914 949 - xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX, 950 - SMP_CACHE_BYTES); 915 + xbc_nodes = xbc_alloc_mem(sizeof(struct xbc_node) * XBC_NODE_MAX); 951 916 if (!xbc_nodes) { 952 917 if (emsg) 953 918 *emsg = "Failed to allocate bootconfig nodes";
+1 -1
tools/bootconfig/Makefile
··· 17 17 18 18 all: $(ALL_PROGRAMS) test 19 19 20 - $(OUTPUT)bootconfig: main.c $(LIBSRC) 20 + $(OUTPUT)bootconfig: main.c include/linux/bootconfig.h $(LIBSRC) 21 21 $(CC) $(filter %.c,$^) $(CFLAGS) -o $@ 22 22 23 23 test: $(ALL_PROGRAMS) test-bootconfig.sh
+44 -1
tools/bootconfig/include/linux/bootconfig.h
··· 2 2 #ifndef _BOOTCONFIG_LINUX_BOOTCONFIG_H 3 3 #define _BOOTCONFIG_LINUX_BOOTCONFIG_H 4 4 5 - #include "../../../../include/linux/bootconfig.h" 5 + #include <stdio.h> 6 + #include <stdlib.h> 7 + #include <stdint.h> 8 + #include <stdbool.h> 9 + #include <ctype.h> 10 + #include <errno.h> 11 + #include <string.h> 12 + 6 13 7 14 #ifndef fallthrough 8 15 # define fallthrough 9 16 #endif 17 + 18 + #define WARN_ON(cond) \ 19 + ((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \ 20 + __FILE__, __LINE__, __func__, #cond) : 0) 21 + 22 + #define unlikely(cond) (cond) 23 + 24 + /* Copied from lib/string.c */ 25 + static inline char *skip_spaces(const char *str) 26 + { 27 + while (isspace(*str)) 28 + ++str; 29 + return (char *)str; 30 + } 31 + 32 + static inline char *strim(char *s) 33 + { 34 + size_t size; 35 + char *end; 36 + 37 + size = strlen(s); 38 + if (!size) 39 + return s; 40 + 41 + end = s + size - 1; 42 + while (end >= s && isspace(*end)) 43 + end--; 44 + *(end + 1) = '\0'; 45 + 46 + return skip_spaces(s); 47 + } 48 + 49 + #define __init 50 + #define __initdata 51 + 52 + #include "../../../../include/linux/bootconfig.h" 10 53 11 54 #endif
-12
tools/bootconfig/include/linux/bug.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _SKC_LINUX_BUG_H 3 - #define _SKC_LINUX_BUG_H 4 - 5 - #include <stdio.h> 6 - #include <stdlib.h> 7 - 8 - #define WARN_ON(cond) \ 9 - ((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \ 10 - __FILE__, __LINE__, __func__, #cond) : 0) 11 - 12 - #endif
-7
tools/bootconfig/include/linux/ctype.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _SKC_LINUX_CTYPE_H 3 - #define _SKC_LINUX_CTYPE_H 4 - 5 - #include <ctype.h> 6 - 7 - #endif
-7
tools/bootconfig/include/linux/errno.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _SKC_LINUX_ERRNO_H 3 - #define _SKC_LINUX_ERRNO_H 4 - 5 - #include <asm/errno.h> 6 - 7 - #endif
-14
tools/bootconfig/include/linux/kernel.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _SKC_LINUX_KERNEL_H 3 - #define _SKC_LINUX_KERNEL_H 4 - 5 - #include <stdlib.h> 6 - #include <stdint.h> 7 - #include <stdbool.h> 8 - 9 - #define unlikely(cond) (cond) 10 - 11 - #define __init 12 - #define __initdata 13 - 14 - #endif
-11
tools/bootconfig/include/linux/memblock.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _XBC_LINUX_MEMBLOCK_H 3 - #define _XBC_LINUX_MEMBLOCK_H 4 - 5 - #include <stdlib.h> 6 - 7 - #define SMP_CACHE_BYTES 0 8 - #define memblock_alloc(size, align) malloc(size) 9 - #define memblock_free_ptr(paddr, size) free(paddr) 10 - 11 - #endif
-32
tools/bootconfig/include/linux/string.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _SKC_LINUX_STRING_H 3 - #define _SKC_LINUX_STRING_H 4 - 5 - #include <string.h> 6 - 7 - /* Copied from lib/string.c */ 8 - static inline char *skip_spaces(const char *str) 9 - { 10 - while (isspace(*str)) 11 - ++str; 12 - return (char *)str; 13 - } 14 - 15 - static inline char *strim(char *s) 16 - { 17 - size_t size; 18 - char *end; 19 - 20 - size = strlen(s); 21 - if (!size) 22 - return s; 23 - 24 - end = s + size - 1; 25 - while (end >= s && isspace(*end)) 26 - end--; 27 - *(end + 1) = '\0'; 28 - 29 - return skip_spaces(s); 30 - } 31 - 32 - #endif
-1
tools/bootconfig/main.c
··· 12 12 #include <errno.h> 13 13 #include <endian.h> 14 14 15 - #include <linux/kernel.h> 16 15 #include <linux/bootconfig.h> 17 16 18 17 #define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)