On 30.01.26 02:15, Ilya Maximets wrote:
On 1/29/26 10:32 PM, Vladimir Sementsov-Ogievskiy wrote:
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 unsigned int type for queues, and update
the check appropriately.

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
---
  net/af-xdp.c | 17 +++++++++--------
  1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/net/af-xdp.c b/net/af-xdp.c
index 14f302ea21..bb7a7d8e33 100644
--- a/net/af-xdp.c
+++ b/net/af-xdp.c
@@ -442,14 +442,14 @@ static NetClientInfo net_af_xdp_info = {
  };
static int *parse_socket_fds(const char *sock_fds_str,
-                             int64_t n_expected, Error **errp)
+                             unsigned n_expected, Error **errp)
  {
      gchar **substrings = g_strsplit(sock_fds_str, ":", -1);
-    int64_t i, n_sock_fds = g_strv_length(substrings);
+    unsigned i, n_sock_fds = g_strv_length(substrings);
      int *sock_fds = NULL;
if (n_sock_fds != n_expected) {
-        error_setg(errp, "expected %"PRIi64" socket fds, got %"PRIi64,
+        error_setg(errp, "expected %u socket fds, got %u",
                     n_expected, n_sock_fds);
          goto exit;
      }
@@ -484,7 +484,7 @@ int net_init_af_xdp(const Netdev *netdev,
      unsigned int ifindex;
      uint32_t prog_id = 0;
      g_autofree int *sock_fds = NULL;
-    int64_t i, queues;
+    unsigned i, queues;
      Error *err = NULL;
      AFXDPState *s;
      bool inhibit;
@@ -496,13 +496,14 @@ int net_init_af_xdp(const Netdev *netdev,
          return -1;
      }
- queues = opts->has_queues ? opts->queues : 1;
-    if (queues < 1) {
+    if (opts->has_queues && (opts->queues < 0 || opts->queues > UINT_MAX)) {

Not a full review, but this changes the logic.  Zero is not a valid number
of queues.

Oops, good shot, thanks for looking. Will fix.


          error_setg(errp, "invalid number of queues (%" PRIi64 ") for '%s'",
-                   queues, opts->ifname);
+                   opts->queues, opts->ifname);
          return -1;
      }
+ queues = opts->has_queues ? opts->queues : 1;
+
      inhibit = opts->has_inhibit && opts->inhibit;
      if (inhibit && !opts->sock_fds && !opts->map_path) {
          error_setg(errp, "'inhibit=on' requires 'sock-fds' or 'map-path'");
@@ -537,7 +538,7 @@ int net_init_af_xdp(const Netdev *netdev,
for (i = 0; i < queues; i++) {
          nc = qemu_new_net_client(&net_af_xdp_info, peer, "af-xdp", name);
-        qemu_set_info_str(nc, "af-xdp%"PRIi64" to %s", i, opts->ifname);
+        qemu_set_info_str(nc, "af-xdp%u to %s", i, opts->ifname);
          nc->queue_index = i;
if (!nc0) {



--
Best regards,
Vladimir

Reply via email to