1 // SPDX-License-Identifier: GPL-2.0
3 * /proc/bootconfig - Extra boot configuration
6 #include <linux/init.h>
7 #include <linux/printk.h>
8 #include <linux/proc_fs.h>
9 #include <linux/seq_file.h>
10 #include <linux/bootconfig.h>
11 #include <linux/slab.h>
13 static char *saved_boot_config
;
15 static int boot_config_proc_show(struct seq_file
*m
, void *v
)
17 if (saved_boot_config
)
18 seq_puts(m
, saved_boot_config
);
22 /* Rest size of buffer */
23 #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0)
25 /* Return the needed total length if @size is 0 */
26 static int __init
copy_xbc_key_value_list(char *dst
, size_t size
)
28 struct xbc_node
*leaf
, *vnode
;
30 char *key
, *end
= dst
+ size
;
33 key
= kzalloc(XBC_KEYLEN_MAX
, GFP_KERNEL
);
35 xbc_for_each_key_value(leaf
, val
) {
36 ret
= xbc_node_compose_key(leaf
, key
, XBC_KEYLEN_MAX
);
39 ret
= snprintf(dst
, rest(dst
, end
), "%s = ", key
);
43 vnode
= xbc_node_get_child(leaf
);
44 if (vnode
&& xbc_node_is_array(vnode
)) {
45 xbc_array_for_each_value(vnode
, val
) {
46 ret
= snprintf(dst
, rest(dst
, end
), "\"%s\"%s",
47 val
, vnode
->next
? ", " : "\n");
53 ret
= snprintf(dst
, rest(dst
, end
), "\"%s\"\n", val
);
62 return ret
< 0 ? ret
: dst
- (end
- size
);
65 static int __init
proc_boot_config_init(void)
69 len
= copy_xbc_key_value_list(NULL
, 0);
74 saved_boot_config
= kzalloc(len
+ 1, GFP_KERNEL
);
75 if (!saved_boot_config
)
78 len
= copy_xbc_key_value_list(saved_boot_config
, len
+ 1);
80 kfree(saved_boot_config
);
85 proc_create_single("bootconfig", 0, NULL
, boot_config_proc_show
);
89 fs_initcall(proc_boot_config_init
);