On Thu, Jun 18, 2015 at 07:23:25PM +0200, Stefan Koch wrote:
> 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 <[email protected]>
> ---
> drivers/usb/core/sysfs.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
> index d269738..457bff5 100644
> --- a/drivers/usb/core/sysfs.c
> +++ b/drivers/usb/core/sysfs.c
> @@ -926,6 +926,46 @@ static ssize_t supports_autosuspend_show(struct device
> *dev,
> }
> static DEVICE_ATTR_RO(supports_autosuspend);
>
> +/*
> + * interface_authorized_show - show authorization status of an USB interface
> + * 1 is authorized, 0 is deauthorized
> + */
> +static ssize_t interface_authorized_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct usb_interface *intf = to_usb_interface(dev);
> +
> + return sprintf(buf, "%u\n", intf->authorized);
> +}
> +
> +/*
> + * interface_authorized_store - authorize or deauthorize an USB interface
> + * 1 is to authorize, 0 is to deauthorize
Not only 1/0, but Y/N, y/n and other combinations that strtobool
handles.
No need to have this comment line at all.
> + */
> +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);
> + bool val;
> +
> + if (strtobool(buf, &val) != 0)
> + return -EINVAL;
> +
> + switch (val) {
> + case 0:
true and false as this is a boolean?
And because it is, just turn this into a simple if/else statement, it's
less lines.
> + usb_deauthorize_interface(intf);
> + break;
> + case 1:
> + usb_authorize_interface(intf);
> + break;
> + }
> +
> + return count;
> +}
> +static struct device_attribute dev_attr_interface_authorized =
> + __ATTR(authorized, S_IRUGO | S_IWUSR,
__ATTR_RW()?
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html