Re: [PATCH] virDomainHostdevDefNew: update users not to check return value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/27/25 7:46 AM, Roman Bogorodskiy wrote:
virDomainHostdevDefNew() has been using g_new0() for a while now. As it
calls abort() on OOM, it's not necessary to check whether
the return value is NULL.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@xxxxxxxxx>

Reviewed-by: Laine Stump <laine@xxxxxxxxxx>

(I had to check to make sure this wasn't in the 17 patch series I sent in earlier this month (but haven't pushed yet) - turns out I had found/changed virDomainHostdevDef*Insert*() to return void. (I'll be pushing all of those as soon as this release is done - they didn't get reviewed until after RC1 was tagged, and they weren't bug fixes...)

---
  src/conf/domain_conf.c |  3 +--
  src/libxl/xen_common.c |  4 +---
  src/libxl/xen_xl.c     |  4 +---
  src/lxc/lxc_native.c   |  4 ----
  src/vbox/vbox_common.c | 12 +-----------
  5 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5630a469be..d4ce85b3a1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13316,8 +13316,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt,
ctxt->node = node; - if (!(def = virDomainHostdevDefNew()))
-        goto error;
+    def = virDomainHostdevDefNew();
if (virXMLPropEnumDefault(node, "mode", virDomainHostdevModeTypeFromString,
                                VIR_XML_PROP_NONE,
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index b7ec552631..cbcdbf5a00 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -445,9 +445,7 @@ xenParsePCI(char *entry)
          }
      }
- if (!(hostdev = virDomainHostdevDefNew()))
-       return NULL;
-
+    hostdev = virDomainHostdevDefNew();
      hostdev->managed = false;
      hostdev->writeFiltering = filtered;
      hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 53f6871efc..482b151666 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -924,9 +924,7 @@ xenParseXLUSB(virConf *conf, virDomainDef *def)
                  key = nextkey;
              }
- if (!(hostdev = virDomainHostdevDefNew()))
-               return -1;
-
+            hostdev = virDomainHostdevDefNew();
              hostdev->managed = false;
              hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB;
              hostdev->source.subsys.u.usb.bus = busNum;
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index c0011e0600..7700804429 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -377,10 +377,6 @@ static virDomainHostdevDef *
  lxcCreateHostdevDef(const char *data)
  {
      virDomainHostdevDef *hostdev = virDomainHostdevDefNew();
-
-    if (!hostdev)
-        return NULL;
-
      hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES;
      hostdev->source.caps.type = VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET;
      hostdev->source.caps.u.net.ifname = g_strdup(data);
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index de3c9989a5..2121d7e2d1 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3087,11 +3087,8 @@ vboxHostDeviceGetXMLDesc(struct _vboxDriver *data, virDomainDef *def, IMachine *
      /* Alloc mem needed for the filters now */
      def->hostdevs = g_new0(virDomainHostdevDef *, def->nhostdevs);
- for (i = 0; i < def->nhostdevs; i++) {
+    for (i = 0; i < def->nhostdevs; i++)
          def->hostdevs[i] = virDomainHostdevDefNew();
-        if (!def->hostdevs[i])
-            goto release_hostdevs;
-    }
for (i = 0; i < deviceFilters.count; i++) {
          PRBool active = PR_FALSE;
@@ -3138,13 +3135,6 @@ vboxHostDeviceGetXMLDesc(struct _vboxDriver *data, virDomainDef *def, IMachine *
      gVBoxAPI.UArray.vboxArrayRelease(&deviceFilters);
      VBOX_RELEASE(USBCommon);
      return;
-
- release_hostdevs:
-    for (i = 0; i < def->nhostdevs; i++)
-        virDomainHostdevDefFree(def->hostdevs[i]);
-    VIR_FREE(def->hostdevs);
-
-    goto release_filters;
  }



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux