diff mbox series

[1/3] net: avoid cast-align warning in VLAN insert function

Message ID 20210713064910.12793-2-elibr@nvidia.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series Avoid cast-align warnings | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Eli Britstein July 13, 2021, 6:49 a.m. UTC
In rte_vlan_insert there is a casting of rte_pktmbuf_prepend returned
value to (struct rte_ether_hdr *), which causes cast-align warning when
using gcc flags '-Werror -Wcast-align':

In file included from .../include/rte_ethdev.h:165,
                 from lib/netdev-dpdk.c:33:
.../include/rte_ether.h: In function 'rte_vlan_insert':
.../include/rte_ether.h:375:7: error: cast increases required alignment
    of target type [-Werror=cast-align]
  375 |  nh = (struct rte_ether_hdr *)
      |       ^

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

Fixes: c974021a5949 ("ether: add soft vlan encap/decap")
Cc: stable@dpdk.org

Signed-off-by: Eli Britstein <elibr@nvidia.com>
---
 lib/net/rte_ether.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Olivier Matz July 30, 2021, 10:57 a.m. UTC | #1
On Tue, Jul 13, 2021 at 09:49:08AM +0300, Eli Britstein wrote:
> In rte_vlan_insert there is a casting of rte_pktmbuf_prepend returned
> value to (struct rte_ether_hdr *), which causes cast-align warning when
> using gcc flags '-Werror -Wcast-align':
> 
> In file included from .../include/rte_ethdev.h:165,
>                  from lib/netdev-dpdk.c:33:
> .../include/rte_ether.h: In function 'rte_vlan_insert':
> .../include/rte_ether.h:375:7: error: cast increases required alignment
>     of target type [-Werror=cast-align]
>   375 |  nh = (struct rte_ether_hdr *)
>       |       ^
> 
> As the code assumes correct alignment, add first a (void *) casting, to
> avoid the warning.
> 
> Fixes: c974021a5949 ("ether: add soft vlan encap/decap")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Eli Britstein <elibr@nvidia.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>
diff mbox series

Patch

diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index 7ee5e9a292..6e21155161 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -372,7 +372,7 @@  static inline int rte_vlan_insert(struct rte_mbuf **m)
 		return -EINVAL;
 
 	oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *);
-	nh = (struct rte_ether_hdr *)
+	nh = (struct rte_ether_hdr *)(void *)
 		rte_pktmbuf_prepend(*m, sizeof(struct rte_vlan_hdr));
 	if (nh == NULL)
 		return -ENOSPC;