Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-13 Thread Sergei Organov
Alan Stern <[EMAIL PROTECTED]> writes: > On Mon, 12 Feb 2007, Sergei Organov wrote: > >> The fact remains that even GCC extensions to C can't deal with >> endianness. I'd like to have such an extension though. > > It would be nice. And useful. It would also be nice if the compiler > could deal w

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-12 Thread Alan Stern
On Mon, 12 Feb 2007, Sergei Organov wrote: > The fact remains that even GCC extensions to C can't deal with > endianness. I'd like to have such an extension though. It would be nice. And useful. It would also be nice if the compiler could deal with unaligned data automatically. Bear in mind t

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-12 Thread Sergei Organov
Alan Stern <[EMAIL PROTECTED]> writes: > On Fri, 9 Feb 2007, Sergei Organov wrote: > >> Alan Stern <[EMAIL PROTECTED]> writes: >> >> > On Thu, 8 Feb 2007, Sergei Organov wrote: >> > >> >> IMHO aligned(N) should be used in portable code only to *increase* >> >> alignment (this effectively excludes

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-09 Thread Alan Stern
On Fri, 9 Feb 2007, Sergei Organov wrote: > Alan Stern <[EMAIL PROTECTED]> writes: > > > On Thu, 8 Feb 2007, Sergei Organov wrote: > > > >> IMHO aligned(N) should be used in portable code only to *increase* > >> alignment (this effectively excludes usage of 'packed'), and then the > >> alignment

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-09 Thread Sergei Organov
Alan Stern <[EMAIL PROTECTED]> writes: > On Thu, 8 Feb 2007, Sergei Organov wrote: > >> IMHO aligned(N) should be used in portable code only to *increase* >> alignment (this effectively excludes usage of 'packed'), and then the >> alignment won't affect the low-level operations, that automatically

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-09 Thread Sergei Organov
Alan Stern <[EMAIL PROTECTED]> writes: > On Thu, 8 Feb 2007, Sergei Organov wrote: > >> IMHO aligned(N) should be used in portable code only to *increase* >> alignment (this effectively excludes usage of 'packed'), and then the >> alignment won't affect the low-level operations, that automatically

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Alan Stern
On Thu, 8 Feb 2007, Sergei Organov wrote: > IMHO aligned(N) should be used in portable code only to *increase* > alignment (this effectively excludes usage of 'packed'), and then the > alignment won't affect the low-level operations, that automatically > answers your question. Simple? If you don'

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Sergei Organov
Alan Stern <[EMAIL PROTECTED]> writes: > On Thu, 8 Feb 2007, Sergei Organov wrote: > >> Unfortunately I can't have the correct type for this field in C (it >> should be "2-bytes-little-endian-unsigned-integer-unaligned"), so I >> can't get type-safety here anyway. Declaring this field __le16 is IMH

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Sergei Organov
Oliver Neukum <[EMAIL PROTECTED]> writes: > Am Donnerstag, 8. Februar 2007 16:41 schrieb Sergei Organov: >> > If you do that, le16 is just as valid, especially if declared >> > unaligned. >> >> I don't think so: >> >> 1. 'unsigned char', be it used in the form of 'u8' or not, has neither >>    al

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Alan Stern
On Thu, 8 Feb 2007, Sergei Organov wrote: > Unfortunately I can't have the correct type for this field in C (it > should be "2-bytes-little-endian-unsigned-integer-unaligned"), so I > can't get type-safety here anyway. Declaring this field __le16 is IMHO a > poor attempt as it creates an illusion

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Oliver Neukum
Am Donnerstag, 8. Februar 2007 16:41 schrieb Sergei Organov: > > If you do that, le16 is just as valid, especially if declared > > unaligned. > > I don't think so: > > 1. 'unsigned char', be it used in the form of 'u8' or not, has neither >    alignment nor endianness problems, while le16 has bot

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Sergei Organov
Oliver Neukum <[EMAIL PROTECTED]> writes: >> Unfortunately I can't have the correct type for this field in C (it >> should be "2-bytes-little-endian-unsigned-integer-unaligned"), so I >> can't get type-safety here anyway. Declaring this field __le16 is IMHO a >> poor attempt as it creates an illusi

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Oliver Neukum
> Unfortunately I can't have the correct type for this field in C (it > should be "2-bytes-little-endian-unsigned-integer-unaligned"), so I > can't get type-safety here anyway. Declaring this field __le16 is IMHO a > poor attempt as it creates an illusion of type safety when in fact there > is no

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-08 Thread Sergei Organov
Oliver Neukum <[EMAIL PROTECTED]> writes: > Am Mittwoch, 7. Februar 2007 18:31 schrieb Pete Zaitcev: >> On Wed, 7 Feb 2007 14:39:28 +0100, Oliver Neukum <[EMAIL PROTECTED]> wrote: >> > Am Mittwoch, 7. Februar 2007 14:31 schrieb Sergei Organov: >> >> > > static inline unsigned usb_get_uint16(__u

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Mittwoch, 7. Februar 2007 23:45 schrieb Pete Zaitcev: > On Wed, 7 Feb 2007 21:26:36 +0100, Oliver Neukum <[EMAIL PROTECTED]> wrote: > > > > It would not, if le16_to_cpu took a pointer to u8. But as it is, > > > functions are quite different. > > > > That's what casts are for. However, why do y

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Pete Zaitcev
On Wed, 7 Feb 2007 21:26:36 +0100, Oliver Neukum <[EMAIL PROTECTED]> wrote: > > It would not, if le16_to_cpu took a pointer to u8. But as it is, > > functions are quite different. > > That's what casts are for. However, why do you have no type information > in the first place? Untyped data is ris

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Alan Stern
On Wed, 7 Feb 2007, Oliver Neukum wrote: > > I have often thought exactly the same thing. It seems so natural to > > combine unaligned reads and writes with byte-reordering. I even brought > > up the issue on LKML: Why shouldn't there be architecture-dependent > > versions of > > > > get

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Mittwoch, 7. Februar 2007 18:31 schrieb Pete Zaitcev: > On Wed, 7 Feb 2007 14:39:28 +0100, Oliver Neukum <[EMAIL PROTECTED]> wrote: > > Am Mittwoch, 7. Februar 2007 14:31 schrieb Sergei Organov: > > > > static inline unsigned usb_get_uint16(__u8 const *p) > > > { > > > return p[0] | (p[

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Mittwoch, 7. Februar 2007 19:47 schrieb Alan Stern: > On Wed, 7 Feb 2007, Sergei Organov wrote: > > > In fact if there were macro/function similar to get_unaligned(), but > > converting from little-/big-endian to native, say, get_unaligned_le(), > > I'd use it: > > ... > > > Unfortunately th

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Mittwoch, 7. Februar 2007 19:23 schrieb David Brownell: > On Wednesday 07 February 2007 4:25 am, Oliver Neukum wrote: > > > 1. Disallow any padding > > 2. Assume the structure may be in unaligned memory > > > > Issue number #1 is usually handled by the USB specification. > > Key word "usually

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Sergei Organov
David Brownell <[EMAIL PROTECTED]> writes: > On Tuesday 06 February 2007 2:48 pm, Pete Zaitcev wrote: >> On Tue, 6 Feb 2007 13:08:19 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> >> wrote: >> >> > [btw, I truly have little idea about which are those specific costs, >> > out of professional cur

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Alan Stern
On Wed, 7 Feb 2007, Sergei Organov wrote: > In fact if there were macro/function similar to get_unaligned(), but > converting from little-/big-endian to native, say, get_unaligned_le(), > I'd use it: ... > Unfortunately there is no such macro, or did I miss it? I have often thought exactly the

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread David Brownell
On Wednesday 07 February 2007 4:25 am, Oliver Neukum wrote: > 1. Disallow any padding > 2. Assume the structure may be in unaligned memory > > Issue number #1 is usually handled by the USB specification. Key word "usually"; they haven't AFAIK promised to do so. > #2 is not. Therefore packed da

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Sergei Organov
Pete Zaitcev <[EMAIL PROTECTED]> writes: > On Wed, 7 Feb 2007 14:39:28 +0100, Oliver Neukum <[EMAIL PROTECTED]> wrote: >> Am Mittwoch, 7. Februar 2007 14:31 schrieb Sergei Organov: > >> >   static inline unsigned usb_get_uint16(__u8 const *p) >> >   { >> >     return p[0] | (p[1] << 8); >> >   } >

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Pete Zaitcev
On Wed, 7 Feb 2007 14:39:28 +0100, Oliver Neukum <[EMAIL PROTECTED]> wrote: > Am Mittwoch, 7. Februar 2007 14:31 schrieb Sergei Organov: > >   static inline unsigned usb_get_uint16(__u8 const *p) > >   { > >     return p[0] | (p[1] << 8); > >   } > > It makes little sense to reinvent le16_to_cpu(

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Sergei Organov
Oliver Neukum <[EMAIL PROTECTED]> writes: > Am Mittwoch, 7. Februar 2007 15:04 schrieb Sergei Organov: >> Unfortunately le16_to_cpu() is not exactly what's needed here, and if >> I re-implement the above in terms of it: > > The issues of endianness and alignment are orthogonal. If you > face both d

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Mittwoch, 7. Februar 2007 15:04 schrieb Sergei Organov: > Unfortunately le16_to_cpu() is not exactly what's needed here, and if > I re-implement the above in terms of it: The issues of endianness and alignment are orthogonal. If you face both do: x = le16_to_cpu(get_unaligned(p)); Don't reinv

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Sergei Organov
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, 2

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
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

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Sergei Organov
Inaky Perez-Gonzalez <[EMAIL PROTECTED]> writes: [...] > Here is my point: it's way easier and more maintenable to do > > struct some_descriptor { > __le16 foo; > __u8 bar; > } __attribute__((packed)); > ... > struct some_descriptor descr; >

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Mittwoch, 7. Februar 2007 08:00 schrieb David Brownell: > > In scope of (1) i can't understand: structs are padded implicitly, > > member access is coded explicitly. > > But the struct declarations in question are not memory layouts. > > They're "on-the-wire" protocol structures, where the com

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-07 Thread Oliver Neukum
Am Dienstag, 6. Februar 2007 23:48 schrieb Pete Zaitcev: > On Tue, 6 Feb 2007 13:08:19 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> > wrote: > > > [btw, I truly have little idea about which are those specific costs, > > out of professional curiosity, got any pointers?] > > http://www.digital

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread David Brownell
On Tuesday 06 February 2007 5:58 pm, Oleg Verych wrote: > > Would you clarify "non aligned access issue" on well known platforms > (*x86-*). I see on gcc's output, that they are not carry much about it: X86 has hardware logic to handle misaligned access directly. Which is why GCC output doesn't p

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread Oleg Verych
> From: David Brownell > Newsgroups: gmane.linux.usb.devel > Subject: Re: PATCH: usb: descriptor structures have to be packed > Date: Tue, 6 Feb 2007 16:02:27 -0800 Hallo. > On Tuesday 06 February 2007 2:48 pm, Pete Zaitcev wrote: >> On Tue, 6 Feb 2007 13:08:19 -0800, Inaky Perez-Gonzalez <[EMAIL

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread David Brownell
On Tuesday 06 February 2007 2:48 pm, Pete Zaitcev wrote: > On Tue, 6 Feb 2007 13:08:19 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> > wrote: > > > [btw, I truly have little idea about which are those specific costs, > > out of professional curiosity, got any pointers?] > > http://www.digital

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread Pete Zaitcev
On Tue, 6 Feb 2007 13:08:19 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> wrote: > [btw, I truly have little idea about which are those specific costs, > out of professional curiosity, got any pointers?] http://www.digitalvampire.org/blog/articles/2006/07/31/why-you-shouldnt-use-__attribute__

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread David Brownell
On Tuesday 06 February 2007 1:08 pm, Inaky Perez-Gonzalez wrote: > On Friday 02 February 2007 19:05, you wrote: > > The code should have used sizes such as > > USB_DT_CONFIG_SIZE instead of sizeof(). > > I have a problem with that, and is maintenance. Is not that I don't like > DT_CONFIG_SIZE

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread David Brownell
On Friday 02 February 2007 7:05 pm, Pete Zaitcev wrote: > On Fri, 2 Feb 2007 17:32:24 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> > wrote: > > > usb: descriptor structures have to be packed > > > Many of the Wireless USB decriptors added to usb_ch9.h don't have the > > __attribute__((packed)

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-06 Thread Inaky Perez-Gonzalez
On Friday 02 February 2007 19:05, you wrote: > On Fri, 2 Feb 2007 17:32:24 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> wrote: > > usb: descriptor structures have to be packed > > > > Many of the Wireless USB decriptors added to usb_ch9.h don't have the > > __attribute__((packed)) tag, and thus

Re: [linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-02 Thread Pete Zaitcev
On Fri, 2 Feb 2007 17:32:24 -0800, Inaky Perez-Gonzalez <[EMAIL PROTECTED]> wrote: > usb: descriptor structures have to be packed > Many of the Wireless USB decriptors added to usb_ch9.h don't have the > __attribute__((packed)) tag, and thus, they don't reflect the wire > size. This patch fixes

[linux-usb-devel] PATCH: usb: descriptor structures have to be packed

2007-02-02 Thread Inaky Perez-Gonzalez
usb: descriptor structures have to be packed Many of the Wireless USB decriptors added to usb_ch9.h don't have the __attribute__((packed)) tag, and thus, they don't reflect the wire size. This patch fixes that. Signed-off-by: Inaky Perez-Gonzalez <[EMAIL PROTECTED]> --- usb_ch9.h | 20