Thread (19 messages) 19 messages, 4 authors, 2021-10-25

Re: [dpdk-dev] [PATCH 2/3] mbuf: avoid cast-align warning in pktmbuf mtod offset macro

From: Olivier Matz <hidden>
Date: 2021-07-28 15:28:51

On Tue, Jul 13, 2021 at 09:49:09AM +0300, Eli Britstein wrote:
In rte_pktmbuf_mtod_offset macro, there is a casting from char * to type
't', which may cause cast-align warning when using gcc flags
'-Werror -Wcast-align':

.../include/rte_mbuf_core.h:723:3: error: cast increases required alignment
    of target type [-Werror=cast-align]
  723 |  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
      |   ^

As the code assumes correct alignment, add first a (void *) casting, to
avoid the warning.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Eli Britstein <redacted>
My initial thinking was that it's the problem of the application: if
-Werror=cast-align is used, it is up to the application to cast the
return value of rte_pktmbuf_mtod_offset() to (void *) before casting it
to the network type.

But, if I understand correctly, the problem is not about the application
code itself, but about inlined code in the header files of dpdk
(i.e. compiling an empty C file that just includes the dpdk headers with
-Werror=cast-align). Is it correct? If yes I think it should be
highlighted in the commit log.

Out of curiosity, how did you find the errors? I mean, is it possible
that some casts are missing some other headers, or is this patchset
exhaustive?

Thanks,
Olivier

quoted hunk ↗ jump to hunk
---
 lib/mbuf/rte_mbuf_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/mbuf/rte_mbuf_core.h b/lib/mbuf/rte_mbuf_core.h
index bb38d7f581..dabdeee604 100644
--- a/lib/mbuf/rte_mbuf_core.h
+++ b/lib/mbuf/rte_mbuf_core.h
@@ -720,7 +720,7 @@ struct rte_mbuf_ext_shared_info {
  *   The type to cast the result into.
  */
 #define rte_pktmbuf_mtod_offset(m, t, o)	\
-	((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
+	((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
 
 /**
  * A macro that points to the start of the data in the mbuf.
-- 
2.28.0.2311.g225365fb51
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help