[PATCH 05/75] conf: Drop virAsprintf() and virAsprintfQuiet() retval checking

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

 



These functions can't fail really. Drop checking of their retval
then.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/capabilities.c          |  3 +-
 src/conf/domain_addr.c           |  8 ++---
 src/conf/domain_audit.c          | 60 ++++++++++++--------------------
 src/conf/domain_conf.c           | 48 ++++++++++---------------
 src/conf/moment_conf.c           |  5 ++-
 src/conf/network_conf.c          |  2 +-
 src/conf/node_device_util.c      |  3 +-
 src/conf/snapshot_conf.c         |  5 +--
 src/conf/storage_conf.c          |  6 ++--
 src/conf/virchrdev.c             |  7 ++--
 src/conf/virnetworkobj.c         |  8 ++---
 src/conf/virnetworkportdef.c     |  2 +-
 src/conf/virnwfilterbindingobj.c |  2 +-
 src/conf/virstorageobj.c         |  3 +-
 14 files changed, 61 insertions(+), 101 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 697d464fe9..b93b6ff451 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1869,8 +1869,7 @@ virCapabilitiesInitCaches(virCapsPtr caps)
         int rv = -1;
 
         VIR_FREE(path);
-        if (virAsprintf(&path, "%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos) < 0)
-            goto cleanup;
+        virAsprintf(&path, "%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos);
 
         VIR_DIR_CLOSE(dirp);
 
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index dd8e04576a..9cc098a025 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1388,10 +1388,10 @@ virDomainCCWAddressAsString(virDomainDeviceCCWAddressPtr addr)
 {
     char *addrstr = NULL;
 
-    ignore_value(virAsprintf(&addrstr, "%x.%x.%04x",
-                             addr->cssid,
-                             addr->ssid,
-                             addr->devno));
+    virAsprintf(&addrstr, "%x.%x.%04x",
+                addr->cssid,
+                addr->ssid,
+                addr->devno);
     return addrstr;
 }
 
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 2ae39e3698..98b80e5bec 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -53,7 +53,7 @@ virDomainAuditGetRdev(const char *path)
         (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) {
         int maj = major(sb.st_rdev);
         int min = minor(sb.st_rdev);
-        ignore_value(virAsprintfQuiet(&ret, "%02X:%02X", maj, min));
+        virAsprintfQuiet(&ret, "%02X:%02X", maj, min);
     }
     return ret;
 }
@@ -101,11 +101,8 @@ virDomainAuditGenericDev(virDomainObjPtr vm,
     if (!newsrcpath && !oldsrcpath)
         return;
 
-    if (virAsprintfQuiet(&newdev, "new-%s", type) < 0)
-        goto no_memory;
-
-    if (virAsprintfQuiet(&olddev, "old-%s", type) < 0)
-        goto no_memory;
+    virAsprintfQuiet(&newdev, "new-%s", type);
+    virAsprintfQuiet(&olddev, "old-%s", type);
 
     virUUIDFormat(vm->def->uuid, uuidstr);
 
@@ -376,22 +373,15 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
     case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
         switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-            if (virAsprintfQuiet(&address,
-                                 VIR_PCI_DEVICE_ADDRESS_FMT,
-                                 pcisrc->addr.domain,
-                                 pcisrc->addr.bus,
-                                 pcisrc->addr.slot,
-                                 pcisrc->addr.function) < 0) {
-                VIR_WARN("OOM while encoding audit message");
-                goto cleanup;
-            }
+            virAsprintfQuiet(&address,
+                             VIR_PCI_DEVICE_ADDRESS_FMT,
+                             pcisrc->addr.domain,
+                             pcisrc->addr.bus,
+                             pcisrc->addr.slot,
+                             pcisrc->addr.function);
             break;
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
-            if (virAsprintfQuiet(&address, "%.3d.%.3d",
-                                 usbsrc->bus, usbsrc->device) < 0) {
-                VIR_WARN("OOM while encoding audit message");
-                goto cleanup;
-            }
+            virAsprintfQuiet(&address, "%.3d.%.3d", usbsrc->bus, usbsrc->device);
             break;
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
             if (scsisrc->protocol ==
@@ -403,13 +393,10 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
             } else {
                 virDomainHostdevSubsysSCSIHostPtr scsihostsrc =
                     &scsisrc->u.host;
-                if (virAsprintfQuiet(&address, "%s:%u:%u:%llu",
-                                     scsihostsrc->adapter, scsihostsrc->bus,
-                                     scsihostsrc->target,
-                                     scsihostsrc->unit) < 0) {
-                    VIR_WARN("OOM while encoding audit message");
-                    goto cleanup;
-                }
+                virAsprintfQuiet(&address, "%s:%u:%u:%llu",
+                                 scsihostsrc->adapter, scsihostsrc->bus,
+                                 scsihostsrc->target,
+                                 scsihostsrc->unit);
             }
             break;
         }
@@ -661,11 +648,8 @@ virDomainAuditCgroupMajor(virDomainObjPtr vm, virCgroupPtr cgroup,
 {
     char *extra;
 
-    if (virAsprintfQuiet(&extra, "major category=%s maj=%02X acl=%s",
-                         name, maj, perms) < 0) {
-        VIR_WARN("OOM while encoding audit message");
-        return;
-    }
+    virAsprintfQuiet(&extra, "major category=%s maj=%02X acl=%s",
+                     name, maj, perms);
 
     virDomainAuditCgroup(vm, cgroup, reason, extra, success);
 
@@ -699,13 +683,14 @@ virDomainAuditCgroupPath(virDomainObjPtr vm, virCgroupPtr cgroup,
 
     rdev = virDomainAuditGetRdev(path);
 
-    if (!(detail = virAuditEncode("path", path)) ||
-        virAsprintfQuiet(&extra, "path %s rdev=%s acl=%s",
-                         detail, VIR_AUDIT_STR(rdev), perms) < 0) {
+    if (!(detail = virAuditEncode("path", path))) {
         VIR_WARN("OOM while encoding audit message");
         goto cleanup;
     }
 
+    virAsprintfQuiet(&extra, "path %s rdev=%s acl=%s",
+                     detail, VIR_AUDIT_STR(rdev), perms);
+
     virDomainAuditCgroup(vm, cgroup, reason, extra, rc == 0);
 
  cleanup:
@@ -936,12 +921,13 @@ virDomainAuditShmem(virDomainObjPtr vm,
 
     virUUIDFormat(vm->def->uuid, uuidstr);
 
-    if (!vmname ||
-        virAsprintfQuiet(&shmpath, "/dev/shm/%s", def->name) < 0) {
+    if (!vmname) {
         VIR_WARN("OOM while encoding audit message");
         goto cleanup;
     }
 
+    virAsprintfQuiet(&shmpath, "/dev/shm/%s", def->name);
+
     if (!virt) {
         VIR_WARN("Unexpected virt type %d while encoding audit message",
                  vm->def->virtType);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 80e19a15df..5674032b30 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4911,8 +4911,7 @@ virDomainPostParseCheckISCSIPath(char **srcpath)
     if (strchr(*srcpath, '/'))
         return 0;
 
-    if (virAsprintf(&path, "%s/0", *srcpath) < 0)
-        return -1;
+    virAsprintf(&path, "%s/0", *srcpath);
     VIR_FREE(*srcpath);
     *srcpath = g_steal_pointer(&path);
     return 0;
@@ -5573,8 +5572,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def G_GNUC_UNUSED,
          */
         return 0;
     }
-    if (virAsprintf(&order, "%u", info->bootIndex) < 0)
-        return -1;
+    virAsprintf(&order, "%u", info->bootIndex);
 
     if (virHashLookup(bootHash, order)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -10122,9 +10120,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 
     if (!target && !(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) {
         if (def->src->srcpool) {
-            if (virAsprintf(&tmp, "pool = '%s', volume = '%s'",
-                def->src->srcpool->pool, def->src->srcpool->volume) < 0)
-                goto error;
+            virAsprintf(&tmp, "pool = '%s', volume = '%s'",
+                        def->src->srcpool->pool, def->src->srcpool->volume);
 
             virReportError(VIR_ERR_NO_TARGET, "%s", tmp);
             VIR_FREE(tmp);
@@ -10321,8 +10318,7 @@ virDomainParseScaledValue(const char *xpath,
     g_autofree char *bytes_str = NULL;
 
     *val = 0;
-    if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0)
-        return -1;
+    virAsprintf(&xpath_full, "string(%s)", xpath);
 
     bytes_str = virXPathString(xpath_full, ctxt);
     if (!bytes_str) {
@@ -10342,11 +10338,10 @@ virDomainParseScaledValue(const char *xpath,
         return -1;
     }
 
-    if ((units_xpath &&
-         virAsprintf(&xpath_full, "string(%s)", units_xpath) < 0) ||
-        (!units_xpath &&
-         virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0))
-        return -1;
+    if (units_xpath)
+         virAsprintf(&xpath_full, "string(%s)", units_xpath);
+    else
+         virAsprintf(&xpath_full, "string(%s/@unit)", xpath);
     unit = virXPathString(xpath_full, ctxt);
 
     if (virScaleInteger(&bytes, unit, scale, max) < 0)
@@ -19375,8 +19370,7 @@ virDomainResctrlMonDefParse(virDomainDefPtr def,
             if (!(tmp = virBitmapFormat(domresmon->vcpus)))
                 goto cleanup;
 
-            if (virAsprintf(&id, "vcpus_%s", tmp) < 0)
-                goto cleanup;
+            virAsprintf(&id, "vcpus_%s", tmp);
         }
 
         virResctrlMonitorSetAlloc(domresmon->instance, resctrl->alloc);
@@ -19426,8 +19420,7 @@ virDomainResctrlNew(xmlNodePtr node,
          * directory, so it's nice to have it named appropriately.  For now it's
          * 'vcpus_...' but it's designed in order for it to be changeable in the
          * future (it's part of the status XML). */
-        if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0)
-            goto cleanup;
+        virAsprintf(&alloc_id, "vcpus_%s", vcpus_str);
     }
 
     if (virResctrlAllocSetID(alloc, alloc_id) < 0)
@@ -24028,10 +24021,8 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf,
     virBufferAsprintf(attrBuf, " protocol='%s'",
                       virStorageNetProtocolTypeToString(src->protocol));
 
-    if (src->volume) {
-        if (virAsprintf(&path, "%s/%s", src->volume, src->path) < 0)
-            return -1;
-    }
+    if (src->volume)
+        virAsprintf(&path, "%s/%s", src->volume, src->path);
 
     virBufferEscapeString(attrBuf, " name='%s'", path ? path : src->path);
 
@@ -29198,7 +29189,7 @@ char
 {
     char *ret;
 
-    ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+    virAsprintf(&ret, "%s/%s.xml", dir, name);
     return ret;
 }
 
@@ -30348,8 +30339,7 @@ virDomainDefGetShortName(const virDomainDef *def)
     len = mbstowcs(NULL, def->name, 0);
     if ((len == (size_t) -1 && errno == EILSEQ) ||
         len == strlen(def->name)) {
-        ignore_value(virAsprintf(&ret, "%d-%.*s", def->id,
-                                 VIR_DOMAIN_SHORT_NAME_MAX, def->name));
+        virAsprintf(&ret, "%d-%.*s", def->id, VIR_DOMAIN_SHORT_NAME_MAX, def->name);
         return ret;
     }
 
@@ -30385,7 +30375,7 @@ virDomainDefGetShortName(const virDomainDef *def)
         return NULL;
     }
 
-    ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname));
+    virAsprintf(&ret, "%d-%s", def->id, shortname);
     return ret;
 }
 
@@ -31191,10 +31181,8 @@ virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
     }
 
     /* iscsi pool has only one source device path */
-    if (virAsprintf(&def->src->path, "%s/%s",
-                    pooldef->source.devices[0].path,
-                    tokens[3]) < 0)
-        goto cleanup;
+    virAsprintf(&def->src->path, "%s/%s", pooldef->source.devices[0].path,
+                tokens[3]);
 
     /* Storage pool have not supported these 2 attributes yet,
      * use the defaults.
diff --git a/src/conf/moment_conf.c b/src/conf/moment_conf.c
index f54a44b33e..f11ba76dd4 100644
--- a/src/conf/moment_conf.c
+++ b/src/conf/moment_conf.c
@@ -77,9 +77,8 @@ virDomainMomentDefPostParse(virDomainMomentDefPtr def)
 
     gettimeofday(&tv, NULL);
 
-    if (!def->name &&
-        virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0)
-        return -1;
+    if (!def->name)
+        virAsprintf(&def->name, "%lld", (long long)tv.tv_sec);
 
     def->creationTime = tv.tv_sec;
     return 0;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 7f8e43b25c..8d2bef439b 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -2756,7 +2756,7 @@ virNetworkConfigFile(const char *dir,
 {
     char *ret = NULL;
 
-    ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+    virAsprintf(&ret, "%s/%s.xml", dir, name);
     return ret;
 }
 
diff --git a/src/conf/node_device_util.c b/src/conf/node_device_util.c
index 2728b8a510..6c7b73384f 100644
--- a/src/conf/node_device_util.c
+++ b/src/conf/node_device_util.c
@@ -182,8 +182,7 @@ virNodeDeviceDeleteVport(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
-        goto cleanup;
+    virAsprintf(&scsi_host_name, "scsi_%s", name);
 
     /* If at startup time we provided a parent, then use that to
      * get the parent_host value; otherwise, we have to determine
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index f9fbca3c07..2c53e9d764 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -618,10 +618,7 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDefPtr def)
         if ((tmp = strrchr(tmppath, '.')) && !strchr(tmp, '/'))
             *tmp = '\0';
 
-        if (virAsprintf(&disk->src->path, "%s.%s", tmppath, def->parent.name) < 0) {
-            VIR_FREE(tmppath);
-            return -1;
-        }
+        virAsprintf(&disk->src->path, "%s.%s", tmppath, def->parent.name);
 
         VIR_FREE(tmppath);
 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index f212eefe25..ec9db7edb0 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -953,11 +953,9 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
      * path and permissions */
     if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
         if (def->type == VIR_STORAGE_POOL_LOGICAL) {
-            if (virAsprintf(&target_path, "/dev/%s", def->source.name) < 0)
-                return NULL;
+            virAsprintf(&target_path, "/dev/%s", def->source.name);
         } else if (def->type == VIR_STORAGE_POOL_ZFS) {
-            if (virAsprintf(&target_path, "/dev/zvol/%s", def->source.name) < 0)
-                return NULL;
+            virAsprintf(&target_path, "/dev/zvol/%s", def->source.name);
         } else {
             target_path = virXPathString("string(./target/path)", ctxt);
             if (!target_path) {
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index 1d02a4ad66..204813c5fd 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -88,12 +88,10 @@ static char *virChrdevLockFilePath(const char *dev)
         ++p;
     }
 
-    if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0)
-        goto cleanup;
+    virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename);
 
     sanitizedPath = virFileSanitizePath(path);
 
- cleanup:
     VIR_FREE(path);
     VIR_FREE(devCopy);
 
@@ -135,8 +133,7 @@ static int virChrdevLockFileCreate(const char *dev)
 
     /* ensure correct format according to filesystem hierarchy standard */
     /* http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLOCKLOCKFILES */
-    if (virAsprintf(&pidStr, "%10lld\n", (long long) getpid()) < 0)
-        goto cleanup;
+    virAsprintf(&pidStr, "%10lld\n", (long long)getpid());
 
     /* create the lock file */
     if ((lockfd = open(path, O_WRONLY | O_CREAT | O_EXCL, 00644)) < 0) {
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index e7017bffa9..852c0a5e43 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1627,7 +1627,7 @@ virNetworkObjGetPortStatusDir(virNetworkObjPtr net,
                               const char *stateDir)
 {
     char *ret;
-    ignore_value(virAsprintf(&ret, "%s/%s/ports", stateDir, net->def->name));
+    virAsprintf(&ret, "%s/%s/ports", stateDir, net->def->name);
     return ret;
 }
 
@@ -1739,8 +1739,7 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
         if (!virStringStripSuffix(de->d_name, ".xml"))
             continue;
 
-        if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0)
-            goto cleanup;
+        virAsprintf(&file, "%s/%s.xml", dir, de->d_name);
 
         if (unlink(file) < 0 && errno != ENOENT)
             VIR_WARN("Unable to delete %s", file);
@@ -1900,8 +1899,7 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
         if (!virStringStripSuffix(de->d_name, ".xml"))
             continue;
 
-        if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0)
-            goto cleanup;
+        virAsprintf(&file, "%s/%s.xml", dir, de->d_name);
 
         portdef = virNetworkPortDefParseFile(file);
         VIR_FREE(file);
diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index 459384611c..09bd25a9ef 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -428,7 +428,7 @@ virNetworkPortDefConfigFile(const char *dir,
 {
     char *ret = NULL;
 
-    ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+    virAsprintf(&ret, "%s/%s.xml", dir, name);
     return ret;
 }
 
diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c
index 48d53fafb1..0066faadd8 100644
--- a/src/conf/virnwfilterbindingobj.c
+++ b/src/conf/virnwfilterbindingobj.c
@@ -142,7 +142,7 @@ virNWFilterBindingObjConfigFile(const char *dir,
 {
     char *ret;
 
-    ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name));
+    virAsprintf(&ret, "%s/%s.xml", dir, name);
     return ret;
 }
 
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index a4fd330663..15c5f2624d 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1229,8 +1229,7 @@ matchFCHostToSCSIHost(virStorageAdapterFCHostPtr fchost,
          */
         if (!fchost->parent &&
             (conn = virGetConnectNodeDev())) {
-            if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
-                goto cleanup;
+            virAsprintf(&scsi_host_name, "scsi_%s", name);
             if ((parent_name = virNodeDeviceGetParentName(conn,
                                                           scsi_host_name))) {
                 if (virStorageIsSameHostnum(parent_name, scsi_hostnum)) {
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[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