Re: PATCH: usb: descriptor structures have to be packed

Sergei Organov <[email protected]>
Newsgroups gmane.linux.usb.devel
Message-ID <[email protected]>
Oliver Neukum <[email protected]> writes:
> Am Mittwoch, 7. Februar 2007 14:31 schrieb Sergei Organov:
>
>>   struct some_descriptor descr;
>>   ...
>>   read_from_wire(&descr, sizeof(descr));
>>   do_something_with_values(usb_get_uint16(descr->foo), bar);
>>   ...
>>   usb_set_uint16(descr->foo, 2385);
>>   
>> where:
>>   
>>   static inline unsigned usb_get_uint16(__u8 const *p)
>>   {
>>     return p[0] | (p[1] << 8);
>>   }
>
> It makes little sense to reinvent le16_to_cpu()

Unfortunately le16_to_cpu() is not exactly what's needed here, and if
I re-implement the above in terms of it:

static inline unsigned usb_get_uint16(__u8 const *p)
{
  typedef __u16 __u16_alias __attribute__((__may_alias__));
  __u16 v = *(__u16_alias*)p;
  return le16_to_cpu(v);
}

it will bring back alignment issues (the 'p' could be mis-aligned for
__u16 type access).

-- Sergei.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.