]> xenbits.xensource.com Git - libvirt.git/commitdiff
src: Don't check for retval of some glib functions
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Jan 2022 07:52:57 +0000 (08:52 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Jan 2022 11:13:51 +0000 (12:13 +0100)
There are a few glib functions that abort on OOM and thus there's
no point in checking their retval against NULL. Nevertheless, we
do have those checks in a few places. Remove them.

Generated using the following spatch:

  @@
  expression x;
  identifier n;
  expression r;
  @@
  (
    x = g_strdup_printf(...);
  | x = g_strdup_vprintf(...);
  | x = g_strdup(...);
  | x = g_strndup(...);
  | x = g_new0(...);
  | x = g_realloc(...);
  )
    ... when != x
  - if(!x)
  (
  -   return r;
  |
  -   goto n;
  )

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/hyperv/hyperv_driver.c
src/util/virprocess.c

index 3327f0132e26bb39eb335d382f1fa9cd4dd4a5f6..7b684e04ba1cd0a21130fb3748d9af18697c888d 100644 (file)
@@ -482,8 +482,6 @@ hypervDomainAddVirtualDiskParent(virDomainPtr domain,
     parent__PATH = g_strdup_printf("\\\\%s\\Root\\Virtualization\\V2:"
                                    "Msvm_ResourceAllocationSettingData.InstanceID=\"%s\"",
                                    hostname, parentInstanceIDEscaped);
-    if (!parent__PATH)
-        return -1;
 
     if (hypervSetEmbeddedProperty(controllerResource, "Parent", parent__PATH) < 0)
         return -1;
@@ -529,9 +527,6 @@ hypervDomainAddVirtualHardDisk(virDomainPtr domain,
                                 "Msvm_ResourceAllocationSettingData.InstanceID=\"%s\"",
                                 hostname, vhdInstanceIdEscaped);
 
-    if (!vhd__PATH)
-        return -1;
-
     if (hypervSetEmbeddedProperty(volumeResource, "Parent", vhd__PATH) < 0)
         return -1;
 
@@ -660,8 +655,6 @@ hypervDomainAttachPhysicalDisk(virDomainPtr domain,
     controller__PATH = g_strdup_printf("\\\\%s\\Root\\Virtualization\\V2:"
                                        "Msvm_ResourceAllocationSettingData.InstanceID=\"%s\"",
                                        hostname, controllerInstanceIdEscaped);
-    if (!controller__PATH)
-        return -1;
 
     if (hypervSetEmbeddedProperty(diskResource, "Parent", controller__PATH) < 0)
         return -1;
@@ -711,8 +704,6 @@ hypervDomainAddOpticalDrive(virDomainPtr domain,
     parent__PATH = g_strdup_printf("\\\\%s\\Root\\Virtualization\\V2:"
                                    "Msvm_ResourceAllocationSettingData.InstanceID=\"%s\"",
                                    hostname, parentInstanceIDEscaped);
-    if (!parent__PATH)
-        return -1;
 
     if (hypervSetEmbeddedProperty(driveResource, "Parent", parent__PATH) < 0)
         return -1;
@@ -756,8 +747,6 @@ hypervDomainAddOpticalDisk(virDomainPtr domain,
     vhd__PATH = g_strdup_printf("\\\\%s\\Root\\Virtualization\\V2:"
                                 "Msvm_ResourceAllocationSettingData.InstanceID=\"%s\"",
                                 hostname, vhdInstanceIdEscaped);
-    if (!vhd__PATH)
-        return -1;
 
     if (hypervSetEmbeddedProperty(volumeResource, "Parent", vhd__PATH) < 0)
         return -1;
@@ -829,9 +818,6 @@ hypervDomainAttachFloppy(virDomainPtr domain,
                                 "Msvm_ResourceAllocationSettingData.InstanceID=\"%s\"",
                                 hostname, vhdInstanceIdEscaped);
 
-    if (!vfd__PATH)
-        return -1;
-
     if (hypervSetEmbeddedProperty(volumeResource, "Parent", vfd__PATH) < 0)
         return -1;
 
index 5788faea9c8582f4cb41d26f78c1ad3ebbba065d..b559a4257ec6621eced5b3b75edd64a1b9da418a 100644 (file)
@@ -1827,8 +1827,6 @@ virProcessGetSchedInfo(unsigned long long *cpuWait,
         proc = g_strdup_printf("/proc/%d/task/%d/sched", (int) pid, (int) tid);
     else
         proc = g_strdup_printf("/proc/%d/sched", (int) pid);
-    if (!proc)
-        return -1;
 
     /* The file is not guaranteed to exist (needs CONFIG_SCHED_DEBUG) */
     if (access(proc, R_OK) < 0) {