File tree Expand file tree Collapse file tree 6 files changed +63
-15
lines changed Expand file tree Collapse file tree 6 files changed +63
-15
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ usbcore-y += phy.o port.o
11
11
usbcore-$(CONFIG_OF) += of.o
12
12
usbcore-$(CONFIG_USB_PCI) += hcd-pci.o
13
13
usbcore-$(CONFIG_ACPI) += usb-acpi.o
14
+ usbcore-$(CONFIG_SYSCTL) += sysctl.o
14
15
15
16
obj-$(CONFIG_USB) += usbcore.o
16
17
Original file line number Diff line number Diff line change @@ -5054,9 +5054,6 @@ static int descriptors_changed(struct usb_device *udev,
5054
5054
return changed ;
5055
5055
}
5056
5056
5057
- /* sysctl */
5058
- int deny_new_usb __read_mostly = 0 ;
5059
-
5060
5057
static void hub_port_connect (struct usb_hub * hub , int port1 , u16 portstatus ,
5061
5058
u16 portchange )
5062
5059
{
Original file line number Diff line number Diff line change
1
+ #include <linux/errno.h>
2
+ #include <linux/init.h>
3
+ #include <linux/kmemleak.h>
4
+ #include <linux/sysctl.h>
5
+ #include <linux/usb.h>
6
+
7
+ static struct ctl_table usb_table [] = {
8
+ {
9
+ .procname = "deny_new_usb" ,
10
+ .data = & deny_new_usb ,
11
+ .maxlen = sizeof (int ),
12
+ .mode = 0644 ,
13
+ .proc_handler = proc_dointvec_minmax_sysadmin ,
14
+ .extra1 = SYSCTL_ZERO ,
15
+ .extra2 = SYSCTL_ONE ,
16
+ },
17
+ { }
18
+ };
19
+
20
+ static struct ctl_table usb_root_table [] = {
21
+ { .procname = "kernel" ,
22
+ .mode = 0555 ,
23
+ .child = usb_table },
24
+ { }
25
+ };
26
+
27
+ static struct ctl_table_header * usb_table_header ;
28
+
29
+ int __init usb_init_sysctl (void )
30
+ {
31
+ usb_table_header = register_sysctl_table (usb_root_table );
32
+ if (!usb_table_header ) {
33
+ pr_warn ("usb: sysctl registration failed\n" );
34
+ return - ENOMEM ;
35
+ }
36
+
37
+ kmemleak_not_leak (usb_table_header );
38
+ return 0 ;
39
+ }
40
+
41
+ void usb_exit_sysctl (void )
42
+ {
43
+ unregister_sysctl_table (usb_table_header );
44
+ }
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
72
72
#define usb_autosuspend_delay 0
73
73
#endif
74
74
75
+ int deny_new_usb __read_mostly = 0 ;
76
+ EXPORT_SYMBOL (deny_new_usb );
77
+
75
78
static bool match_endpoint (struct usb_endpoint_descriptor * epd ,
76
79
struct usb_endpoint_descriptor * * bulk_in ,
77
80
struct usb_endpoint_descriptor * * bulk_out ,
@@ -978,6 +981,9 @@ static int __init usb_init(void)
978
981
usb_debugfs_init ();
979
982
980
983
usb_acpi_register ();
984
+ retval = usb_init_sysctl ();
985
+ if (retval )
986
+ goto sysctl_init_failed ;
981
987
retval = bus_register (& usb_bus_type );
982
988
if (retval )
983
989
goto bus_register_failed ;
@@ -1012,6 +1018,8 @@ static int __init usb_init(void)
1012
1018
bus_notifier_failed :
1013
1019
bus_unregister (& usb_bus_type );
1014
1020
bus_register_failed :
1021
+ usb_exit_sysctl ();
1022
+ sysctl_init_failed :
1015
1023
usb_acpi_unregister ();
1016
1024
usb_debugfs_cleanup ();
1017
1025
out :
@@ -1035,6 +1043,7 @@ static void __exit usb_exit(void)
1035
1043
usb_hub_cleanup ();
1036
1044
bus_unregister_notifier (& usb_bus_type , & usb_bus_nb );
1037
1045
bus_unregister (& usb_bus_type );
1046
+ usb_exit_sysctl ();
1038
1047
usb_acpi_unregister ();
1039
1048
usb_debugfs_cleanup ();
1040
1049
idr_destroy (& usb_bus_idr );
Original file line number Diff line number Diff line change @@ -2035,8 +2035,16 @@ extern void usb_led_activity(enum usb_led_event ev);
2035
2035
static inline void usb_led_activity (enum usb_led_event ev ) {}
2036
2036
#endif
2037
2037
2038
- /* sysctl */
2038
+ /* sysctl.c */
2039
2039
extern int deny_new_usb ;
2040
+ #ifdef CONFIG_SYSCTL
2041
+ extern int usb_init_sysctl (void );
2042
+ extern void usb_exit_sysctl (void );
2043
+ #else
2044
+ static inline int usb_init_sysctl (void ) { return 0 ; }
2045
+ static inline void usb_exit_sysctl (void ) { }
2046
+ #endif /* CONFIG_SYSCTL */
2047
+
2040
2048
2041
2049
#endif /* __KERNEL__ */
2042
2050
Original file line number Diff line number Diff line change @@ -2322,17 +2322,6 @@ static struct ctl_table kern_table[] = {
2322
2322
.extra1 = SYSCTL_ZERO ,
2323
2323
.extra2 = SYSCTL_ONE ,
2324
2324
},
2325
- #if IS_ENABLED (CONFIG_USB )
2326
- {
2327
- .procname = "deny_new_usb" ,
2328
- .data = & deny_new_usb ,
2329
- .maxlen = sizeof (int ),
2330
- .mode = 0644 ,
2331
- .proc_handler = proc_dointvec_minmax_sysadmin ,
2332
- .extra1 = SYSCTL_ZERO ,
2333
- .extra2 = SYSCTL_ONE ,
2334
- },
2335
- #endif
2336
2325
{
2337
2326
.procname = "ngroups_max" ,
2338
2327
.data = & ngroups_max ,
You can’t perform that action at this time.
0 commit comments