diff mbox series

[1/1] vdpa: Make ncs autofree

Message ID 20220214193415.1606752-2-eperezma@redhat.com
State New
Headers show
Series vdpa: Make ncs autofree | expand

Commit Message

Eugenio Perez Martin Feb. 14, 2022, 7:34 p.m. UTC
Simplifying memory management.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 net/vhost-vdpa.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Jason Wang Feb. 15, 2022, 3:04 a.m. UTC | #1
On Tue, Feb 15, 2022 at 3:34 AM Eugenio Pérez <eperezma@redhat.com> wrote:
>
> Simplifying memory management.
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.com>

> ---
>  net/vhost-vdpa.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 4125d13118..4befba5cc7 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -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
>
Stefano Garzarella Feb. 16, 2022, 8:41 a.m. UTC | #2
On Mon, Feb 14, 2022 at 08:34:15PM +0100, Eugenio Pérez wrote:
>Simplifying memory management.
>
>Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
>---
> net/vhost-vdpa.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>index 4125d13118..4befba5cc7 100644
>--- a/net/vhost-vdpa.c
>+++ b/net/vhost-vdpa.c
>@@ -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
>
>
Laurent Vivier Feb. 22, 2022, 12:34 a.m. UTC | #3
Le 14/02/2022 à 20:34, Eugenio Pérez a écrit :
> Simplifying memory management.
> 
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>   net/vhost-vdpa.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 4125d13118..4befba5cc7 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -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;
>   }

Applied to my trivial-patches branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 4125d13118..4befba5cc7 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -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;
 }