Skip to content

Commit a91e4f1

Browse files
mhiramatrostedt
authored andcommitted
bootconfig: Allocate xbc_nodes array dynamically
To reduce the large static array from kernel data, allocate xbc_nodes array dynamically only if the kernel loads a bootconfig. Note that this also add dummy memblock.h for user-spacae bootconfig tool. Link: http://lkml.kernel.org/r/158108569699.3187.6512834527603883707.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent f61872b commit a91e4f1

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/bootconfig.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
#define pr_fmt(fmt) "bootconfig: " fmt
88

9+
#include <linux/bootconfig.h>
910
#include <linux/bug.h>
1011
#include <linux/ctype.h>
1112
#include <linux/errno.h>
1213
#include <linux/kernel.h>
14+
#include <linux/memblock.h>
1315
#include <linux/printk.h>
14-
#include <linux/bootconfig.h>
1516
#include <linux/string.h>
1617

1718
/*
@@ -23,7 +24,7 @@
2324
* node (for array).
2425
*/
2526

26-
static struct xbc_node xbc_nodes[XBC_NODE_MAX] __initdata;
27+
static struct xbc_node *xbc_nodes __initdata;
2728
static int xbc_node_num __initdata;
2829
static char *xbc_data __initdata;
2930
static size_t xbc_data_size __initdata;
@@ -719,7 +720,8 @@ void __init xbc_destroy_all(void)
719720
xbc_data = NULL;
720721
xbc_data_size = 0;
721722
xbc_node_num = 0;
722-
memset(xbc_nodes, 0, sizeof(xbc_nodes));
723+
memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX);
724+
xbc_nodes = NULL;
723725
}
724726

725727
/**
@@ -748,6 +750,13 @@ int __init xbc_init(char *buf)
748750
return -ERANGE;
749751
}
750752

753+
xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX,
754+
SMP_CACHE_BYTES);
755+
if (!xbc_nodes) {
756+
pr_err("Failed to allocate memory for bootconfig nodes.\n");
757+
return -ENOMEM;
758+
}
759+
memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX);
751760
xbc_data = buf;
752761
xbc_data_size = ret + 1;
753762
last_parent = NULL;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 __pa(addr) (addr)
8+
#define SMP_CACHE_BYTES 0
9+
#define memblock_alloc(size, align) malloc(size)
10+
#define memblock_free(paddr, size) free(paddr)
11+
12+
#endif

0 commit comments

Comments
 (0)