@samitouri / QOSamiQemu / commits / fb96c3e818

net/af-xdp: fix type overflow

In for-loop in net_init_af_xdp, we do nc->queue_index = i, where is is int64_t for 0 to queues-1, and nc->queue_index is unsigned int. Also in parse_socket_fds, g_strv_length() returns guint which is equivalent to unsigned int. Let's simply use int type for queues, and update the check appropriately. It could be unsigned int, but in future commits we'll share with net/tap.c the common function which will return number of queues or negative error. So, let's simply use int for queues-related variables, that simplifies things. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Ben Chaney <bchaney@akamai.com> Signed-off-by: Jason Wang <jasowang@redhat.com>

Vladimir Sementsov-Ogievskiy committed Mar 18, 2026 at 14:31 UTC fb96c3e81838c3e64e649a71d2818fb1f489731b
1 file changed +9 -8
net/af-xdp.c
+9 -8
@@ -442,14 +442,14 @@ static NetClientInfo net_af_xdp_info = {
442 };
443
444 static int *parse_socket_fds(const char *sock_fds_str,
445 - int64_t n_expected, Error **errp)
445 + int n_expected, Error **errp)
446 {
447 gchar **substrings = g_strsplit(sock_fds_str, ":", -1);
448 - int64_t i, n_sock_fds = g_strv_length(substrings);
448 + int i, n_sock_fds = g_strv_length(substrings);
449 int *sock_fds = NULL;
450
451 if (n_sock_fds != n_expected) {
452 - error_setg(errp, "expected %"PRIi64" socket fds, got %"PRIi64,
452 + error_setg(errp, "expected %d socket fds, got %d",
453 n_expected, n_sock_fds);
454 goto exit;
455 }
@@ -484,7 +484,7 @@ int net_init_af_xdp(const Netdev *netdev,
484 unsigned int ifindex;
485 uint32_t prog_id = 0;
486 g_autofree int *sock_fds = NULL;
487 - int64_t i, queues;
487 + int i, queues;
488 Error *err = NULL;
489 AFXDPState *s;
490 bool inhibit;
@@ -496,13 +496,14 @@ int net_init_af_xdp(const Netdev *netdev,
496 return -1;
497 }
498
499 - queues = opts->has_queues ? opts->queues : 1;
500 - if (queues < 1) {
499 + if (opts->has_queues && (opts->queues < 1 || opts->queues > INT_MAX)) {
500 error_setg(errp, "invalid number of queues (%" PRIi64 ") for '%s'",
502 - queues, opts->ifname);
501 + opts->queues, opts->ifname);
502 return -1;
503 }
504
505 + queues = opts->has_queues ? opts->queues : 1;
506 +
507 inhibit = opts->has_inhibit && opts->inhibit;
508 if (inhibit && !opts->sock_fds && !opts->map_path) {
509 error_setg(errp, "'inhibit=on' requires 'sock-fds' or 'map-path'");
@@ -537,7 +538,7 @@ int net_init_af_xdp(const Netdev *netdev,
538
539 for (i = 0; i < queues; i++) {
540 nc = qemu_new_net_client(&net_af_xdp_info, peer, "af-xdp", name);
540 - qemu_set_info_str(nc, "af-xdp%"PRIi64" to %s", i, opts->ifname);
541 + qemu_set_info_str(nc, "af-xdp%d to %s", i, opts->ifname);
542 nc->queue_index = i;
543
544 if (!nc0) {