Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From 548b8ca62c64a16305929e2eaf3d546d48de9c25 Mon Sep 17 00:00:00 2001 |
| 2 | From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 3 | Date: Tue, 21 Feb 2017 19:46:24 +0100 |
| 4 | Subject: [PATCH] adb: Fix build on big endian systems |
| 5 | |
| 6 | The usb_linux_client.c file defines cpu_to_le16/32 by using the C |
| 7 | library htole16/32 function calls. However, cpu_to_le16/32 are used |
| 8 | when initializing structures, i.e in a context where a function call |
| 9 | is not allowed. |
| 10 | |
| 11 | It works fine on little endian systems because htole16/32 are defined |
| 12 | by the C library as no-ops. But on big-endian systems, they are |
| 13 | actually doing something, which might involve calling a function, |
| 14 | causing build failures. |
| 15 | |
| 16 | To solve this, we simply open-code cpu_to_le16/32 in a way that allows |
| 17 | them to be used when initializing structures. |
| 18 | |
| 19 | Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 20 | --- |
| 21 | adb/usb_linux_client.c | 11 +++++++++-- |
| 22 | 1 file changed, 9 insertions(+), 2 deletions(-) |
| 23 | |
| 24 | diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c |
| 25 | index 8426e0ea14..6e8b5bbbd2 100644 |
| 26 | --- a/adb/usb_linux_client.c |
| 27 | +++ b/adb/usb_linux_client.c |
| 28 | @@ -34,8 +34,15 @@ |
| 29 | #define MAX_PACKET_SIZE_FS 64 |
| 30 | #define MAX_PACKET_SIZE_HS 512 |
| 31 | |
| 32 | -#define cpu_to_le16(x) htole16(x) |
| 33 | -#define cpu_to_le32(x) htole32(x) |
| 34 | +#if __BYTE_ORDER == __LITTLE_ENDIAN |
| 35 | +# define cpu_to_le16(x) (x) |
| 36 | +# define cpu_to_le32(x) (x) |
| 37 | +#else |
| 38 | +# define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)) |
| 39 | +# define cpu_to_le32(x) \ |
| 40 | + ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \ |
| 41 | + (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) |
| 42 | +#endif |
| 43 | |
| 44 | struct usb_handle |
| 45 | { |