You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2019/07/08 20:44:48 UTC
[mynewt-nimble] 08/08: nimble/ll: Add static checks for mbuf data
alignment
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit d512d353a021605b901740e3bd3281c547a9a9c2
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sun Jul 7 11:40:10 2019 +0200
nimble/ll: Add static checks for mbuf data alignment
Since copying of received PDUs into mbufs assumes data in mbuf is word
aligned, let's add static checks to make sure this is indeed true to
avoid surprises in the future.
---
nimble/controller/src/ble_ll.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 45a7b92..94ab950 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -320,6 +320,18 @@ ble_ll_rxpdu_alloc(uint16_t len)
uint16_t databuf_len;
int rem_len;
+ /*
+ * Make sure that data in mbuf are word-aligned with and without packet
+ * header. This is essential for proper and quick copying of received PDUs
+ * into mbufs.
+ */
+ _Static_assert((offsetof(struct os_mbuf, om_data) & 3) == 0,
+ "Unaligned om_data");
+ _Static_assert(((offsetof(struct os_mbuf, om_data) +
+ sizeof(struct os_mbuf_pkthdr) +
+ sizeof(struct ble_mbuf_hdr)) & 3) == 0,
+ "Unaligned data trailing packet header");
+
om_ret = os_msys_get_pkthdr(len, sizeof(struct ble_mbuf_hdr));
if (!om_ret) {
goto rxpdu_alloc_fail;