aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/config.c66
-rw-r--r--drivers/usb/core/devio.c7
-rw-r--r--drivers/usb/core/hub.c23
3 files changed, 77 insertions, 19 deletions
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 31ccdccd7a04..051163189810 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -171,6 +171,31 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
171 ep, buffer, size); 171 ep, buffer, size);
172} 172}
173 173
174static const unsigned short low_speed_maxpacket_maxes[4] = {
175 [USB_ENDPOINT_XFER_CONTROL] = 8,
176 [USB_ENDPOINT_XFER_ISOC] = 0,
177 [USB_ENDPOINT_XFER_BULK] = 0,
178 [USB_ENDPOINT_XFER_INT] = 8,
179};
180static const unsigned short full_speed_maxpacket_maxes[4] = {
181 [USB_ENDPOINT_XFER_CONTROL] = 64,
182 [USB_ENDPOINT_XFER_ISOC] = 1023,
183 [USB_ENDPOINT_XFER_BULK] = 64,
184 [USB_ENDPOINT_XFER_INT] = 64,
185};
186static const unsigned short high_speed_maxpacket_maxes[4] = {
187 [USB_ENDPOINT_XFER_CONTROL] = 64,
188 [USB_ENDPOINT_XFER_ISOC] = 1024,
189 [USB_ENDPOINT_XFER_BULK] = 512,
190 [USB_ENDPOINT_XFER_INT] = 1023,
191};
192static const unsigned short super_speed_maxpacket_maxes[4] = {
193 [USB_ENDPOINT_XFER_CONTROL] = 512,
194 [USB_ENDPOINT_XFER_ISOC] = 1024,
195 [USB_ENDPOINT_XFER_BULK] = 1024,
196 [USB_ENDPOINT_XFER_INT] = 1024,
197};
198
174static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, 199static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
175 int asnum, struct usb_host_interface *ifp, int num_ep, 200 int asnum, struct usb_host_interface *ifp, int num_ep,
176 unsigned char *buffer, int size) 201 unsigned char *buffer, int size)
@@ -179,6 +204,8 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
179 struct usb_endpoint_descriptor *d; 204 struct usb_endpoint_descriptor *d;
180 struct usb_host_endpoint *endpoint; 205 struct usb_host_endpoint *endpoint;
181 int n, i, j, retval; 206 int n, i, j, retval;
207 unsigned int maxp;
208 const unsigned short *maxpacket_maxes;
182 209
183 d = (struct usb_endpoint_descriptor *) buffer; 210 d = (struct usb_endpoint_descriptor *) buffer;
184 buffer += d->bLength; 211 buffer += d->bLength;
@@ -286,6 +313,42 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
286 endpoint->desc.wMaxPacketSize = cpu_to_le16(8); 313 endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
287 } 314 }
288 315
316 /* Validate the wMaxPacketSize field */
317 maxp = usb_endpoint_maxp(&endpoint->desc);
318
319 /* Find the highest legal maxpacket size for this endpoint */
320 i = 0; /* additional transactions per microframe */
321 switch (to_usb_device(ddev)->speed) {
322 case USB_SPEED_LOW:
323 maxpacket_maxes = low_speed_maxpacket_maxes;
324 break;
325 case USB_SPEED_FULL:
326 maxpacket_maxes = full_speed_maxpacket_maxes;
327 break;
328 case USB_SPEED_HIGH:
329 /* Bits 12..11 are allowed only for HS periodic endpoints */
330 if (usb_endpoint_xfer_int(d) || usb_endpoint_xfer_isoc(d)) {
331 i = maxp & (BIT(12) | BIT(11));
332 maxp &= ~i;
333 }
334 /* fallthrough */
335 default:
336 maxpacket_maxes = high_speed_maxpacket_maxes;
337 break;
338 case USB_SPEED_SUPER:
339 case USB_SPEED_SUPER_PLUS:
340 maxpacket_maxes = super_speed_maxpacket_maxes;
341 break;
342 }
343 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)];
344
345 if (maxp > j) {
346 dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, setting to %d\n",
347 cfgno, inum, asnum, d->bEndpointAddress, maxp, j);
348 maxp = j;
349 endpoint->desc.wMaxPacketSize = cpu_to_le16(i | maxp);
350 }
351
289 /* 352 /*
290 * Some buggy high speed devices have bulk endpoints using 353 * Some buggy high speed devices have bulk endpoints using
291 * maxpacket sizes other than 512. High speed HCDs may not 354 * maxpacket sizes other than 512. High speed HCDs may not
@@ -293,9 +356,6 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
293 */ 356 */
294 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH 357 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
295 && usb_endpoint_xfer_bulk(d)) { 358 && usb_endpoint_xfer_bulk(d)) {
296 unsigned maxp;
297
298 maxp = usb_endpoint_maxp(&endpoint->desc) & 0x07ff;
299 if (maxp != 512) 359 if (maxp != 512)
300 dev_warn(ddev, "config %d interface %d altsetting %d " 360 dev_warn(ddev, "config %d interface %d altsetting %d "
301 "bulk endpoint 0x%X has invalid maxpacket %d\n", 361 "bulk endpoint 0x%X has invalid maxpacket %d\n",
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index e9f5043a2167..e6a6d67c8705 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -241,7 +241,8 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
241 goto error_decrease_mem; 241 goto error_decrease_mem;
242 } 242 }
243 243
244 mem = usb_alloc_coherent(ps->dev, size, GFP_USER, &dma_handle); 244 mem = usb_alloc_coherent(ps->dev, size, GFP_USER | __GFP_NOWARN,
245 &dma_handle);
245 if (!mem) { 246 if (!mem) {
246 ret = -ENOMEM; 247 ret = -ENOMEM;
247 goto error_free_usbm; 248 goto error_free_usbm;
@@ -2582,7 +2583,9 @@ static unsigned int usbdev_poll(struct file *file,
2582 if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed)) 2583 if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed))
2583 mask |= POLLOUT | POLLWRNORM; 2584 mask |= POLLOUT | POLLWRNORM;
2584 if (!connected(ps)) 2585 if (!connected(ps))
2585 mask |= POLLERR | POLLHUP; 2586 mask |= POLLHUP;
2587 if (list_empty(&ps->list))
2588 mask |= POLLERR;
2586 return mask; 2589 return mask;
2587} 2590}
2588 2591
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index bee13517676f..1d5fc32d06d0 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1052,14 +1052,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1052 1052
1053 /* Continue a partial initialization */ 1053 /* Continue a partial initialization */
1054 if (type == HUB_INIT2 || type == HUB_INIT3) { 1054 if (type == HUB_INIT2 || type == HUB_INIT3) {
1055 device_lock(hub->intfdev); 1055 device_lock(&hdev->dev);
1056 1056
1057 /* Was the hub disconnected while we were waiting? */ 1057 /* Was the hub disconnected while we were waiting? */
1058 if (hub->disconnected) { 1058 if (hub->disconnected)
1059 device_unlock(hub->intfdev); 1059 goto disconnected;
1060 kref_put(&hub->kref, hub_release);
1061 return;
1062 }
1063 if (type == HUB_INIT2) 1060 if (type == HUB_INIT2)
1064 goto init2; 1061 goto init2;
1065 goto init3; 1062 goto init3;
@@ -1262,7 +1259,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1262 queue_delayed_work(system_power_efficient_wq, 1259 queue_delayed_work(system_power_efficient_wq,
1263 &hub->init_work, 1260 &hub->init_work,
1264 msecs_to_jiffies(delay)); 1261 msecs_to_jiffies(delay));
1265 device_unlock(hub->intfdev); 1262 device_unlock(&hdev->dev);
1266 return; /* Continues at init3: below */ 1263 return; /* Continues at init3: below */
1267 } else { 1264 } else {
1268 msleep(delay); 1265 msleep(delay);
@@ -1281,12 +1278,12 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1281 /* Scan all ports that need attention */ 1278 /* Scan all ports that need attention */
1282 kick_hub_wq(hub); 1279 kick_hub_wq(hub);
1283 1280
1284 /* Allow autosuspend if it was suppressed */ 1281 if (type == HUB_INIT2 || type == HUB_INIT3) {
1285 if (type <= HUB_INIT3) 1282 /* Allow autosuspend if it was suppressed */
1283 disconnected:
1286 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); 1284 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1287 1285 device_unlock(&hdev->dev);
1288 if (type == HUB_INIT2 || type == HUB_INIT3) 1286 }
1289 device_unlock(hub->intfdev);
1290 1287
1291 kref_put(&hub->kref, hub_release); 1288 kref_put(&hub->kref, hub_release);
1292} 1289}
@@ -1315,8 +1312,6 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
1315 struct usb_device *hdev = hub->hdev; 1312 struct usb_device *hdev = hub->hdev;
1316 int i; 1313 int i;
1317 1314
1318 cancel_delayed_work_sync(&hub->init_work);
1319
1320 /* hub_wq and related activity won't re-trigger */ 1315 /* hub_wq and related activity won't re-trigger */
1321 hub->quiescing = 1; 1316 hub->quiescing = 1;
1322 1317