Commit 93ad908c43ed5d8e3e546dd22fa08b668c5090d9
Committed by
Marek Vasut
1 parent
81c1d7b605
Exists in
master
and in
57 other branches
usb: do explicit unaligned accesses
usb_hub_descriptor has to be packed as it's used for communication with the device. Member wHubCharacteristics violates the natural alignment rules. Use explicit unaligned access functions for this member. Fixes ARMv7 traping while using USB. v2: fix typo found by Thomas Langer v3: rebased on top of u-boot-usb/master Signed-off-by: Lucas Stach <dev@lynxeye.de>
Showing 2 changed files with 14 additions and 7 deletions Side-by-side Diff
common/usb_hub.c
| ... | ... | @@ -43,6 +43,7 @@ |
| 43 | 43 | #include <common.h> |
| 44 | 44 | #include <command.h> |
| 45 | 45 | #include <asm/processor.h> |
| 46 | +#include <asm/unaligned.h> | |
| 46 | 47 | #include <linux/ctype.h> |
| 47 | 48 | #include <asm/byteorder.h> |
| 48 | 49 | #include <asm/unaligned.h> |
| ... | ... | @@ -269,6 +270,7 @@ |
| 269 | 270 | int i; |
| 270 | 271 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ); |
| 271 | 272 | unsigned char *bitmap; |
| 273 | + short hubCharacteristics; | |
| 272 | 274 | struct usb_hub_descriptor *descriptor; |
| 273 | 275 | struct usb_hub_device *hub; |
| 274 | 276 | #ifdef USB_HUB_DEBUG |
| ... | ... | @@ -304,8 +306,9 @@ |
| 304 | 306 | } |
| 305 | 307 | memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength); |
| 306 | 308 | /* adjust 16bit values */ |
| 307 | - hub->desc.wHubCharacteristics = | |
| 308 | - le16_to_cpu(descriptor->wHubCharacteristics); | |
| 309 | + put_unaligned(le16_to_cpu(get_unaligned( | |
| 310 | + &descriptor->wHubCharacteristics)), | |
| 311 | + &hub->desc.wHubCharacteristics); | |
| 309 | 312 | /* set the bitmap */ |
| 310 | 313 | bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0]; |
| 311 | 314 | /* devices not removable by default */ |
| ... | ... | @@ -322,7 +325,8 @@ |
| 322 | 325 | dev->maxchild = descriptor->bNbrPorts; |
| 323 | 326 | USB_HUB_PRINTF("%d ports detected\n", dev->maxchild); |
| 324 | 327 | |
| 325 | - switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) { | |
| 328 | + hubCharacteristics = get_unaligned(&hub->desc.wHubCharacteristics); | |
| 329 | + switch (hubCharacteristics & HUB_CHAR_LPSM) { | |
| 326 | 330 | case 0x00: |
| 327 | 331 | USB_HUB_PRINTF("ganged power switching\n"); |
| 328 | 332 | break; |
| 329 | 333 | |
| ... | ... | @@ -335,12 +339,12 @@ |
| 335 | 339 | break; |
| 336 | 340 | } |
| 337 | 341 | |
| 338 | - if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND) | |
| 342 | + if (hubCharacteristics & HUB_CHAR_COMPOUND) | |
| 339 | 343 | USB_HUB_PRINTF("part of a compound device\n"); |
| 340 | 344 | else |
| 341 | 345 | USB_HUB_PRINTF("standalone hub\n"); |
| 342 | 346 | |
| 343 | - switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) { | |
| 347 | + switch (hubCharacteristics & HUB_CHAR_OCPM) { | |
| 344 | 348 | case 0x00: |
| 345 | 349 | USB_HUB_PRINTF("global over-current protection\n"); |
| 346 | 350 | break; |
drivers/usb/host/ehci-hcd.c
| ... | ... | @@ -22,6 +22,7 @@ |
| 22 | 22 | */ |
| 23 | 23 | #include <common.h> |
| 24 | 24 | #include <asm/byteorder.h> |
| 25 | +#include <asm/unaligned.h> | |
| 25 | 26 | #include <usb.h> |
| 26 | 27 | #include <asm/io.h> |
| 27 | 28 | #include <malloc.h> |
| 28 | 29 | |
| ... | ... | @@ -866,10 +867,12 @@ |
| 866 | 867 | printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts); |
| 867 | 868 | /* Port Indicators */ |
| 868 | 869 | if (HCS_INDICATOR(reg)) |
| 869 | - descriptor.hub.wHubCharacteristics |= 0x80; | |
| 870 | + put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics) | |
| 871 | + | 0x80, &descriptor.hub.wHubCharacteristics); | |
| 870 | 872 | /* Port Power Control */ |
| 871 | 873 | if (HCS_PPC(reg)) |
| 872 | - descriptor.hub.wHubCharacteristics |= 0x01; | |
| 874 | + put_unaligned(get_unaligned(&descriptor.hub.wHubCharacteristics) | |
| 875 | + | 0x01, &descriptor.hub.wHubCharacteristics); | |
| 873 | 876 | |
| 874 | 877 | /* Start the host controller. */ |
| 875 | 878 | cmd = ehci_readl(&hcor->or_usbcmd); |