Skip to content

Commit

Permalink
treewide: fix strict-aliasing errors
Browse files Browse the repository at this point in the history
How valid/stupid/useless/dangerous is this patch? I don't know.
Hopefully, we'll find out soon enough.

Signed-off-by: Robin Jarry <[email protected]>
  • Loading branch information
rjarry committed Mar 27, 2024
1 parent c9ca8b2 commit 289dac9
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct br_client *br_connect(const char *sock_path) {

strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);

if (connect(client->sock_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
if (connect(client->sock_fd, (void *)&addr, sizeof(addr)) < 0)
goto err;

return client;
Expand Down
2 changes: 1 addition & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static int listen_api_socket(void) {

strncpy(addr.sun_path, br.api_sock_path, sizeof addr.sun_path - 1);

if (bind(fd, (struct sockaddr *)&addr, sizeof addr) < 0) {
if (bind(fd, (void *)&addr, sizeof addr) < 0) {
LOG(ERR, "bind: %s: %s", br.api_sock_path, strerror(errno));
close(fd);
return -1;
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ project(
add_project_arguments('-D_GNU_SOURCE', language: 'c')
add_project_arguments('-DALLOW_EXPERIMENTAL_API', language: 'c')
add_project_arguments('-Wmissing-prototypes', language: 'c')
add_project_arguments('-fstrict-aliasing', language: 'c')
add_project_arguments('-Wstrict-aliasing=2', language: 'c')
add_project_arguments('-Wno-format-truncation', language: 'c')

dpdk_dep = dependency(
Expand Down
15 changes: 9 additions & 6 deletions modules/infra/control/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ static void set_key(struct node_data_key *key, const char *graph, const char *no
memccpy(key->node, node, 0, sizeof(key->node));
}

int br_node_data_get(const char *graph, const char *node, void **data) {
void *br_node_data_get(const char *graph, const char *node) {
struct node_data_key key;
void *data = NULL;

set_key(&key, graph, node);
if (rte_hash_lookup_data(hash, &key, data) < 0) {

if (rte_hash_lookup_data(hash, &key, &data) < 0) {
LOG(ERR, "(%s, %s): %s", graph, node, rte_strerror(rte_errno));
return -1;
return NULL;
}
return 0;
return data;
}

int br_node_data_set(const char *graph, const char *node, void *data) {
Expand Down Expand Up @@ -93,7 +96,7 @@ static void node_data_reset(const char *graph) {
uint32_t iter;

iter = 0;
while (rte_hash_iterate(hash, (const void **)&key, &data, &iter) >= 0) {
while (rte_hash_iterate(hash, (void *)&key, &data, &iter) >= 0) {
if (strcmp(key->graph, graph) == 0) {
rte_hash_del_key(hash, key);
free(data);
Expand Down Expand Up @@ -399,7 +402,7 @@ static void graph_fini(void) {
uint32_t iter;

iter = 0;
while (rte_hash_iterate(hash, (const void **)&key, &data, &iter) >= 0) {
while (rte_hash_iterate(hash, (void *)&key, &data, &iter) >= 0) {
rte_hash_del_key(hash, key);
free(data);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/datapath/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int rx_init(const struct rte_graph *graph, struct rte_node *node) {

(void)graph;

if (br_node_data_get(graph->name, node->name, (void **)&data) < 0)
if ((data = br_node_data_get(graph->name, node->name)) == NULL)
return -1;

ctx = rte_zmalloc(
Expand Down
8 changes: 4 additions & 4 deletions modules/infra/datapath/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static inline uint16_t tx_burst(
txq_id = ctx->txq_ids[port_id];
tx_ok = rte_eth_tx_burst(port_id, txq_id, mbufs, n);
if (tx_ok < n)
rte_node_enqueue(graph, node, TX_ERROR, (void **)&mbufs[tx_ok], n - tx_ok);
rte_node_enqueue(graph, node, TX_ERROR, (void *)&mbufs[tx_ok], n - tx_ok);

return tx_ok;
}
Expand All @@ -54,7 +54,7 @@ tx_process(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t
struct tx_mbuf_priv *priv;

if ((priv = tx_mbuf_priv(mbuf)) == NULL) {
rte_node_enqueue(graph, node, NO_PORT, (void **)&mbuf, 1);
rte_node_enqueue(graph, node, NO_PORT, (void *)&mbuf, 1);
continue;
}
if (priv->port_id != port_id) {
Expand All @@ -64,7 +64,7 @@ tx_process(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t
graph,
node,
port_id,
(struct rte_mbuf **)&objs[burst_start],
(void *)&objs[burst_start],
i - burst_start
);
}
Expand Down Expand Up @@ -109,7 +109,7 @@ static int tx_init(const struct rte_graph *graph, struct rte_node *node) {
return -1;
}

if (br_node_data_get(graph->name, node->name, (void **)&data) < 0)
if ((data = br_node_data_get(graph->name, node->name)) == NULL)
return -1;

ctx = rte_malloc(__func__, sizeof(*ctx), RTE_CACHE_LINE_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/include/br_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var = (void *)node->ctx; \
} while (0)

int br_node_data_get(const char *graph, const char *node, void **data);
void *br_node_data_get(const char *graph, const char *node);

int br_node_data_set(const char *graph, const char *node, void *data);

Expand Down
4 changes: 2 additions & 2 deletions modules/infra/lib/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int br_infra_graph_dump(const struct br_client *c, size_t *len, char **dot) {
errno = EINVAL;
goto out;
}
if (send_recv(c, BR_INFRA_GRAPH_DUMP, 0, NULL, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_GRAPH_DUMP, 0, NULL, (void *)&resp) < 0)
goto out;

*dot = calloc(1, resp->len);
Expand Down Expand Up @@ -49,7 +49,7 @@ int br_infra_graph_stats(
goto out;
}

if (send_recv(c, BR_INFRA_GRAPH_STATS, 0, NULL, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_GRAPH_STATS, 0, NULL, (void *)&resp) < 0)
goto out;

*stats = calloc(resp->n_stats, sizeof(*resp->stats));
Expand Down
6 changes: 3 additions & 3 deletions modules/infra/lib/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int br_infra_port_add(const struct br_client *c, const char *devargs, uint16_t *
memset(&req, 0, sizeof(req));
memccpy(req.devargs, devargs, 0, sizeof(req.devargs));

if (send_recv(c, BR_INFRA_PORT_ADD, sizeof(req), &req, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_PORT_ADD, sizeof(req), &req, (void *)&resp) < 0)
goto out;

if (port_id != NULL)
Expand Down Expand Up @@ -48,7 +48,7 @@ int br_infra_port_get(const struct br_client *c, uint16_t port_id, struct br_inf
goto out;
}

if (send_recv(c, BR_INFRA_PORT_GET, sizeof(req), &req, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_PORT_GET, sizeof(req), &req, (void *)&resp) < 0)
goto out;

memcpy(port, &resp->port, sizeof(*port));
Expand All @@ -68,7 +68,7 @@ int br_infra_port_list(const struct br_client *c, size_t *n_ports, struct br_inf
goto out;
}

if (send_recv(c, BR_INFRA_PORT_LIST, 0, NULL, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_PORT_LIST, 0, NULL, (void *)&resp) < 0)
goto out;

*n_ports = resp->n_ports;
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/lib/rxq.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int br_infra_rxq_list(const struct br_client *c, size_t *n_rxqs, struct br_infra
goto out;
}

if (send_recv(c, BR_INFRA_RXQ_LIST, 0, NULL, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_RXQ_LIST, 0, NULL, (void *)&resp) < 0)
goto out;

*n_rxqs = resp->n_rxqs;
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/lib/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int br_infra_stats_get(
if (pattern != NULL)
snprintf(req.pattern, sizeof(req.pattern), "%s", pattern);

if (send_recv(c, BR_INFRA_STATS_GET, sizeof(req), &req, (void **)&resp) < 0)
if (send_recv(c, BR_INFRA_STATS_GET, sizeof(req), &req, (void *)&resp) < 0)
goto out;

*stats = calloc(resp->n_stats, sizeof(*resp->stats));
Expand Down
8 changes: 4 additions & 4 deletions modules/ip4/control/nh4.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int next_hop_lookup(ip4_addr_t gw, struct next_hop **nh) {
int ret;
if (next_hops == NULL)
return -EIO;
if ((ret = rte_hash_lookup_data(next_hops, &gw, (void **)nh)) < 0) {
if ((ret = rte_hash_lookup_data(next_hops, &gw, (void *)nh)) < 0) {
return ret;
}
return 0;
Expand All @@ -53,7 +53,7 @@ int next_hop_delete(ip4_addr_t gw, bool force) {
if (next_hops == NULL)
return -EIO;

pos = rte_hash_lookup_data(next_hops, &gw, (void **)&nh);
pos = rte_hash_lookup_data(next_hops, &gw, (void *)&nh);
if (pos == -ENOENT && force)
return 0;
if (pos < 0)
Expand Down Expand Up @@ -82,7 +82,7 @@ static struct api_out nh4_add(const void *request, void **response) {
return api_out(ENODEV, 0);
if (next_hop_lookup(req->nh.host, &old_nh) == 0 && !req->exist_ok)
return api_out(EEXIST, 0);
if (rte_mempool_get(nh_pool, (void **)&nh) < 0)
if (rte_mempool_get(nh_pool, (void *)&nh) < 0)
return api_out(ENOMEM, 0);

memset(nh, 0, sizeof(*nh));
Expand Down Expand Up @@ -137,7 +137,7 @@ static struct api_out nh4_list(const void *request, void **response) {

num = 0;
iter = 0;
while (rte_hash_iterate(next_hops, (const void **)&host, (void **)&nh, &iter) >= 0) {
while (rte_hash_iterate(next_hops, (void *)&host, (void *)&nh, &iter) >= 0) {
resp->nhs[num].host = nh->ip;
resp->nhs[num].port_id = nh->port_id;
memcpy(&resp->nhs[num].mac, &nh->eth_addr[0], sizeof(resp->nhs[num].mac));
Expand Down
2 changes: 1 addition & 1 deletion modules/ip4/datapath/rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ rewrite_process(struct rte_graph *graph, struct rte_node *node, void **objs, uin
trace_packet(node->name, mbuf);

dst_addr = ip4_fwd_mbuf_priv(mbuf)->next_hop;
if (rte_hash_lookup_data(next_hops, &dst_addr, (void **)&nh) < 0)
if (rte_hash_lookup_data(next_hops, &dst_addr, (void *)&nh) < 0)
goto next;

eth_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *);
Expand Down
2 changes: 1 addition & 1 deletion modules/ip4/lib/nh4.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int br_ip_nh4_list(const struct br_client *c, size_t *n_nhs, struct br_ip_nh4 **
goto out;
}

if (send_recv(c, BR_IP_NH4_LIST, 0, NULL, (void **)&resp) < 0)
if (send_recv(c, BR_IP_NH4_LIST, 0, NULL, (void *)&resp) < 0)
goto out;

*n_nhs = resp->n_nhs;
Expand Down
4 changes: 2 additions & 2 deletions modules/ip4/lib/route4.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int br_ip_route4_get(const struct br_client *c, ip4_addr_t dest, struct br_ip_nh
}

req.dest = dest;
if ((ret = send_recv(c, BR_IP_ROUTE4_GET, sizeof(req), &req, (void **)&resp)) < 0)
if ((ret = send_recv(c, BR_IP_ROUTE4_GET, sizeof(req), &req, (void *)&resp)) < 0)
goto out;

memcpy(nh, &resp->nh, sizeof(*nh));
Expand All @@ -76,7 +76,7 @@ int br_ip_route4_list(const struct br_client *c, size_t *n_routes, struct br_ip_
goto out;
}

if (send_recv(c, BR_IP_ROUTE4_LIST, 0, NULL, (void **)&resp) < 0)
if (send_recv(c, BR_IP_ROUTE4_LIST, 0, NULL, (void *)&resp) < 0)
goto out;

*n_routes = resp->n_routes;
Expand Down
1 change: 1 addition & 0 deletions subprojects/dpdk.wrap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ depth = 1
diff_files =
dpdk/build-whole-archive-for-static-libs.patch,
dpdk/build-pass-cflags-in-subproject.patch,
dpdk/mbuf-fix-strict-aliasing-error.patch,
dpdk/graph-enhance-export-to-graphviz.patch,
dpdk/graph-expose-node-context-as-pointers.patch,
dpdk/graph-avoid-accessing-global-list-in-rte_graph_clust.patch,
Expand Down
29 changes: 29 additions & 0 deletions subprojects/packagefiles/dpdk/mbuf-fix-strict-aliasing-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 880c9688cf7403846dbf6ef0191e722d62a16a23 Mon Sep 17 00:00:00 2001
From: Robin Jarry <[email protected]>
Date: Wed, 27 Mar 2024 22:22:13 +0100
Subject: [PATCH] mbuf: fix strict-aliasing error

Signed-off-by: Robin Jarry <[email protected]>
---
lib/mbuf/rte_mbuf.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index 286b32b788a5..0076f0d80ba8 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -595,9 +595,9 @@ __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m)
*/
static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
{
- struct rte_mbuf *m;
+ void *m;

- if (rte_mempool_get(mp, (void **)&m) < 0)
+ if (rte_mempool_get(mp, &m) < 0)
return NULL;
__rte_mbuf_raw_sanity_check(m);
return m;
--
2.44.0

0 comments on commit 289dac9

Please sign in to comment.