mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Fabian van der Werf <fvanderwerf@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] usb: fix unaligned access
Date: Sun, 23 Oct 2011 11:29:58 +0200	[thread overview]
Message-ID: <CAJeSw6Be=2jNOw1SSz1xB-7bXL9RyrUuLz+yWcZvxfNap6RkwQ@mail.gmail.com> (raw)
In-Reply-To: <20111022202035.GK23421@pengutronix.de>

>
> Looks like a valid patch, I wonder that this never was a problem before.
> ARM should break here aswell I think. What architecture are you using?
>

I am working with a pandaboard (arm cortex a9). The pandaboard has a
usb ethernet controller, so I need usb to boot over tftp. I guess that
most arm configurations don't need usb for booting, and in that case
you won't run into this problem.

Regards,
Fabian

> Sascha
>
>>
>> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
>> index 7039a2c..369a393 100644
>> --- a/drivers/usb/core/usb.c
>> +++ b/drivers/usb/core/usb.c
>> @@ -50,6 +50,7 @@
>>  #include <driver.h>
>>  #include <linux/ctype.h>
>>  #include <asm/byteorder.h>
>> +#include <asm/unaligned.h>
>>  #include <xfuncs.h>
>>  #include <init.h>
>>
>> @@ -1071,6 +1072,7 @@ static int usb_hub_configure(struct usb_device *dev)
>>       struct usb_hub_status *hubsts;
>>       int i;
>>       struct usb_hub_device *hub;
>> +     unsigned short hub_chars;
>>
>>       hub = xzalloc(sizeof (*hub));
>>       dev->hub = hub;
>> @@ -1100,8 +1102,8 @@ static int usb_hub_configure(struct usb_device *dev)
>>       }
>>       memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
>>       /* adjust 16bit values */
>> -     hub->desc.wHubCharacteristics =
>> -                             le16_to_cpu(descriptor->wHubCharacteristics);
>> +     hub_chars = le16_to_cpu(get_unaligned(&descriptor->wHubCharacteristics));
>> +     put_unaligned(hub_chars, &hub->desc.wHubCharacteristics);
>>       /* set the bitmap */
>>       bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
>>       /* devices not removable by default */
>> @@ -1118,7 +1120,7 @@ static int usb_hub_configure(struct usb_device *dev)
>>       dev->maxchild = descriptor->bNbrPorts;
>>       USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
>>
>> -     switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) {
>> +     switch (hub_chars & HUB_CHAR_LPSM) {
>>       case 0x00:
>>               USB_HUB_PRINTF("ganged power switching\n");
>>               break;
>> @@ -1131,12 +1133,12 @@ static int usb_hub_configure(struct usb_device *dev)
>>               break;
>>       }
>>
>> -     if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
>> +     if (hub_chars & HUB_CHAR_COMPOUND)
>>               USB_HUB_PRINTF("part of a compound device\n");
>>       else
>>               USB_HUB_PRINTF("standalone hub\n");
>>
>> -     switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) {
>> +     switch (hub_chars & HUB_CHAR_OCPM) {
>>       case 0x00:
>>               USB_HUB_PRINTF("global over-current protection\n");
>>               break;
>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>> index 72f1c14..20c518a 100644
>> --- a/drivers/usb/host/ehci-hcd.c
>> +++ b/drivers/usb/host/ehci-hcd.c
>> @@ -33,6 +33,7 @@
>>  #include <errno.h>
>>  #include <usb/ehci.h>
>>  #include <asm/mmu.h>
>> +#include <asm/unaligned.h>
>>
>>  #include "ehci.h"
>>
>> @@ -795,6 +796,7 @@ static int ehci_init(struct usb_host *host)
>>       struct ehci_priv *ehci = to_ehci(host);
>>       uint32_t reg;
>>       uint32_t cmd;
>> +     unsigned short hub_chars;
>>
>>       ehci_halt(ehci);
>>
>> @@ -819,12 +821,15 @@ static int ehci_init(struct usb_host *host)
>>       reg = ehci_readl(&ehci->hccr->cr_hcsparams);
>>       descriptor.hub.bNbrPorts = HCS_N_PORTS(reg);
>>
>> +     hub_chars = get_unaligned(&descriptor.hub.wHubCharacteristics);
>>       /* Port Indicators */
>>       if (HCS_INDICATOR(reg))
>> -             descriptor.hub.wHubCharacteristics |= 0x80;
>> +             hub_chars |= 0x80;
>>       /* Port Power Control */
>>       if (HCS_PPC(reg))
>> -             descriptor.hub.wHubCharacteristics |= 0x01;
>> +             hub_chars |= 0x01;
>> +
>> +     put_unaligned(hub_chars, &descriptor.hub.wHubCharacteristics);
>>
>>       /* Start the host controller. */
>>       cmd = ehci_readl(&ehci->hcor->or_usbcmd);
>> --
>> 1.7.0.4
>>
>>
>> _______________________________________________
>> barebox mailing list
>> barebox@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
>>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2011-10-23  9:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-22 13:19 Fabian van der Werf
2011-10-22 20:20 ` Sascha Hauer
2011-10-23  9:29   ` Fabian van der Werf [this message]
2011-10-24 15:14     ` Antony Pavlov
2011-10-24 17:07       ` Sascha Hauer
2011-10-24 18:37         ` Fabian van der Werf
2011-10-24 19:02           ` Eric Bénard
2011-10-24 19:30             ` Sascha Hauer
2011-10-24 19:42               ` Eric Bénard
2011-10-25 18:36                 ` Fabian van der Werf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJeSw6Be=2jNOw1SSz1xB-7bXL9RyrUuLz+yWcZvxfNap6RkwQ@mail.gmail.com' \
    --to=fvanderwerf@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox