From 50be359a96b34e24a462459005cdacc151a5ccad Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 9 Nov 2021 17:46:31 +0100 Subject: [PATCH 1/2] sys/net/gnrc: fix compilation with -Wcast-align Also ensure that the alignment requirement is indeed matched. --- sys/include/net/gnrc/sixlowpan/frag/rb.h | 5 ++++- .../sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/include/net/gnrc/sixlowpan/frag/rb.h b/sys/include/net/gnrc/sixlowpan/frag/rb.h index c990ada640..4994044e13 100644 --- a/sys/include/net/gnrc/sixlowpan/frag/rb.h +++ b/sys/include/net/gnrc/sixlowpan/frag/rb.h @@ -22,7 +22,9 @@ #include #include +#include +#include "architecture.h" #include "net/gnrc/netif/hdr.h" #include "net/gnrc/pkt.h" #ifdef MODULE_GNRC_SIXLOWPAN_FRAG_SFR @@ -99,13 +101,14 @@ typedef struct { * @brief The reassembled packet in the packet buffer */ gnrc_pktsnip_t *pkt; -#if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR) +#if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR) || defined(DOXYGEN) /** * @brief Bitmap for received fragments * * @note Only available with module `gnrc_sixlowpan_frag_sfr` compiled * in. */ + alignas(gnrc_sixlowpan_frag_sfr_bitmap_t) BITFIELD(received, SIXLOWPAN_SFR_ACK_BITMAP_SIZE); int8_t offset_diff; /**< offset change due to * recompression */ diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c b/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c index 8058a5b545..d2bcda3cf8 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c @@ -13,6 +13,8 @@ * @author Martine Lenders */ +#include + #include "irq.h" #include "kernel_defines.h" #ifdef MODULE_GNRC_IPV6_NIB @@ -106,7 +108,7 @@ static gnrc_sixlowpan_frag_sfr_stats_t _stats; * * @return A gnrc_sixlowpan_frag_sfr_bitmap_t. */ -static inline gnrc_sixlowpan_frag_sfr_bitmap_t *_to_bitmap(uint8_t *bitmap); +static inline gnrc_sixlowpan_frag_sfr_bitmap_t *_get_bitmap(gnrc_sixlowpan_frag_rb_t *frag_rb); /** * @brief Checks if fragment represented by a fragment descriptor requested an @@ -927,7 +929,7 @@ static void _try_reassembly(gnrc_netif_hdr_t *netif_hdr, entry->entry.rb->received[3], entry->entry.base->current_size, entry->entry.base->datagram_size); - bitmap = _to_bitmap(entry->entry.rb->received); + bitmap = _get_bitmap(entry->entry.rb); if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_STATS)) { _stats.acks.partly++; } @@ -1209,9 +1211,14 @@ static void _check_failed_frags(sixlowpan_sfr_ack_t *ack, /* ====== INTERNAL FUNCTIONS USED BY PUBLIC FUNCTIONS ====== * ====== AND TO MANIPULATE INTERNAL DATA STRUCTURES ====== */ -static inline gnrc_sixlowpan_frag_sfr_bitmap_t *_to_bitmap(uint8_t *bitmap) +static inline gnrc_sixlowpan_frag_sfr_bitmap_t *_get_bitmap(gnrc_sixlowpan_frag_rb_t *frag_rb) { - return (gnrc_sixlowpan_frag_sfr_bitmap_t *)bitmap; + DECLARE_CONSTANT(is_aligned, + HAS_ALIGNMENT_OF(offsetof(gnrc_sixlowpan_frag_rb_t, received), + alignof(gnrc_sixlowpan_frag_sfr_bitmap_t))) + static_assert(is_aligned, + "gnrc_sixlowpan_frag_rb_t::received must be suitably aligned"); + return (gnrc_sixlowpan_frag_sfr_bitmap_t *)(uintptr_t)frag_rb->received; } static inline bool _frag_ack_req(_frag_desc_t *frag) From 6907bdf140bd7cf077c06410fd2673245211f251 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 16 Nov 2021 14:49:59 +0100 Subject: [PATCH 2/2] sys/net/gnrc: make cppcheck happy --- .../network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c b/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c index d2bcda3cf8..7b77c12e7a 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/sfr/gnrc_sixlowpan_frag_sfr.c @@ -1401,7 +1401,7 @@ static int _resend_frag(clist_node_t *node, void *fbuf_ptr) cur_frag_size = _find_offset_and_copy_rest(data, &pkt, frag_size, frag_desc->offset); /* copy remaining packet snips */ - cur_frag_size = _copy_pkt_to_frag(data, pkt, frag_size, cur_frag_size); + _copy_pkt_to_frag(data, pkt, frag_size, cur_frag_size); DEBUG("6lo sfr: resending fragment (retry: %u, tag: %u, X: %i, seq: %u, " "frag_size: %u, %s: %u)\n", frag_desc->retries, hdr->base.tag, sixlowpan_sfr_rfrag_ack_req(hdr),