diff options
-rw-r--r-- | drivers/usb/core/hcd.c | 31 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 2 | ||||
-rw-r--r-- | include/linux/usb/hcd.h | 16 |
3 files changed, 31 insertions, 18 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 83df1dde9c08..86b3d1190500 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -854,10 +854,10 @@ static ssize_t authorized_default_show(struct device *dev, | |||
854 | { | 854 | { |
855 | struct usb_device *rh_usb_dev = to_usb_device(dev); | 855 | struct usb_device *rh_usb_dev = to_usb_device(dev); |
856 | struct usb_bus *usb_bus = rh_usb_dev->bus; | 856 | struct usb_bus *usb_bus = rh_usb_dev->bus; |
857 | struct usb_hcd *usb_hcd; | 857 | struct usb_hcd *hcd; |
858 | 858 | ||
859 | usb_hcd = bus_to_hcd(usb_bus); | 859 | hcd = bus_to_hcd(usb_bus); |
860 | return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default); | 860 | return snprintf(buf, PAGE_SIZE, "%u\n", !!HCD_DEV_AUTHORIZED(hcd)); |
861 | } | 861 | } |
862 | 862 | ||
863 | static ssize_t authorized_default_store(struct device *dev, | 863 | static ssize_t authorized_default_store(struct device *dev, |
@@ -868,12 +868,16 @@ static ssize_t authorized_default_store(struct device *dev, | |||
868 | unsigned val; | 868 | unsigned val; |
869 | struct usb_device *rh_usb_dev = to_usb_device(dev); | 869 | struct usb_device *rh_usb_dev = to_usb_device(dev); |
870 | struct usb_bus *usb_bus = rh_usb_dev->bus; | 870 | struct usb_bus *usb_bus = rh_usb_dev->bus; |
871 | struct usb_hcd *usb_hcd; | 871 | struct usb_hcd *hcd; |
872 | 872 | ||
873 | usb_hcd = bus_to_hcd(usb_bus); | 873 | hcd = bus_to_hcd(usb_bus); |
874 | result = sscanf(buf, "%u\n", &val); | 874 | result = sscanf(buf, "%u\n", &val); |
875 | if (result == 1) { | 875 | if (result == 1) { |
876 | usb_hcd->authorized_default = val ? 1 : 0; | 876 | if (val) |
877 | set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags); | ||
878 | else | ||
879 | clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags); | ||
880 | |||
877 | result = size; | 881 | result = size; |
878 | } else { | 882 | } else { |
879 | result = -EINVAL; | 883 | result = -EINVAL; |
@@ -2720,10 +2724,17 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2720 | dev_info(hcd->self.controller, "%s\n", hcd->product_desc); | 2724 | dev_info(hcd->self.controller, "%s\n", hcd->product_desc); |
2721 | 2725 | ||
2722 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ | 2726 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ |
2723 | if (authorized_default < 0 || authorized_default > 1) | 2727 | if (authorized_default < 0 || authorized_default > 1) { |
2724 | hcd->authorized_default = hcd->wireless ? 0 : 1; | 2728 | if (hcd->wireless) |
2725 | else | 2729 | clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags); |
2726 | hcd->authorized_default = authorized_default; | 2730 | else |
2731 | set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags); | ||
2732 | } else { | ||
2733 | if (authorized_default) | ||
2734 | set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags); | ||
2735 | else | ||
2736 | clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags); | ||
2737 | } | ||
2727 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 2738 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
2728 | 2739 | ||
2729 | /* per default all interfaces are authorized */ | 2740 | /* per default all interfaces are authorized */ |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 8d5b2f4113cd..f8bbd0b6d9fe 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -510,7 +510,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
510 | if (root_hub) /* Root hub always ok [and always wired] */ | 510 | if (root_hub) /* Root hub always ok [and always wired] */ |
511 | dev->authorized = 1; | 511 | dev->authorized = 1; |
512 | else { | 512 | else { |
513 | dev->authorized = usb_hcd->authorized_default; | 513 | dev->authorized = !!HCD_DEV_AUTHORIZED(usb_hcd); |
514 | dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; | 514 | dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; |
515 | } | 515 | } |
516 | return dev; | 516 | return dev; |
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 36ce3d215cad..4d147277b30d 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h | |||
@@ -58,12 +58,6 @@ | |||
58 | * | 58 | * |
59 | * Since "struct usb_bus" is so thin, you can't share much code in it. | 59 | * Since "struct usb_bus" is so thin, you can't share much code in it. |
60 | * This framework is a layer over that, and should be more sharable. | 60 | * This framework is a layer over that, and should be more sharable. |
61 | * | ||
62 | * @authorized_default: Specifies if new devices are authorized to | ||
63 | * connect by default or they require explicit | ||
64 | * user space authorization; this bit is settable | ||
65 | * through /sys/class/usb_host/X/authorized_default. | ||
66 | * For the rest is RO, so we don't lock to r/w it. | ||
67 | */ | 61 | */ |
68 | 62 | ||
69 | /*-------------------------------------------------------------------------*/ | 63 | /*-------------------------------------------------------------------------*/ |
@@ -121,6 +115,7 @@ struct usb_hcd { | |||
121 | #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ | 115 | #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ |
122 | #define HCD_FLAG_DEAD 6 /* controller has died? */ | 116 | #define HCD_FLAG_DEAD 6 /* controller has died? */ |
123 | #define HCD_FLAG_INTF_AUTHORIZED 7 /* authorize interfaces? */ | 117 | #define HCD_FLAG_INTF_AUTHORIZED 7 /* authorize interfaces? */ |
118 | #define HCD_FLAG_DEV_AUTHORIZED 8 /* authorize devices? */ | ||
124 | 119 | ||
125 | /* The flags can be tested using these macros; they are likely to | 120 | /* The flags can be tested using these macros; they are likely to |
126 | * be slightly faster than test_bit(). | 121 | * be slightly faster than test_bit(). |
@@ -140,6 +135,14 @@ struct usb_hcd { | |||
140 | #define HCD_INTF_AUTHORIZED(hcd) \ | 135 | #define HCD_INTF_AUTHORIZED(hcd) \ |
141 | ((hcd)->flags & (1U << HCD_FLAG_INTF_AUTHORIZED)) | 136 | ((hcd)->flags & (1U << HCD_FLAG_INTF_AUTHORIZED)) |
142 | 137 | ||
138 | /* | ||
139 | * Specifies if devices are authorized by default | ||
140 | * or they require explicit user space authorization; this bit is | ||
141 | * settable through /sys/class/usb_host/X/authorized_default | ||
142 | */ | ||
143 | #define HCD_DEV_AUTHORIZED(hcd) \ | ||
144 | ((hcd)->flags & (1U << HCD_FLAG_DEV_AUTHORIZED)) | ||
145 | |||
143 | /* Flags that get set only during HCD registration or removal. */ | 146 | /* Flags that get set only during HCD registration or removal. */ |
144 | unsigned rh_registered:1;/* is root hub registered? */ | 147 | unsigned rh_registered:1;/* is root hub registered? */ |
145 | unsigned rh_pollable:1; /* may we poll the root hub? */ | 148 | unsigned rh_pollable:1; /* may we poll the root hub? */ |
@@ -150,7 +153,6 @@ struct usb_hcd { | |||
150 | * support the new root-hub polling mechanism. */ | 153 | * support the new root-hub polling mechanism. */ |
151 | unsigned uses_new_polling:1; | 154 | unsigned uses_new_polling:1; |
152 | unsigned wireless:1; /* Wireless USB HCD */ | 155 | unsigned wireless:1; /* Wireless USB HCD */ |
153 | unsigned authorized_default:1; | ||
154 | unsigned has_tt:1; /* Integrated TT in root hub */ | 156 | unsigned has_tt:1; /* Integrated TT in root hub */ |
155 | unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */ | 157 | unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */ |
156 | unsigned can_do_streams:1; /* HC supports streams */ | 158 | unsigned can_do_streams:1; /* HC supports streams */ |