Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: interface authorization: SysFS part of USB interface authorization

This introduces an attribute for each interface to
authorize (1) or deauthorize (0) it:
/sys/bus/usb/devices/INTERFACE/authorized

Signed-off-by: Stefan Koch <stefan.koch10@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Stefan Koch and committed by
Greg Kroah-Hartman
310d2b41 b3910cef

+36
+36
drivers/usb/core/sysfs.c
··· 957 957 } 958 958 static DEVICE_ATTR_RO(supports_autosuspend); 959 959 960 + /* 961 + * interface_authorized_show - show authorization status of an USB interface 962 + * 1 is authorized, 0 is deauthorized 963 + */ 964 + static ssize_t interface_authorized_show(struct device *dev, 965 + struct device_attribute *attr, char *buf) 966 + { 967 + struct usb_interface *intf = to_usb_interface(dev); 968 + 969 + return sprintf(buf, "%u\n", intf->authorized); 970 + } 971 + 972 + /* 973 + * interface_authorized_store - authorize or deauthorize an USB interface 974 + */ 975 + static ssize_t interface_authorized_store(struct device *dev, 976 + struct device_attribute *attr, const char *buf, size_t count) 977 + { 978 + struct usb_interface *intf = to_usb_interface(dev); 979 + bool val; 980 + 981 + if (strtobool(buf, &val) != 0) 982 + return -EINVAL; 983 + 984 + if (val) 985 + usb_authorize_interface(intf); 986 + else 987 + usb_deauthorize_interface(intf); 988 + 989 + return count; 990 + } 991 + static struct device_attribute dev_attr_interface_authorized = 992 + __ATTR(authorized, S_IRUGO | S_IWUSR, 993 + interface_authorized_show, interface_authorized_store); 994 + 960 995 static struct attribute *intf_attrs[] = { 961 996 &dev_attr_bInterfaceNumber.attr, 962 997 &dev_attr_bAlternateSetting.attr, ··· 1001 966 &dev_attr_bInterfaceProtocol.attr, 1002 967 &dev_attr_modalias.attr, 1003 968 &dev_attr_supports_autosuspend.attr, 969 + &dev_attr_interface_authorized.attr, 1004 970 NULL, 1005 971 }; 1006 972 static struct attribute_group intf_attr_grp = {