Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * /proc/bootconfig - Extra boot configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/bootconfig.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static char *saved_boot_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static int boot_config_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	if (saved_boot_config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 		seq_puts(m, saved_boot_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Rest size of buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* Return the needed total length if @size is 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int __init copy_xbc_key_value_list(char *dst, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	struct xbc_node *leaf, *vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	char *key, *end = dst + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	const char *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	char q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	xbc_for_each_key_value(leaf, val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		ret = snprintf(dst, rest(dst, end), "%s = ", key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		dst += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		vnode = xbc_node_get_child(leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		if (vnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 			xbc_array_for_each_value(vnode, val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 				if (strchr(val, '"'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 					q = '\'';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 					q = '"';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 				ret = snprintf(dst, rest(dst, end), "%c%s%c%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 					q, val, q, xbc_node_is_array(vnode) ? ", " : "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 				if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 				dst += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 			ret = snprintf(dst, rest(dst, end), "\"\"\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 			dst += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	kfree(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	return ret < 0 ? ret : dst - (end - size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static int __init proc_boot_config_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	len = copy_xbc_key_value_list(NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	if (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 		saved_boot_config = kzalloc(len + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		if (!saved_boot_config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		len = copy_xbc_key_value_list(saved_boot_config, len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 		if (len < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 			kfree(saved_boot_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 			return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 	proc_create_single("bootconfig", 0, NULL, boot_config_proc_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) fs_initcall(proc_boot_config_init);