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
1111usbcore-$(CONFIG_OF) += of.o
1212usbcore-$(CONFIG_USB_PCI) += hcd-pci.o
1313usbcore-$(CONFIG_ACPI) += usb-acpi.o
14+ usbcore-$(CONFIG_SYSCTL) += sysctl.o
1415
1516obj-$(CONFIG_USB) += usbcore.o
1617
Original file line number Diff line number Diff line change @@ -5054,9 +5054,6 @@ static int descriptors_changed(struct usb_device *udev,
50545054 return changed ;
50555055}
50565056
5057- /* sysctl */
5058- int deny_new_usb __read_mostly = 0 ;
5059-
50605057static void hub_port_connect (struct usb_hub * hub , int port1 , u16 portstatus ,
50615058 u16 portchange )
50625059{
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");
7272#define usb_autosuspend_delay 0
7373#endif
7474
75+ int deny_new_usb __read_mostly = 0 ;
76+ EXPORT_SYMBOL (deny_new_usb );
77+
7578static bool match_endpoint (struct usb_endpoint_descriptor * epd ,
7679 struct usb_endpoint_descriptor * * bulk_in ,
7780 struct usb_endpoint_descriptor * * bulk_out ,
@@ -978,6 +981,9 @@ static int __init usb_init(void)
978981 usb_debugfs_init ();
979982
980983 usb_acpi_register ();
984+ retval = usb_init_sysctl ();
985+ if (retval )
986+ goto sysctl_init_failed ;
981987 retval = bus_register (& usb_bus_type );
982988 if (retval )
983989 goto bus_register_failed ;
@@ -1012,6 +1018,8 @@ static int __init usb_init(void)
10121018bus_notifier_failed :
10131019 bus_unregister (& usb_bus_type );
10141020bus_register_failed :
1021+ usb_exit_sysctl ();
1022+ sysctl_init_failed :
10151023 usb_acpi_unregister ();
10161024 usb_debugfs_cleanup ();
10171025out :
@@ -1035,6 +1043,7 @@ static void __exit usb_exit(void)
10351043 usb_hub_cleanup ();
10361044 bus_unregister_notifier (& usb_bus_type , & usb_bus_nb );
10371045 bus_unregister (& usb_bus_type );
1046+ usb_exit_sysctl ();
10381047 usb_acpi_unregister ();
10391048 usb_debugfs_cleanup ();
10401049 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);
20352035static inline void usb_led_activity (enum usb_led_event ev ) {}
20362036#endif
20372037
2038- /* sysctl */
2038+ /* sysctl.c */
20392039extern 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+
20402048
20412049#endif /* __KERNEL__ */
20422050
Original file line number Diff line number Diff line change @@ -2322,17 +2322,6 @@ static struct ctl_table kern_table[] = {
23222322 .extra1 = SYSCTL_ZERO ,
23232323 .extra2 = SYSCTL_ONE ,
23242324 },
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
23362325 {
23372326 .procname = "ngroups_max" ,
23382327 .data = & ngroups_max ,
You can’t perform that action at this time.
0 commit comments