Hello. On 6/13/2015 12:28 AM, Stefan Koch wrote:
To allow (1) or deny (0) interfaces a mask or interface attributes could written.
"Could be written", perhaps?
For interfaces that belongs together use the mask for authorization.
Belong.
As default each bit has the initial value of the default authorization bit. Entry: /sys/bus/usb/devices/*-*:*.*/interface_authorized
Signed-off-by: Stefan Koch <skoch@xxxxxxx> --- drivers/usb/core/sysfs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index afa0799e..54e2e8e 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -995,6 +995,60 @@ static ssize_t supports_autosuspend_show(struct device *dev, } static DEVICE_ATTR_RO(supports_autosuspend); +/* + * show authorization status of usb interface
USB. [...]
+/* + * authorize or deauthorize an usb interface
USB.
+ * 1 is to authorize, 0 is to deauthorize + */ +static ssize_t interface_authorized_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct usb_interface *intf = to_usb_interface(dev); + struct usb_device *usb_pdev = NULL; + int rc = 0; + unsigned val = 0; + unsigned intf_nr = 0;
No need for these initializers.
+ u32 mask = 0; + + if (!dev->parent || !intf || !intf->cur_altsetting) + return -ENODEV; + + usb_pdev = to_usb_device(dev->parent); +
No need for this empty line.
+ if (!usb_pdev) + return -ENODEV; + + mask = usb_pdev->mask; + intf_nr = intf->cur_altsetting->desc.bInterfaceNumber; + + if (sscanf(buf, "%u\n", &val) != 1) + return -EINVAL; + + if (val == 0) + mask &= ~(1 << intf_nr); + else if (val == 1) + mask |= (1 << intf_nr);
Parens not needed here. These *if* statements ask to be a *switch* statement instead.
+ + rc = usb_device_set_mask(dev->parent, mask); + + return rc < 0 ? rc : count; +} +static DEVICE_ATTR_RW(interface_authorized); +
[...] WBR, Sergei -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html