Skip to content

Commit

Permalink
ethdev: convert string initialization
Browse files Browse the repository at this point in the history
gcc 15 experimental [1], with -Wextra flag, gives warning in variable
initialization as string [2].

The warning has a point when initialized variable is intended to use as
string, since assignment is missing the required null terminator for
this case. But warning is useless for our usecase.

In this patch only updated a few instance to show the issue, there are
many instances to fix, if we prefer to go this way.
Other option is to disable warning but it can be useful for actual
string usecases, so I prefer to keep it.

Converted string initialization to array initialization.

[1]
gcc (GCC) 15.0.0 20241003 (experimental)

[2]
../lib/ethdev/rte_flow.h:906:36:
  error: initializer-string for array of ‘unsigned char’ is too long
        [-Werror=unterminated-string-initialization]
906 |         .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
    |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~

../lib/ethdev/rte_flow.h:907:36:
  error: initializer-string for array of ‘unsigned char’ is too long
         [-Werror=unterminated-string-initialization]
907 |         .hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
    |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~

../lib/ethdev/rte_flow.h:1009:25:
  error: initializer-string for array of ‘unsigned char’ is too long
         [-Werror=unterminated-string-initialization]
1009 |                         "\xff\xff\xff\xff\xff\xff\xff\xff"
     |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../lib/ethdev/rte_flow.h:1012:25:
  error: initializer-string for array of ‘unsigned char’ is too long
         [-Werror=unterminated-string-initialization]
1012 |                         "\xff\xff\xff\xff\xff\xff\xff\xff"
     |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../lib/ethdev/rte_flow.h:1135:20:
  error: initializer-string for array of ‘unsigned char’ is too long
         [-Werror=unterminated-string-initialization]
1135 |         .hdr.vni = "\xff\xff\xff",
     |                    ^~~~~~~~~~~~~~

Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
  • Loading branch information
ferruhy committed Oct 10, 2024
1 parent e347b12 commit 20af899
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 163 deletions.
31 changes: 16 additions & 15 deletions app/test-pmd/cmdline_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,20 +898,20 @@ struct vxlan_encap_conf vxlan_encap_conf = {
.select_ipv4 = 1,
.select_vlan = 0,
.select_tos_ttl = 0,
.vni = "\x00\x00\x00",
.vni = { 0x00, 0x00, 0x00 },
.udp_src = 0,
.udp_dst = RTE_BE16(RTE_VXLAN_DEFAULT_PORT),
.ipv4_src = RTE_IPV4(127, 0, 0, 1),
.ipv4_dst = RTE_IPV4(255, 255, 255, 255),
.ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x01",
.ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x11\x11",
.ipv6_src = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
.ipv6_dst = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11 },
.vlan_tci = 0,
.ip_tos = 0,
.ip_ttl = 255,
.eth_src = "\x00\x00\x00\x00\x00\x00",
.eth_dst = "\xff\xff\xff\xff\xff\xff",
.eth_src = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.eth_dst = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};

/** Maximum number of items in struct rte_flow_action_vxlan_encap. */
Expand All @@ -934,16 +934,16 @@ struct action_vxlan_encap_data {
struct nvgre_encap_conf nvgre_encap_conf = {
.select_ipv4 = 1,
.select_vlan = 0,
.tni = "\x00\x00\x00",
.tni = { 0x00, 0x00, 0x00 },
.ipv4_src = RTE_IPV4(127, 0, 0, 1),
.ipv4_dst = RTE_IPV4(255, 255, 255, 255),
.ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x01",
.ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x11\x11",
.ipv6_src = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
.ipv6_dst = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11 },
.vlan_tci = 0,
.eth_src = "\x00\x00\x00\x00\x00\x00",
.eth_dst = "\xff\xff\xff\xff\xff\xff",
.eth_src = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.eth_dst = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};

