Commit ff8e2c56 authored by Stefan Koch's avatar Stefan Koch Committed by Greg Kroah-Hartman

usb: interface authorization: Use a flag for the default device authorization

With this patch a flag instead of a variable
is used for the default device authorization.
Signed-off-by: default avatarStefan Koch <stefan.koch10@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7f59c150
...@@ -854,10 +854,10 @@ static ssize_t authorized_default_show(struct device *dev, ...@@ -854,10 +854,10 @@ static ssize_t authorized_default_show(struct device *dev,
{ {
struct usb_device *rh_usb_dev = to_usb_device(dev); struct usb_device *rh_usb_dev = to_usb_device(dev);
struct usb_bus *usb_bus = rh_usb_dev->bus; struct usb_bus *usb_bus = rh_usb_dev->bus;
struct usb_hcd *usb_hcd; struct usb_hcd *hcd;
usb_hcd = bus_to_hcd(usb_bus); hcd = bus_to_hcd(usb_bus);
return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default); return snprintf(buf, PAGE_SIZE, "%u\n", !!HCD_DEV_AUTHORIZED(hcd));
} }
static ssize_t authorized_default_store(struct device *dev, static ssize_t authorized_default_store(struct device *dev,
...@@ -868,12 +868,16 @@ static ssize_t authorized_default_store(struct device *dev, ...@@ -868,12 +868,16 @@ static ssize_t authorized_default_store(struct device *dev,
unsigned val; unsigned val;
struct usb_device *rh_usb_dev = to_usb_device(dev); struct usb_device *rh_usb_dev = to_usb_device(dev);
struct usb_bus *usb_bus = rh_usb_dev->bus; struct usb_bus *usb_bus = rh_usb_dev->bus;
struct usb_hcd *usb_hcd; struct usb_hcd *hcd;
usb_hcd = bus_to_hcd(usb_bus); hcd = bus_to_hcd(usb_bus);
result = sscanf(buf, "%u\n", &val); result = sscanf(buf, "%u\n", &val);
if (result == 1) { if (result == 1) {
usb_hcd->authorized_default = val ? 1 : 0; if (val)
set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
else
clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
result = size; result = size;
} else { } else {
result = -EINVAL; result = -EINVAL;
...@@ -2720,10 +2724,17 @@ int usb_add_hcd(struct usb_hcd *hcd, ...@@ -2720,10 +2724,17 @@ int usb_add_hcd(struct usb_hcd *hcd,
dev_info(hcd->self.controller, "%s\n", hcd->product_desc); dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
/* Keep old behaviour if authorized_default is not in [0, 1]. */ /* Keep old behaviour if authorized_default is not in [0, 1]. */
if (authorized_default < 0 || authorized_default > 1) if (authorized_default < 0 || authorized_default > 1) {
hcd->authorized_default = hcd->wireless ? 0 : 1; if (hcd->wireless)
else clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
hcd->authorized_default = authorized_default; else
set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
} else {
if (authorized_default)
set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
else
clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
}
set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
/* per default all interfaces are authorized */ /* per default all interfaces are authorized */
......
...@@ -510,7 +510,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, ...@@ -510,7 +510,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
if (root_hub) /* Root hub always ok [and always wired] */ if (root_hub) /* Root hub always ok [and always wired] */
dev->authorized = 1; dev->authorized = 1;
else { else {
dev->authorized = usb_hcd->authorized_default; dev->authorized = !!HCD_DEV_AUTHORIZED(usb_hcd);
dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0;
} }
return dev; return dev;
......
...@@ -58,12 +58,6 @@ ...@@ -58,12 +58,6 @@
* *
* Since "struct usb_bus" is so thin, you can't share much code in it. * Since "struct usb_bus" is so thin, you can't share much code in it.
* This framework is a layer over that, and should be more sharable. * This framework is a layer over that, and should be more sharable.
*
* @authorized_default: Specifies if new devices are authorized to
* connect by default or they require explicit
* user space authorization; this bit is settable
* through /sys/class/usb_host/X/authorized_default.
* For the rest is RO, so we don't lock to r/w it.
*/ */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -121,6 +115,7 @@ struct usb_hcd { ...@@ -121,6 +115,7 @@ struct usb_hcd {
#define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */
#define HCD_FLAG_DEAD 6 /* controller has died? */ #define HCD_FLAG_DEAD 6 /* controller has died? */
#define HCD_FLAG_INTF_AUTHORIZED 7 /* authorize interfaces? */ #define HCD_FLAG_INTF_AUTHORIZED 7 /* authorize interfaces? */
#define HCD_FLAG_DEV_AUTHORIZED 8 /* authorize devices? */
/* The flags can be tested using these macros; they are likely to /* The flags can be tested using these macros; they are likely to
* be slightly faster than test_bit(). * be slightly faster than test_bit().
...@@ -140,6 +135,14 @@ struct usb_hcd { ...@@ -140,6 +135,14 @@ struct usb_hcd {
#define HCD_INTF_AUTHORIZED(hcd) \ #define HCD_INTF_AUTHORIZED(hcd) \
((hcd)->flags & (1U << HCD_FLAG_INTF_AUTHORIZED)) ((hcd)->flags & (1U << HCD_FLAG_INTF_AUTHORIZED))
/*
* Specifies if devices are authorized by default
* or they require explicit user space authorization; this bit is
* settable through /sys/class/usb_host/X/authorized_default
*/
#define HCD_DEV_AUTHORIZED(hcd) \
((hcd)->flags & (1U << HCD_FLAG_DEV_AUTHORIZED))
/* Flags that get set only during HCD registration or removal. */ /* Flags that get set only during HCD registration or removal. */
unsigned rh_registered:1;/* is root hub registered? */ unsigned rh_registered:1;/* is root hub registered? */
unsigned rh_pollable:1; /* may we poll the root hub? */ unsigned rh_pollable:1; /* may we poll the root hub? */
...@@ -150,7 +153,6 @@ struct usb_hcd { ...@@ -150,7 +153,6 @@ struct usb_hcd {
* support the new root-hub polling mechanism. */ * support the new root-hub polling mechanism. */
unsigned uses_new_polling:1; unsigned uses_new_polling:1;
unsigned wireless:1; /* Wireless USB HCD */ unsigned wireless:1; /* Wireless USB HCD */
unsigned authorized_default:1;
unsigned has_tt:1; /* Integrated TT in root hub */ unsigned has_tt:1; /* Integrated TT in root hub */
unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */ unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */
unsigned can_do_streams:1; /* HC supports streams */ unsigned can_do_streams:1; /* HC supports streams */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment