Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools: usb: ffs-aio-example: Fix build error with aarch64-*-gnu-gcc toolchain(s)

The tools/usb/aio_simple.c file when cross-compiled with
aarch64-*-gnu-gcc toolchain(s) leads to the following errors:

aio_simple.c:30:10: fatal error: endian.h: No such file or directory
30 | #include <endian.h>
| ^~~~~~~~~~

aio_simple.c:88:14: note: (near initialization for
'descriptors.fs_count')
aio_simple.c:110:14: error: initializer element is not constant
110 | .hs_count = htole32(3),
| ^~~~~~~
aio_simple.c:110:14: note: (near initialization for
'descriptors.hs_count')
aio_simple.c:124:22: error: initializer element is not constant
124 | .wMaxPacketSize = htole16(512),
| ^~~~~~~
aio_simple.c:124:22: note: (near initialization for
'descriptors.hs_descs.bulk_sink.wMaxPacketSize')

Fix these compilation issues by:
- Switching to _DEFAULT_SOURCE:
_BSD_SOURCE is deprecated and gives a build warning. Let's use
_DEFAULT_SOURCE instead.
- Currently this file uses library htole16/32 function calls.
Replace these with equivalent 'cpu_to_le16/32' calls.

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Bhupesh Sharma <bhupesh.sharma@linaro.org>
Link: https://lore.kernel.org/r/20221029161312.171165-1-bhupesh.sharma@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Bhupesh Sharma and committed by
Greg Kroah-Hartman
c5edb757 dced8892

+31 -13
+31 -13
tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
··· 25 25 * For more information, please refer to <http://unlicense.org/> 26 26 */ 27 27 28 - #define _BSD_SOURCE /* for endian.h */ 28 + /* $(CROSS_COMPILE)cc -g -o aio_simple aio_simple.c -laio */ 29 + 30 + #define _DEFAULT_SOURCE /* for endian.h */ 29 31 30 32 #include <endian.h> 31 33 #include <errno.h> ··· 51 49 52 50 #define BUF_LEN 8192 53 51 52 + /* 53 + * cpu_to_le16/32 are used when initializing structures, a context where a 54 + * function call is not allowed. To solve this, we code cpu_to_le16/32 in a way 55 + * that allows them to be used when initializing structures. 56 + */ 57 + 58 + #if BYTE_ORDER == __LITTLE_ENDIAN 59 + #define cpu_to_le16(x) (x) 60 + #define cpu_to_le32(x) (x) 61 + #else 62 + #define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)) 63 + #define cpu_to_le32(x) \ 64 + ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \ 65 + (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) 66 + #endif 67 + 54 68 /******************** Descriptors and Strings *******************************/ 55 69 56 70 static const struct { ··· 80 62 } __attribute__ ((__packed__)) fs_descs, hs_descs; 81 63 } __attribute__ ((__packed__)) descriptors = { 82 64 .header = { 83 - .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2), 84 - .flags = htole32(FUNCTIONFS_HAS_FS_DESC | 65 + .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2), 66 + .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC | 85 67 FUNCTIONFS_HAS_HS_DESC), 86 - .length = htole32(sizeof(descriptors)), 68 + .length = cpu_to_le32(sizeof(descriptors)), 87 69 }, 88 - .fs_count = htole32(3), 70 + .fs_count = cpu_to_le32(3), 89 71 .fs_descs = { 90 72 .intf = { 91 73 .bLength = sizeof(descriptors.fs_descs.intf), ··· 107 89 .bmAttributes = USB_ENDPOINT_XFER_BULK, 108 90 }, 109 91 }, 110 - .hs_count = htole32(3), 92 + .hs_count = cpu_to_le32(3), 111 93 .hs_descs = { 112 94 .intf = { 113 95 .bLength = sizeof(descriptors.hs_descs.intf), ··· 121 103 .bDescriptorType = USB_DT_ENDPOINT, 122 104 .bEndpointAddress = 1 | USB_DIR_IN, 123 105 .bmAttributes = USB_ENDPOINT_XFER_BULK, 124 - .wMaxPacketSize = htole16(512), 106 + .wMaxPacketSize = cpu_to_le16(512), 125 107 }, 126 108 .bulk_source = { 127 109 .bLength = sizeof(descriptors.hs_descs.bulk_source), 128 110 .bDescriptorType = USB_DT_ENDPOINT, 129 111 .bEndpointAddress = 2 | USB_DIR_OUT, 130 112 .bmAttributes = USB_ENDPOINT_XFER_BULK, 131 - .wMaxPacketSize = htole16(512), 113 + .wMaxPacketSize = cpu_to_le16(512), 132 114 }, 133 115 }, 134 116 }; ··· 143 125 } __attribute__ ((__packed__)) lang0; 144 126 } __attribute__ ((__packed__)) strings = { 145 127 .header = { 146 - .magic = htole32(FUNCTIONFS_STRINGS_MAGIC), 147 - .length = htole32(sizeof(strings)), 148 - .str_count = htole32(1), 149 - .lang_count = htole32(1), 128 + .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC), 129 + .length = cpu_to_le32(sizeof(strings)), 130 + .str_count = cpu_to_le32(1), 131 + .lang_count = cpu_to_le32(1), 150 132 }, 151 133 .lang0 = { 152 - htole16(0x0409), /* en-us */ 134 + cpu_to_le16(0x0409), /* en-us */ 153 135 STR_INTERFACE, 154 136 }, 155 137 };