mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: netdev: use g_new0
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
0275b06a55
commit
1022e0eeb4
@ -1209,8 +1209,7 @@ virNetDevGetVirtualFunctions(const char *pfname,
|
|||||||
n_vfname, max_vfs) < 0)
|
n_vfname, max_vfs) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(*vfname, *n_vfname) < 0)
|
*vfname = g_new0(char *, *n_vfname);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < *n_vfname; i++) {
|
for (i = 0; i < *n_vfname; i++) {
|
||||||
g_autofree char *pciConfigAddr = NULL;
|
g_autofree char *pciConfigAddr = NULL;
|
||||||
@ -2039,8 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MACStr) {
|
if (MACStr) {
|
||||||
if (VIR_ALLOC(*MAC) < 0)
|
*MAC = g_new0(virMacAddr, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virMacAddrParse(MACStr, *MAC) < 0) {
|
if (virMacAddrParse(MACStr, *MAC) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -2051,8 +2049,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (adminMACStr) {
|
if (adminMACStr) {
|
||||||
if (VIR_ALLOC(*adminMAC) < 0)
|
*adminMAC = g_new0(virMacAddr, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virMacAddrParse(adminMACStr, *adminMAC) < 0) {
|
if (virMacAddrParse(adminMACStr, *adminMAC) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -2064,10 +2061,8 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
|
|||||||
|
|
||||||
if (vlanTag != -1) {
|
if (vlanTag != -1) {
|
||||||
/* construct a simple virNetDevVlan object with a single tag */
|
/* construct a simple virNetDevVlan object with a single tag */
|
||||||
if (VIR_ALLOC(*vlan) < 0)
|
*vlan = g_new0(virNetDevVlan, 1);
|
||||||
goto cleanup;
|
(*vlan)->tag = g_new0(unsigned int, 1);
|
||||||
if (VIR_ALLOC((*vlan)->tag) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
(*vlan)->nTags = 1;
|
(*vlan)->nTags = 1;
|
||||||
(*vlan)->tag[0] = vlanTag;
|
(*vlan)->tag[0] = vlanTag;
|
||||||
}
|
}
|
||||||
@ -2664,8 +2659,8 @@ static int virNetDevGetMcastList(const char *ifname,
|
|||||||
|
|
||||||
cur = buf;
|
cur = buf;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
if (!entry && VIR_ALLOC(entry) < 0)
|
if (!entry)
|
||||||
return -1;
|
entry = g_new0(virNetDevMcastEntry, 1);
|
||||||
|
|
||||||
next = strchr(cur, '\n');
|
next = strchr(cur, '\n');
|
||||||
if (next)
|
if (next)
|
||||||
@ -2709,8 +2704,7 @@ static int virNetDevGetMulticastTable(const char *ifname,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (mcast.nentries > 0) {
|
if (mcast.nentries > 0) {
|
||||||
if (VIR_ALLOC_N(filter->multicast.table, mcast.nentries) < 0)
|
filter->multicast.table = g_new0(virMacAddr, mcast.nentries);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < mcast.nentries; i++) {
|
for (i = 0; i < mcast.nentries; i++) {
|
||||||
virMacAddrSet(&filter->multicast.table[i],
|
virMacAddrSet(&filter->multicast.table[i],
|
||||||
@ -2733,8 +2727,7 @@ virNetDevRxFilterNew(void)
|
|||||||
{
|
{
|
||||||
virNetDevRxFilterPtr filter;
|
virNetDevRxFilterPtr filter;
|
||||||
|
|
||||||
if (VIR_ALLOC(filter) < 0)
|
filter = g_new0(virNetDevRxFilter, 1);
|
||||||
return NULL;
|
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,39 +442,25 @@ int
|
|||||||
virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
|
virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
|
||||||
const virNetDevBandwidth *src)
|
const virNetDevBandwidth *src)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
*dest = NULL;
|
*dest = NULL;
|
||||||
if (!src) {
|
if (!src) {
|
||||||
/* nothing to be copied */
|
/* nothing to be copied */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(*dest) < 0)
|
*dest = g_new0(virNetDevBandwidth, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (src->in) {
|
if (src->in) {
|
||||||
if (VIR_ALLOC((*dest)->in) < 0)
|
(*dest)->in = g_new0(virNetDevBandwidthRate, 1);
|
||||||
goto cleanup;
|
|
||||||
memcpy((*dest)->in, src->in, sizeof(*src->in));
|
memcpy((*dest)->in, src->in, sizeof(*src->in));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src->out) {
|
if (src->out) {
|
||||||
if (VIR_ALLOC((*dest)->out) < 0) {
|
(*dest)->out = g_new0(virNetDevBandwidthRate, 1);
|
||||||
VIR_FREE((*dest)->in);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
memcpy((*dest)->out, src->out, sizeof(*src->out));
|
memcpy((*dest)->out, src->out, sizeof(*src->out));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (ret < 0) {
|
|
||||||
virNetDevBandwidthFree(*dest);
|
|
||||||
*dest = NULL;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -180,8 +180,7 @@ virNetDevIPAddrAdd(const char *ifname,
|
|||||||
if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
|
if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
|
||||||
!(peer && VIR_SOCKET_ADDR_VALID(peer))) {
|
!(peer && VIR_SOCKET_ADDR_VALID(peer))) {
|
||||||
/* compute a broadcast address if this is IPv4 */
|
/* compute a broadcast address if this is IPv4 */
|
||||||
if (VIR_ALLOC(broadcast) < 0)
|
broadcast = g_new0(virSocketAddr, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
|
if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
@ -726,11 +726,9 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
|
|||||||
virNetlinkCallbackDataPtr calld = NULL;
|
virNetlinkCallbackDataPtr calld = NULL;
|
||||||
|
|
||||||
if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
|
if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
|
||||||
if (VIR_ALLOC(calld) < 0)
|
calld = g_new0(struct virNetlinkCallbackData, 1);
|
||||||
goto error;
|
|
||||||
calld->cr_ifname = g_strdup(ifname);
|
calld->cr_ifname = g_strdup(ifname);
|
||||||
if (VIR_ALLOC(calld->virtPortProfile) < 0)
|
calld->virtPortProfile = g_new0(virNetDevVPortProfile, 1);
|
||||||
goto error;
|
|
||||||
memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
|
memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
|
||||||
virMacAddrSet(&calld->macaddress, macaddress);
|
virMacAddrSet(&calld->macaddress, macaddress);
|
||||||
calld->linkdev = g_strdup(linkdev);
|
calld->linkdev = g_strdup(linkdev);
|
||||||
|
@ -165,8 +165,7 @@ virNetDevTapGetRealDeviceName(char *ifname G_GNUC_UNUSED)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret, len) < 0)
|
ret = g_new0(char, len);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (sysctl(name, 6, ret, &len, 0, 0) < 0) {
|
if (sysctl(name, 6, ret, &len, 0, 0) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
|
@ -83,9 +83,7 @@ virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlan *src)
|
|||||||
if (!src || src->nTags == 0)
|
if (!src || src->nTags == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(dst->tag, src->nTags) < 0)
|
dst->tag = g_new0(unsigned int, src->nTags);
|
||||||
return -1;
|
|
||||||
|
|
||||||
dst->trunk = src->trunk;
|
dst->trunk = src->trunk;
|
||||||
dst->nTags = src->nTags;
|
dst->nTags = src->nTags;
|
||||||
dst->nativeMode = src->nativeMode;
|
dst->nativeMode = src->nativeMode;
|
||||||
|
@ -129,9 +129,7 @@ int virNetDevVPortProfileCopy(virNetDevVPortProfilePtr *dst, const virNetDevVPor
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(*dst) < 0)
|
*dst = g_new0(virNetDevVPortProfile, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
memcpy(*dst, src, sizeof(*src));
|
memcpy(*dst, src, sizeof(*src));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -431,8 +429,7 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfilePtr *result,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* at least one of the source profiles is non-empty */
|
/* at least one of the source profiles is non-empty */
|
||||||
if (VIR_ALLOC(*result) < 0)
|
*result = g_new0(virNetDevVPortProfile, 1);
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* start with the interface's profile. There are no pointers in a
|
/* start with the interface's profile. There are no pointers in a
|
||||||
* virtualPortProfile, so a shallow copy is sufficient.
|
* virtualPortProfile, so a shallow copy is sufficient.
|
||||||
|
Loading…
Reference in New Issue
Block a user