Skip to content

Commit ca9c3ad

Browse files
finikorgAnas Nashif
authored and
Anas Nashif
committed
usb: rndis: Use offsetof macro to ease offset calculations
Use macro offsetof() for calculating offset inside structure. Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent be1d865 commit ca9c3ad

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

subsys/usb/class/netusb/function_rndis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int parse_rndis_header(const u8_t *buffer, u32_t buf_len)
154154
*/
155155
if (len < sys_le32_to_cpu(hdr->payload_offset) +
156156
sys_le32_to_cpu(hdr->payload_len) +
157-
(u8_t *)&hdr->payload_offset - (u8_t *)hdr) {
157+
offsetof(struct rndis_payload_packet, payload_offset)) {
158158
SYS_LOG_ERR("Incorrect RNDIS packet");
159159
return -EINVAL;
160160
}
@@ -897,7 +897,7 @@ static void cmd_thread(void)
897897
static void rndis_hdr_add(u8_t *buf, u32_t len)
898898
{
899899
struct rndis_payload_packet *hdr = (void *)buf;
900-
u32_t offset = (u8_t *)&hdr->payload_offset - (u8_t *)hdr;
900+
u32_t offset = offsetof(struct rndis_payload_packet, payload_offset);
901901

902902
memset(hdr, 0, sizeof(*hdr));
903903

0 commit comments

Comments
 (0)