1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/types.h>
4 #include <linux/kconfig.h>
5 #include <linux/list.h>
6 #include <linux/slab.h>
7 #include <linux/export.h>
8 #include <linux/security.h>
9 #include <linux/highmem.h>
10 #include <linux/umh.h>
11 #include <linux/sysctl.h>
12 
13 #include "fallback.h"
14 #include "firmware.h"
15 
16 /*
17  * firmware fallback configuration table
18  */
19 
20 struct firmware_fallback_config fw_fallback_config = {
21 	.force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK),
22 	.loading_timeout = 60,
23 	.old_timeout = 60,
24 };
25 EXPORT_SYMBOL_NS_GPL(fw_fallback_config, FIRMWARE_LOADER_PRIVATE);
26 
27 #ifdef CONFIG_SYSCTL
28 static struct ctl_table firmware_config_table[] = {
29 	{
30 		.procname	= "force_sysfs_fallback",
31 		.data		= &fw_fallback_config.force_sysfs_fallback,
32 		.maxlen         = sizeof(unsigned int),
33 		.mode           = 0644,
34 		.proc_handler   = proc_douintvec_minmax,
35 		.extra1		= SYSCTL_ZERO,
36 		.extra2		= SYSCTL_ONE,
37 	},
38 	{
39 		.procname	= "ignore_sysfs_fallback",
40 		.data		= &fw_fallback_config.ignore_sysfs_fallback,
41 		.maxlen         = sizeof(unsigned int),
42 		.mode           = 0644,
43 		.proc_handler   = proc_douintvec_minmax,
44 		.extra1		= SYSCTL_ZERO,
45 		.extra2		= SYSCTL_ONE,
46 	},
47 	{ }
48 };
49 
50 static struct ctl_table_header *firmware_config_sysct_table_header;
51 int register_firmware_config_sysctl(void)
52 {
53 	firmware_config_sysct_table_header =
54 		register_sysctl("kernel/firmware_config",
55 				firmware_config_table);
56 	if (!firmware_config_sysct_table_header)
57 		return -ENOMEM;
58 	return 0;
59 }
60 EXPORT_SYMBOL_NS_GPL(register_firmware_config_sysctl, FIRMWARE_LOADER_PRIVATE);
61 
62 void unregister_firmware_config_sysctl(void)
63 {
64 	unregister_sysctl_table(firmware_config_sysct_table_header);
65 	firmware_config_sysct_table_header = NULL;
66 }
67 EXPORT_SYMBOL_NS_GPL(unregister_firmware_config_sysctl, FIRMWARE_LOADER_PRIVATE);
68 
69 #endif /* CONFIG_SYSCTL */
70