Commit f6664ba4bcc484a2b924ecfa1052bb729def6685

Authored by Vivek Gautam
Committed by Marek Vasut
1 parent f903a20d1f

usb: gadget: Use unaligned access for wMaxPacketSize

Use get_unaligned() while fetching wMaxPacketSize to avoid
voilating any alignment rules.

Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Piotr Wilczek <p.wilczek@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Lukasz Dalek <luk0104@gmail.com>
Cc: Marek Vasut <marex@denx.de>

Showing 2 changed files with 9 additions and 7 deletions Side-by-side Diff

drivers/usb/gadget/f_mass_storage.c
... ... @@ -2261,7 +2261,8 @@
2261 2261 if (rc)
2262 2262 goto reset;
2263 2263 fsg->bulk_out_enabled = 1;
2264   - common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
  2264 + common->bulk_out_maxpacket =
  2265 + le16_to_cpu(get_unaligned(&d->wMaxPacketSize));
2265 2266 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2266 2267  
2267 2268 /* Allocate the requests */
drivers/usb/gadget/pxa25x_udc.c
... ... @@ -314,7 +314,8 @@
314 314 if (!_ep || !desc || ep->desc || _ep->name == ep0name
315 315 || desc->bDescriptorType != USB_DT_ENDPOINT
316 316 || ep->bEndpointAddress != desc->bEndpointAddress
317   - || ep->fifo_size < le16_to_cpu(desc->wMaxPacketSize)) {
  317 + || ep->fifo_size <
  318 + le16_to_cpu(get_unaligned(&desc->wMaxPacketSize))) {
318 319 printf("%s, bad ep or descriptor\n", __func__);
319 320 return -EINVAL;
320 321 }
321 322  
... ... @@ -329,9 +330,9 @@
329 330  
330 331 /* hardware _could_ do smaller, but driver doesn't */
331 332 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
332   - && le16_to_cpu(desc->wMaxPacketSize)
  333 + && le16_to_cpu(get_unaligned(&desc->wMaxPacketSize))
333 334 != BULK_FIFO_SIZE)
334   - || !desc->wMaxPacketSize) {
  335 + || !get_unaligned(&desc->wMaxPacketSize)) {
335 336 printf("%s, bad %s maxpacket\n", __func__, _ep->name);
336 337 return -ERANGE;
337 338 }
... ... @@ -345,7 +346,7 @@
345 346 ep->desc = desc;
346 347 ep->stopped = 0;
347 348 ep->pio_irqs = 0;
348   - ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
  349 + ep->ep.maxpacket = le16_to_cpu(get_unaligned(&desc->wMaxPacketSize));
349 350  
350 351 /* flush fifo (mostly for OUT buffers) */
351 352 pxa25x_ep_fifo_flush(_ep);
... ... @@ -485,7 +486,7 @@
485 486 {
486 487 unsigned max;
487 488  
488   - max = le16_to_cpu(ep->desc->wMaxPacketSize);
  489 + max = le16_to_cpu(get_unaligned(&ep->desc->wMaxPacketSize));
489 490 do {
490 491 unsigned count;
491 492 int is_last, is_short;
... ... @@ -766,7 +767,7 @@
766 767 */
767 768 if (unlikely(ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
768 769 && req->req.length >
769   - le16_to_cpu(ep->desc->wMaxPacketSize)))
  770 + le16_to_cpu(get_unaligned(&ep->desc->wMaxPacketSize))))
770 771 return -EMSGSIZE;
771 772  
772 773 debug_cond(NOISY, "%s queue req %p, len %d buf %p\n",