Hi,
It seems to be the conversion to a pointer and back that makes
le16_to_cpus to loose the __attribute__((packed)). In my opinion
the compiler should warn that it discards the attribute.
I suspect it does something wrong on other architectures too, but most
support non aligned access. I used gcc-3.4.3 for this tests.
The following is what the preprocessor makes from le16_to_cpus.

static __inline__ void __swab16s(__u16 *addr)
{
        do { *( addr ) = ({ __u16 __tmp = ( *( ( addr ) ) ) ;
        ({ __u16 __x = ( __tmp ); ((__u16)( (((__u16)(__x) & (__u16)0x00ffU) << 
8)
    | (((__u16)(__x) & (__u16)0xff00U) >> 8) )); }) ; })  ; } while (0) ;
}

I found no way to convince the compiler to keep the attribute packed when a
pointer is used:

struct TEST {
        char x;
        short y;
} __attribute__((packed));

void testfunc(TEST *test) {
        (test->y) = ___swab16(test->y); // is working correctly
        (*&test->y) == ___swab16(*&test->y); // does discard
__attribute__((packed))
}
So my proposal is to avoid the call of the macro with a pointer. The
following
is tested to work correctly:

hub->descriptor->wHubCharacteristics=le16_to_cpu(hub->descriptor->wHubCharac
teristics);

Jochen


> > Under Big Endian ARM linux-2.6.11.12 the following code from
usb/core/hub.c
> > triggers an alignment exception:
> >
> >  le16_to_cpus(&hub->descriptor->wHubCharacteristics); /* This triggers
two
> > alignment exceptions */

> struct usb_hub_descriptor {
>       __u8  bDescLength;
>       __u8  bDescriptorType;
>       __u8  bNbrPorts;
>       __u16 wHubCharacteristics;
> .....
> } __attribute__ ((packed));
>
> As you can see the structure is declared packed. This should work. Either
> the macro or the compiler are at fault.



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to