From 98906dbceed6e232da786ddb52bdaa6b4ca36142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 23 Sep 2020 20:44:23 +0200 Subject: [PATCH] interface: use g_new0 instead of VIR_ALLOC* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ján Tomko Reviewed-by: Peter Krempa --- src/interface/interface_backend_netcf.c | 16 ++++++---------- src/interface/interface_backend_udev.c | 22 ++++++++-------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index f30829442d..df04484c59 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -247,8 +247,7 @@ netcfGetMinimalDefForDevice(struct netcf_if *iface) virInterfaceDef *def; /* Allocate our interface definition structure */ - if (VIR_ALLOC(def) < 0) - return NULL; + def = g_new0(virInterfaceDef, 1); def->name = g_strdup(ncf_if_name(iface)); def->mac = g_strdup(ncf_if_mac_string(iface)); @@ -375,8 +374,7 @@ static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC_N(names, count) < 0) - goto cleanup; + names = g_new0(char *, count); if ((count = ncf_list_interfaces(driver->netcf, count, names, status)) < 0) { const char *errmsg, *details; @@ -465,8 +463,7 @@ static int netcfConnectListInterfacesImpl(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC_N(allnames, count) < 0) - goto cleanup; + allnames = g_new0(char *, count); if ((count = ncf_list_interfaces(driver->netcf, count, allnames, status)) < 0) { const char *errmsg, *details; @@ -651,8 +648,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC_N(names, count) < 0) - goto cleanup; + names = g_new0(char *, count); if ((count = ncf_list_interfaces(driver->netcf, count, names, ncf_flags)) < 0) { @@ -666,8 +662,8 @@ netcfConnectListAllInterfaces(virConnectPtr conn, goto cleanup; } - if (ifaces && VIR_ALLOC_N(tmp_iface_objs, count + 1) < 0) - goto cleanup; + if (ifaces) + tmp_iface_objs = g_new0(virInterfacePtr, count + 1); for (i = 0; i < count; i++) { virInterfaceDefPtr def; diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 670de48d52..4e0a80765c 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -86,8 +86,7 @@ udevGetMinimalDefForDevice(struct udev_device *dev) virInterfaceDef *def; /* Allocate our interface definition structure */ - if (VIR_ALLOC(def) < 0) - return NULL; + def = g_new0(virInterfaceDef, 1); def->name = g_strdup(udev_device_get_sysname(dev)); def->mac = g_strdup(udev_device_get_sysattr_value(dev, "address")); @@ -352,10 +351,8 @@ udevConnectListAllInterfaces(virConnectPtr conn, } /* If we're asked for the ifaces then alloc up memory */ - if (ifaces && VIR_ALLOC_N(ifaces_list, count + 1) < 0) { - ret = -1; - goto cleanup; - } + if (ifaces) + ifaces_list = g_new0(virInterfacePtr, count + 1); /* Get a list we can walk */ devices = udev_enumerate_get_list_entry(enumerate); @@ -758,8 +755,8 @@ udevGetIfaceDefBond(struct udev *udev, } /* Allocate our list of slave devices */ - if (VIR_ALLOC_N(ifacedef->data.bond.itf, slave_count) < 0) - goto error; + ifacedef->data.bond.itf = g_new0(struct _virInterfaceDef *, + slave_count); ifacedef->data.bond.nbItf = slave_count; for (i = 0; i < slave_count; i++) { @@ -873,8 +870,7 @@ udevGetIfaceDefBridge(struct udev *udev, } /* Allocate our list of member devices */ - if (VIR_ALLOC_N(ifacedef->data.bridge.itf, member_count) < 0) - goto error; + ifacedef->data.bridge.itf = g_new0(struct _virInterfaceDef *, member_count); ifacedef->data.bridge.nbItf = member_count; /* Get the interface definitions for each member of the bridge */ @@ -976,8 +972,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) const char *devtype; /* Allocate our interface definition structure */ - if (VIR_ALLOC(ifacedef) < 0) - return NULL; + ifacedef = g_new0(virInterfaceDef, 1); /* Clear our structure and set safe defaults */ ifacedef->startmode = VIR_INTERFACE_START_UNSPECIFIED; @@ -1158,8 +1153,7 @@ udevStateInitialize(bool privileged, return -1; } - if (VIR_ALLOC(driver) < 0) - goto cleanup; + driver = g_new0(struct udev_iface_driver, 1); driver->lockFD = -1;