[kernel] generic-2.6/2.6.28: refresh a patch
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.28 / 300-fix_byteorder_header.patch
1 glibc headers define both __LITTLE_ENDIAN and __BIG_ENDIAN
2 which was tripping the check in linux/byteorder.h.  Let's
3 just stay out of userspace's way and use __KERN_{endian}
4
5 The old implementation got away with it as it kept the two
6 implementations in different headers and conditionally included
7 the right one.  The combined header does checks within each
8 function body and depends on only one being defined.
9
10 Converted the arches in mainline that have already moved to the
11 new header, as the other arches merge the will need simlar
12 fixups.
13
14 Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
15 ---
16  arch/avr32/include/asm/byteorder.h |    2 +-
17  arch/mips/include/asm/byteorder.h  |    4 +-
18  arch/sh/include/asm/byteorder.h    |    4 +-
19  arch/sparc/include/asm/byteorder.h |    2 +-
20  include/linux/byteorder.h          |   84 ++++++++++++++++++------------------
21  5 files changed, 48 insertions(+), 48 deletions(-)
22
23 --- a/arch/avr32/include/asm/byteorder.h
24 +++ b/arch/avr32/include/asm/byteorder.h
25 @@ -7,7 +7,7 @@
26  #include <asm/types.h>
27  #include <linux/compiler.h>
28  
29 -#define __BIG_ENDIAN
30 +#define __KERN_BIG_ENDIAN
31  #define __SWAB_64_THRU_32__
32  
33  #ifdef __CHECKER__
34 --- a/arch/mips/include/asm/byteorder.h
35 +++ b/arch/mips/include/asm/byteorder.h
36 @@ -12,9 +12,9 @@
37  #include <asm/types.h>
38  
39  #if defined(__MIPSEB__)
40 -# define __BIG_ENDIAN
41 +# define __KERN_BIG_ENDIAN
42  #elif defined(__MIPSEL__)
43 -# define __LITTLE_ENDIAN
44 +# define __KERN_LITTLE_ENDIAN
45  #else
46  # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
47  #endif
48 --- a/arch/sh/include/asm/byteorder.h
49 +++ b/arch/sh/include/asm/byteorder.h
50 @@ -9,9 +9,9 @@
51  #include <linux/types.h>
52  
53  #ifdef __LITTLE_ENDIAN__
54 -# define __LITTLE_ENDIAN
55 +# define __KERN_LITTLE_ENDIAN
56  #else
57 -# define __BIG_ENDIAN
58 +# define __KERN_BIG_ENDIAN
59  #endif
60  
61  #define __SWAB_64_THRU_32__
62 --- a/arch/sparc/include/asm/byteorder.h
63 +++ b/arch/sparc/include/asm/byteorder.h
64 @@ -4,7 +4,7 @@
65  #include <asm/types.h>
66  #include <asm/asi.h>
67  
68 -#define __BIG_ENDIAN
69 +#define __KERN_BIG_ENDIAN
70  
71  #ifdef CONFIG_SPARC32
72  #define __SWAB_64_THRU_32__
73 --- a/include/linux/byteorder.h
74 +++ b/include/linux/byteorder.h
75 @@ -4,33 +4,33 @@
76  #include <linux/types.h>
77  #include <linux/swab.h>
78  
79 -#if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
80 +#if defined(__KERN_LITTLE_ENDIAN) && defined(__KERN_BIG_ENDIAN)
81  # error Fix asm/byteorder.h to define one endianness
82  #endif
83  
84 -#if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
85 +#if !defined(__KERN_LITTLE_ENDIAN) && !defined(__KERN_BIG_ENDIAN)
86  # error Fix asm/byteorder.h to define arch endianness
87  #endif
88  
89 -#ifdef __LITTLE_ENDIAN
90 -# undef __LITTLE_ENDIAN
91 -# define __LITTLE_ENDIAN 1234
92 +#ifdef __KERN_LITTLE_ENDIAN
93 +# ifndef __LITTLE_ENDIAN
94 +#  define __LITTLE_ENDIAN 1234
95 +# endif
96 +# ifndef __LITTLE_ENDIAN_BITFIELD
97 +#  define __LITTLE_ENDIAN_BITFIELD
98 +# endif
99 +#endif
100 +
101 +#ifdef __KERN_BIG_ENDIAN
102 +# ifndef __BIG_ENDIAN
103 +#  define __BIG_ENDIAN 4321
104 +# endif
105 +# ifndef __BIG_ENDIAN_BITFIELD
106 +#  define __BIG_ENDIAN_BITFIELD
107 +# endif
108  #endif
109  
110 -#ifdef __BIG_ENDIAN
111 -# undef __BIG_ENDIAN
112 -# define __BIG_ENDIAN 4321
113 -#endif
114 -
115 -#if defined(__LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN_BITFIELD)
116 -# define __LITTLE_ENDIAN_BITFIELD
117 -#endif
118 -
119 -#if defined(__BIG_ENDIAN) && !defined(__BIG_ENDIAN_BITFIELD)
120 -# define __BIG_ENDIAN_BITFIELD
121 -#endif
122 -
123 -#ifdef __LITTLE_ENDIAN
124 +#ifdef __KERN_LITTLE_ENDIAN
125  # define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
126  # define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
127  # define __le64_to_cpu(x) ((__force __u64)(__le64)(x))
128 @@ -46,7 +46,7 @@
129  # define __cpu_to_be64(x) ((__force __be64)__swab64(x))
130  #endif
131  
132 -#ifdef __BIG_ENDIAN
133 +#ifdef __KERN_BIG_ENDIAN
134  # define __be16_to_cpu(x) ((__force __u16)(__be16)(x))
135  # define __be32_to_cpu(x) ((__force __u32)(__be32)(x))
136  # define __be64_to_cpu(x) ((__force __u64)(__be64)(x))
137 @@ -87,91 +87,91 @@
138  
139  static inline void __le16_to_cpus(__u16 *p)
140  {
141 -#ifdef __BIG_ENDIAN
142 +#ifdef __KERN_BIG_ENDIAN
143         __swab16s(p);
144  #endif
145  }
146  
147  static inline void __cpu_to_le16s(__u16 *p)
148  {
149 -#ifdef __BIG_ENDIAN
150 +#ifdef __KERN_BIG_ENDIAN
151         __swab16s(p);
152  #endif
153  }
154  
155  static inline void __le32_to_cpus(__u32 *p)
156  {
157 -#ifdef __BIG_ENDIAN
158 +#ifdef __KERN_BIG_ENDIAN
159         __swab32s(p);
160  #endif
161  }
162  
163  static inline void __cpu_to_le32s(__u32 *p)
164  {
165 -#ifdef __BIG_ENDIAN
166 +#ifdef __KERN_BIG_ENDIAN
167         __swab32s(p);
168  #endif
169  }
170  
171  static inline void __le64_to_cpus(__u64 *p)
172  {
173 -#ifdef __BIG_ENDIAN
174 +#ifdef __KERN_BIG_ENDIAN
175         __swab64s(p);
176  #endif
177  }
178  
179  static inline void __cpu_to_le64s(__u64 *p)
180  {
181 -#ifdef __BIG_ENDIAN
182 +#ifdef __KERN_BIG_ENDIAN
183         __swab64s(p);
184  #endif
185  }
186  
187  static inline void __be16_to_cpus(__u16 *p)
188  {
189 -#ifdef __LITTLE_ENDIAN
190 +#ifdef __KERN_LITTLE_ENDIAN
191         __swab16s(p);
192  #endif
193  }
194  
195  static inline void __cpu_to_be16s(__u16 *p)
196  {
197 -#ifdef __LITTLE_ENDIAN
198 +#ifdef __KERN_LITTLE_ENDIAN
199         __swab16s(p);
200  #endif
201  }
202  
203  static inline void __be32_to_cpus(__u32 *p)
204  {
205 -#ifdef __LITTLE_ENDIAN
206 +#ifdef __KERN_LITTLE_ENDIAN
207         __swab32s(p);
208  #endif
209  }
210  
211  static inline void __cpu_to_be32s(__u32 *p)
212  {
213 -#ifdef __LITTLE_ENDIAN
214 +#ifdef __KERN_LITTLE_ENDIAN
215         __swab32s(p);
216  #endif
217  }
218  
219  static inline void __be64_to_cpus(__u64 *p)
220  {
221 -#ifdef __LITTLE_ENDIAN
222 +#ifdef __KERN_LITTLE_ENDIAN
223         __swab64s(p);
224  #endif
225  }
226  
227  static inline void __cpu_to_be64s(__u64 *p)
228  {
229 -#ifdef __LITTLE_ENDIAN
230 +#ifdef __KERN_LITTLE_ENDIAN
231         __swab64s(p);
232  #endif
233  }
234  
235  static inline __u16 __le16_to_cpup(const __le16 *p)
236  {
237 -#ifdef __LITTLE_ENDIAN
238 +#ifdef __KERN_LITTLE_ENDIAN
239         return (__force __u16)*p;
240  #else
241         return __swab16p((__force __u16 *)p);
242 @@ -180,7 +180,7 @@ static inline __u16 __le16_to_cpup(const
243  
244  static inline __u32 __le32_to_cpup(const __le32 *p)
245  {
246 -#ifdef __LITTLE_ENDIAN
247 +#ifdef __KERN_LITTLE_ENDIAN
248         return (__force __u32)*p;
249  #else
250         return __swab32p((__force __u32 *)p);
251 @@ -189,7 +189,7 @@ static inline __u32 __le32_to_cpup(const
252  
253  static inline __u64 __le64_to_cpup(const __le64 *p)
254  {
255 -#ifdef __LITTLE_ENDIAN
256 +#ifdef __KERN_LITTLE_ENDIAN
257         return (__force __u64)*p;
258  #else
259         return __swab64p((__force __u64 *)p);
260 @@ -198,7 +198,7 @@ static inline __u64 __le64_to_cpup(const
261  
262  static inline __le16 __cpu_to_le16p(const __u16 *p)
263  {
264 -#ifdef __LITTLE_ENDIAN
265 +#ifdef __KERN_LITTLE_ENDIAN
266         return (__force __le16)*p;
267  #else
268         return (__force __le16)__swab16p(p);
269 @@ -207,7 +207,7 @@ static inline __le16 __cpu_to_le16p(cons
270  
271  static inline __le32 __cpu_to_le32p(const __u32 *p)
272  {
273 -#ifdef __LITTLE_ENDIAN
274 +#ifdef __KERN_LITTLE_ENDIAN
275         return (__force __le32)*p;
276  #else
277         return (__force __le32)__swab32p(p);
278 @@ -216,7 +216,7 @@ static inline __le32 __cpu_to_le32p(cons
279  
280  static inline __le64 __cpu_to_le64p(const __u64 *p)
281  {
282 -#ifdef __LITTLE_ENDIAN
283 +#ifdef __KERN_LITTLE_ENDIAN
284         return (__force __le64)*p;
285  #else
286         return (__force __le64)__swab64p(p);
287 @@ -225,7 +225,7 @@ static inline __le64 __cpu_to_le64p(cons
288  
289  static inline __u16 __be16_to_cpup(const __be16 *p)
290  {
291 -#ifdef __BIG_ENDIAN
292 +#ifdef __KERN_BIG_ENDIAN
293         return (__force __u16)*p;
294  #else
295         return __swab16p((__force __u16 *)p);
296 @@ -234,7 +234,7 @@ static inline __u16 __be16_to_cpup(const
297  
298  static inline __u32 __be32_to_cpup(const __be32 *p)
299  {
300 -#ifdef __BIG_ENDIAN
301 +#ifdef __KERN_BIG_ENDIAN
302         return (__force __u32)*p;
303  #else
304         return __swab32p((__force __u32 *)p);
305 @@ -243,7 +243,7 @@ static inline __u32 __be32_to_cpup(const
306  
307  static inline __u64 __be64_to_cpup(const __be64 *p)
308  {
309 -#ifdef __BIG_ENDIAN
310 +#ifdef __KERN_BIG_ENDIAN
311         return (__force __u64)*p;
312  #else
313         return __swab64p((__force __u64 *)p);
314 @@ -252,7 +252,7 @@ static inline __u64 __be64_to_cpup(const
315  
316  static inline __be16 __cpu_to_be16p(const __u16 *p)
317  {
318 -#ifdef __BIG_ENDIAN
319 +#ifdef __KERN_BIG_ENDIAN
320         return (__force __be16)*p;
321  #else
322         return (__force __be16)__swab16p(p);
323 @@ -261,7 +261,7 @@ static inline __be16 __cpu_to_be16p(cons
324  
325  static inline __be32 __cpu_to_be32p(const __u32 *p)
326  {
327 -#ifdef __BIG_ENDIAN
328 +#ifdef __KERN_BIG_ENDIAN
329         return (__force __be32)*p;
330  #else
331         return (__force __be32)__swab32p(p);
332 @@ -270,7 +270,7 @@ static inline __be32 __cpu_to_be32p(cons
333  
334  static inline __be64 __cpu_to_be64p(const __u64 *p)
335  {
336 -#ifdef __BIG_ENDIAN
337 +#ifdef __KERN_BIG_ENDIAN
338         return (__force __be64)*p;
339  #else
340         return (__force __be64)__swab64p(p);