Skip to contentSkip to conversation

vdpa: Make ncs autofree

PATCH Applied Eugenio Pérez 5 participants 6 messages Feb 14, 2022 – Feb 22, 2022 Networking

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 vdpa: Make ncs autofree

Simplifying memory management.

---
 net/vhost-vdpa.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +2 -3
index 4125d13118..4befba5cc7 100644
@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
 {
     const NetdevVhostVDPAOptions *opts;
     int vdpa_device_fd;
-    NetClientState **ncs, *nc;
+    g_autofree NetClientState **ncs = NULL;
+    NetClientState *nc;
     int queue_pairs, i, has_cvq = 0;
 
     assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
             goto err;
     }
 
-    g_free(ncs);
     return 0;
 
 err:
@@ -310,7 +310,6 @@ err:
         qemu_del_net_client(ncs[0]);
     }
     qemu_close(vdpa_device_fd);
-    g_free(ncs);
 
     return -1;
 }
Signature · 1 line
2.27.0
Acked-by on v1 1/1
#3 lore raw
In reply to Eugenio Pérez
Quoted 4 lines · Eugenio Pérez

Simplifying memory management.

Quoted 37 lines
---
 net/vhost-vdpa.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +2 -4
index 4125d13118..4befba5cc7 100644
@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
 {
     const NetdevVhostVDPAOptions *opts;
     int vdpa_device_fd;
-    NetClientState **ncs, *nc;
+    g_autofree NetClientState **ncs = NULL;
+    NetClientState *nc;
     int queue_pairs, i, has_cvq = 0;
 
     assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
             goto err;
     }
 
-    g_free(ncs);
     return 0;
 
 err:
@@ -310,7 +310,6 @@ err:
         qemu_del_net_client(ncs[0]);
     }
     qemu_close(vdpa_device_fd);
-    g_free(ncs);
 
     return -1;
 }
--

2.27.0

Reviewed-by on v1 1/1
#4 lore raw
In reply to Eugenio Pérez
Quoted 6 lines · Eugenio Pérez

Simplifying memory management.

---
net/vhost-vdpa.c | 5 ++---

1 file changed, 2 insertions(+), 3 deletions(-)
Quoted 35 lines
net/vhost-vdpa.c +2 -2
index 4125d13118..4befba5cc7 100644
@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
 {
    const NetdevVhostVDPAOptions *opts;
    int vdpa_device_fd;
-    NetClientState **ncs, *nc;
+    g_autofree NetClientState **ncs = NULL;
+    NetClientState *nc;
    int queue_pairs, i, has_cvq = 0;
 
    assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
            goto err;
    }
 
-    g_free(ncs);
    return 0;
 

err:

net/vhost-vdpa.c +0 -1
@@ -310,7 +310,6 @@ err:
        qemu_del_net_client(ncs[0]);
    }
    qemu_close(vdpa_device_fd);
-    g_free(ncs);
 
    return -1;
 }
Signature · 1 line
2.27.0
#5 lore raw
In reply to Eugenio Pérez

Le 14/02/2022 à 20:34, Eugenio Pérez a écrit :

Quoted 30 lines

Simplifying memory management.

---
  net/vhost-vdpa.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +2 -2
index 4125d13118..4befba5cc7 100644
@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
  {
      const NetdevVhostVDPAOptions *opts;
      int vdpa_device_fd;
-    NetClientState **ncs, *nc;
+    g_autofree NetClientState **ncs = NULL;
+    NetClientState *nc;
      int queue_pairs, i, has_cvq = 0;
 
      assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
              goto err;
      }
 
-    g_free(ncs);
      return 0;
 
  err:

net/vhost-vdpa.c err: · line 315

Quoted 7 lines
net/vhost-vdpa.c +0 -1
@@ -310,7 +310,6 @@ err:
          qemu_del_net_client(ncs[0]);
      }
      qemu_close(vdpa_device_fd);
-    g_free(ncs);
 
      return -1;
  }

Applied to my trivial-patches branch.

Thanks,
Laurent