usb: implement dedicated subsystem sysctl tables
This moves the usb related sysctl knobs to an own usb local sysctl table in order to clean up the global sysctl as well as allow the knob to be exported and referenced appropriately when building the usb components as dedicated modules. Signed-off-by: Levente Polyak <levente@leventepolyak.net>
This commit is contained in:
parent
7853f26eff
commit
ba091cb014
|
@ -11,6 +11,7 @@ usbcore-y += phy.o port.o
|
|||
usbcore-$(CONFIG_OF) += of.o
|
||||
usbcore-$(CONFIG_USB_PCI) += hcd-pci.o
|
||||
usbcore-$(CONFIG_ACPI) += usb-acpi.o
|
||||
usbcore-$(CONFIG_SYSCTL) += sysctl.o
|
||||
|
||||
obj-$(CONFIG_USB) += usbcore.o
|
||||
|
||||
|
|
|
@ -5055,9 +5055,6 @@ static int descriptors_changed(struct usb_device *udev,
|
|||
return changed;
|
||||
}
|
||||
|
||||
/* sysctl */
|
||||
int deny_new_usb __read_mostly = 0;
|
||||
|
||||
static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
|
||||
u16 portchange)
|
||||
{
|
||||
|
|
44
drivers/usb/core/sysctl.c
Normal file
44
drivers/usb/core/sysctl.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <linux/errno.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kmemleak.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
static struct ctl_table usb_table[] = {
|
||||
{
|
||||
.procname = "deny_new_usb",
|
||||
.data = &deny_new_usb,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec_minmax_sysadmin,
|
||||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
{ }
|
||||
};
|
||||
|
||||
static struct ctl_table usb_root_table[] = {
|
||||
{ .procname = "kernel",
|
||||
.mode = 0555,
|
||||
.child = usb_table },
|
||||
{ }
|
||||
};
|
||||
|
||||
static struct ctl_table_header *usb_table_header;
|
||||
|
||||
int __init usb_init_sysctl(void)
|
||||
{
|
||||
usb_table_header = register_sysctl_table(usb_root_table);
|
||||
if (!usb_table_header) {
|
||||
pr_warn("usb: sysctl registration failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
kmemleak_not_leak(usb_table_header);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usb_exit_sysctl(void)
|
||||
{
|
||||
unregister_sysctl_table(usb_table_header);
|
||||
}
|
|
@ -71,6 +71,9 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
|
|||
#define usb_autosuspend_delay 0
|
||||
#endif
|
||||
|
||||
int deny_new_usb __read_mostly = 0;
|
||||
EXPORT_SYMBOL(deny_new_usb);
|
||||
|
||||
static bool match_endpoint(struct usb_endpoint_descriptor *epd,
|
||||
struct usb_endpoint_descriptor **bulk_in,
|
||||
struct usb_endpoint_descriptor **bulk_out,
|
||||
|
@ -1010,6 +1013,9 @@ static int __init usb_init(void)
|
|||
usb_debugfs_init();
|
||||
|
||||
usb_acpi_register();
|
||||
retval = usb_init_sysctl();
|
||||
if (retval)
|
||||
goto sysctl_init_failed;
|
||||
retval = bus_register(&usb_bus_type);
|
||||
if (retval)
|
||||
goto bus_register_failed;
|
||||
|
@ -1044,6 +1050,8 @@ major_init_failed:
|
|||
bus_notifier_failed:
|
||||
bus_unregister(&usb_bus_type);
|
||||
bus_register_failed:
|
||||
usb_exit_sysctl();
|
||||
sysctl_init_failed:
|
||||
usb_acpi_unregister();
|
||||
usb_debugfs_cleanup();
|
||||
out:
|
||||
|
@ -1067,6 +1075,7 @@ static void __exit usb_exit(void)
|
|||
usb_hub_cleanup();
|
||||
bus_unregister_notifier(&usb_bus_type, &usb_bus_nb);
|
||||
bus_unregister(&usb_bus_type);
|
||||
usb_exit_sysctl();
|
||||
usb_acpi_unregister();
|
||||
usb_debugfs_cleanup();
|
||||
idr_destroy(&usb_bus_idr);
|
||||
|
|
|
@ -2037,8 +2037,16 @@ extern void usb_led_activity(enum usb_led_event ev);
|
|||
static inline void usb_led_activity(enum usb_led_event ev) {}
|
||||
#endif
|
||||
|
||||
/* sysctl */
|
||||
/* sysctl.c */
|
||||
extern int deny_new_usb;
|
||||
#ifdef CONFIG_SYSCTL
|
||||
extern int usb_init_sysctl(void);
|
||||
extern void usb_exit_sysctl(void);
|
||||
#else
|
||||
static inline int usb_init_sysctl(void) { return 0; }
|
||||
static inline void usb_exit_sysctl(void) { }
|
||||
#endif /* CONFIG_SYSCTL */
|
||||
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
|
|
|
@ -106,9 +106,6 @@
|
|||
#ifdef CONFIG_USER_NS
|
||||
#include <linux/user_namespace.h>
|
||||
#endif
|
||||
#if IS_ENABLED(CONFIG_USB)
|
||||
#include <linux/usb.h>
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SYSCTL)
|
||||
|
||||
|
@ -2308,17 +2305,6 @@ static struct ctl_table kern_table[] = {
|
|||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
#if IS_ENABLED(CONFIG_USB)
|
||||
{
|
||||
.procname = "deny_new_usb",
|
||||
.data = &deny_new_usb,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = proc_dointvec_minmax_sysadmin,
|
||||
.extra1 = SYSCTL_ZERO,
|
||||
.extra2 = SYSCTL_ONE,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.procname = "ngroups_max",
|
||||
.data = &ngroups_max,
|
||||
|
|
Loading…
Reference in a new issue