/** Maximum number of items in struct rte_flow_action_nvgre_encap. */
Expand Down Expand Up @@ -8304,7 +8304,8 @@ parse_prefix(struct context *ctx, const struct token *token,
void *buf, unsigned int size)
{
const struct arg *arg = pop_args(ctx);
static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
static const uint8_t conv[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0,
0xf8, 0xfc, 0xfe, 0xff };
char *end;
uintmax_t u;
unsigned int bytes;
Expand Down
2 changes: 1 addition & 1 deletion app/test/test_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3361,7 +3361,7 @@ test_bpf_filter_sanity(pcap_t *pcap)

hdr = rte_pktmbuf_mtod(m, typeof(hdr));
hdr->eth_hdr = (struct rte_ether_hdr) {
.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4),
};
hdr->ip_hdr = (struct rte_ipv4_hdr) {
Expand Down
2 changes: 1 addition & 1 deletion app/test/test_pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mbuf1_prepare(struct dummy_mbuf *dm, uint32_t plen)
struct rte_udp_hdr udp;
} pkt = {
.eth = {
.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4),
},
.ip = {
Expand Down
4 changes: 2 additions & 2 deletions app/test/test_security_inline_macsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ create_default_flow(const struct mcs_test_vector *td, uint16_t portid,
struct rte_flow *flow;
struct rte_flow_item_eth eth = { .hdr.ether_type = 0, };
static const struct rte_flow_item_eth eth_mask = {
.hdr.dst_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
.hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
.hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.hdr.ether_type = RTE_BE16(0x0000),
};

Expand Down
2 changes: 1 addition & 1 deletion doc/guides/prog_guide/ethdev/flow_offload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,7 @@ For example, to create a pattern template to match on the destination MAC:
const struct rte_flow_pattern_template_attr attr = {.ingress = 1};
struct rte_flow_item_eth eth_m = {
.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff";
.dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
};
struct rte_flow_item pattern[] = {
[0] = {.type = RTE_FLOW_ITEM_TYPE_ETH,
Expand Down
14 changes: 6 additions & 8 deletions drivers/net/cxgbe/cxgbe_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,8 @@ static struct chrte_fparse parseitem[] = {
[RTE_FLOW_ITEM_TYPE_ETH] = {
.fptr = ch_rte_parsetype_eth,
.dmask = &(const struct rte_flow_item_eth){
.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00",
.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.hdr.ether_type = 0xffff,
}
},
Expand Down Expand Up @@ -918,12 +918,10 @@ static struct chrte_fparse parseitem[] = {
.fptr = ch_rte_parsetype_ipv6,
.dmask = &(const struct rte_flow_item_ipv6) {
.hdr = {
.src_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.dst_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.src_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.dst_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.vtc_flow = RTE_BE32(0xff000000),
},
},
Expand Down
14 changes: 6 additions & 8 deletions drivers/net/dpaa2/dpaa2_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ enum rte_flow_action_type dpaa2_supported_fs_action_type[] = {

#ifndef __cplusplus
static const struct rte_flow_item_eth dpaa2_flow_item_eth_mask = {
.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.ether_type = RTE_BE16(0xffff),
};

Expand All @@ -117,12 +117,10 @@ static const struct rte_flow_item_ipv4 dpaa2_flow_item_ipv4_mask = {

static const struct rte_flow_item_ipv6 dpaa2_flow_item_ipv6_mask = {
.hdr = {
.src_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.dst_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.src_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.dst_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.proto = 0xff
},
};
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/mlx4/mlx4_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ static const struct mlx4_flow_proc_item mlx4_flow_proc_item_list[] = {
RTE_FLOW_ITEM_TYPE_IPV4),
.mask_support = &(const struct rte_flow_item_eth){
/* Only destination MAC can be matched. */
.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
},
.mask_default = &rte_flow_item_eth_mask,
.mask_sz = sizeof(struct rte_flow_item_eth),
Expand Down Expand Up @@ -1304,10 +1304,10 @@ mlx4_flow_internal(struct mlx4_priv *priv, struct rte_flow_error *error)
};
struct rte_flow_item_eth eth_spec;
const struct rte_flow_item_eth eth_mask = {
.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};
const struct rte_flow_item_eth eth_allmulti = {
.hdr.dst_addr.addr_bytes = "\x01\x00\x00\x00\x00\x00",
.hdr.dst_addr.addr_bytes = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
struct rte_flow_item_vlan vlan_spec;
const struct rte_flow_item_vlan vlan_mask = {
Expand Down
20 changes: 9 additions & 11 deletions drivers/net/mlx5/mlx5_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -2668,8 +2668,8 @@ mlx5_flow_validate_item_eth(const struct rte_eth_dev *dev,
{
const struct rte_flow_item_eth *mask = item->mask;
const struct rte_flow_item_eth nic_mask = {
.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.ether_type = RTE_BE16(0xffff),
.has_vlan = ext_vlan_sup ? 1 : 0,
};
Expand Down Expand Up @@ -2933,12 +2933,10 @@ mlx5_flow_validate_item_ipv6(const struct rte_eth_dev *dev,
const struct rte_flow_item_ipv6 *spec = item->spec;
const struct rte_flow_item_ipv6 nic_mask = {
.hdr = {
.src_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.dst_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.src_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.dst_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.vtc_flow = RTE_BE32(0xffffffff),
.proto = 0xff,
},
Expand Down Expand Up @@ -3163,7 +3161,7 @@ mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
uint8_t vni[4];
} id = { .vlan_id = 0, };
const struct rte_flow_item_vxlan nic_mask = {
.hdr.vni = "\xff\xff\xff",
.hdr.vni = { 0xff, 0xff, 0xff },
.hdr.rsvd1 = 0xff,
};
const struct rte_flow_item_vxlan *valid_mask;
Expand Down Expand Up @@ -3249,7 +3247,7 @@ mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
} id = { .vlan_id = 0, };

struct rte_flow_item_vxlan_gpe nic_mask = {
.vni = "\xff\xff\xff",
.vni = { 0xff, 0xff, 0xff },
.protocol = 0xff,
.flags = 0xff,
};
Expand Down Expand Up @@ -3563,7 +3561,7 @@ mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
const struct rte_flow_item_geneve nic_mask = {
.ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
.vni = "\xff\xff\xff",
.vni = { 0xff, 0xff, 0xff },
.protocol = RTE_BE16(UINT16_MAX),
};

Expand Down
26 changes: 11 additions & 15 deletions drivers/net/mlx5/mlx5_flow_dv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7697,12 +7697,10 @@ const struct rte_flow_item_ipv4 nic_ipv4_mask = {

const struct rte_flow_item_ipv6 nic_ipv6_mask = {
.hdr = {
.src_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.dst_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.src_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.dst_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.vtc_flow = RTE_BE32(0xffffffff),
.proto = 0xff,
.hop_limits = 0xff,
Expand Down Expand Up @@ -9291,8 +9289,8 @@ flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
const struct rte_flow_item_eth *eth_m;
const struct rte_flow_item_eth *eth_v;
const struct rte_flow_item_eth nic_mask = {
.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.hdr.ether_type = RTE_BE16(0xffff),
.has_vlan = 0,
};
Expand Down Expand Up @@ -9549,12 +9547,10 @@ flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
const struct rte_flow_item_ipv6 *ipv6_v;
const struct rte_flow_item_ipv6 nic_mask = {
.hdr = {
.src_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.dst_addr =
"\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff",
.src_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.dst_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
.vtc_flow = RTE_BE32(0xffffffff),
.proto = 0xff,
.hop_limits = 0xff,
Expand Down Expand Up @@ -10064,7 +10060,7 @@ flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
int i;
struct mlx5_priv *priv = dev->data->dev_private;
const struct rte_flow_item_vxlan nic_mask = {
.hdr.vni = "\xff\xff\xff",
.hdr.vni = { 0xff, 0xff, 0xff },
.hdr.rsvd1 = 0xff,
};

Expand Down
Loading

0 comments on commit 20af899

Please sign in to comment.