]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lib: Don't check for retval for virCommandNew*()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 23 Aug 2022 12:35:47 +0000 (14:35 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 23 Aug 2022 14:14:05 +0000 (16:14 +0200)
The virCommand module is specifically designed so that no caller
has to check for retval of individual virCommand*() APIs except
for virCommandRun() where the actual error is reported. Moreover,
virCommandNew*() use g_new0() to allocate memory and thus it's
not really possible for those APIs to return NULL. Which is why
they are even marked as ATTRIBUTE_NONNULL. But there are few
places where we do check the retval which is a dead code
effectively. Drop those checks.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/qemu/qemu_slirp.c
src/qemu/qemu_tpm.c
src/qemu/qemu_vhost_user_gpu.c
src/qemu/qemu_virtiofs.c
src/util/virtpm.c
tests/virshtest.c

index c802ef7fa865b7e224b67b69a3f22fec066b3eb6..3f83db03bf16b0574aaef06bd53b86600215046a 100644 (file)
@@ -268,8 +268,7 @@ qemuSlirpStart(virDomainObj *vm,
     if (!(pidfile = qemuSlirpCreatePidFilename(cfg, vm->def, net->info.alias)))
         return -1;
 
-    if (!(cmd = virCommandNew(cfg->slirpHelperName)))
-        return -1;
+    cmd = virCommandNew(cfg->slirpHelperName);
 
     virCommandClearCaps(cmd);
     virCommandSetPidFile(cmd, pidfile);
index 584c787b700b935f167c495ff71438913efebceb..d0aed7fa2eb70ee87b0d00b0718167bb8e1caae5 100644 (file)
@@ -279,8 +279,6 @@ qemuTPMCreateConfigFiles(const char *swtpm_setup)
         return 0;
 
     cmd = virCommandNew(swtpm_setup);
-    if (!cmd)
-        return -1;
 
     virCommandAddArgList(cmd, "--create-config-files", "skip-if-exist", NULL);
     virCommandClearCaps(cmd);
@@ -388,8 +386,6 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
         return -1;
 
     cmd = virCommandNew(swtpm_setup);
-    if (!cmd)
-        return -1;
 
     virUUIDFormat(vmuuid, uuid);
     vmid = g_strdup_printf("%s:%s", vmname, uuid);
@@ -500,8 +496,6 @@ qemuTPMEmulatorReconfigure(const char *storagepath,
         return 0;
 
     cmd = virCommandNew(swtpm_setup);
-    if (!cmd)
-        return -1;
 
     virCommandSetUID(cmd, swtpm_user);
     virCommandSetGID(cmd, swtpm_group);
@@ -592,8 +586,6 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm,
     unlink(tpm->data.emulator.source->data.nix.path);
 
     cmd = virCommandNew(swtpm);
-    if (!cmd)
-        goto error;
 
     virCommandClearCaps(cmd);
 
@@ -806,8 +798,6 @@ qemuTPMEmulatorStop(const char *swtpmStateDir,
         return;
 
     cmd = virCommandNew(swtpm_ioctl);
-    if (!cmd)
-        return;
 
     virCommandAddArgList(cmd, "--unix", pathname, "-s", NULL);
 
index 7c5be4098e5bad636e0b519050407bf2378a71b3..bc5a1dc3ec838432af1e4d3474f3067f6a962928 100644 (file)
@@ -133,8 +133,6 @@ int qemuExtVhostUserGPUStart(virQEMUDriver *driver,
         goto error;
 
     cmd = virCommandNew(video->driver->vhost_user_binary);
-    if (!cmd)
-        goto error;
 
     virCommandClearCaps(cmd);
     virCommandSetPidFile(cmd, pidfile);
index ce55286ab5e3bd18cf7c55026206faeaef95552a..a04aa08e39df0b0aa7ed494441e505436e16b5f4 100644 (file)
@@ -132,8 +132,7 @@ qemuVirtioFSBuildCommandLine(virQEMUDriverConfig *cfg,
     g_autoptr(virCommand) cmd = NULL;
     g_auto(virBuffer) opts = VIR_BUFFER_INITIALIZER;
 
-    if (!(cmd = virCommandNew(fs->binary)))
-        return NULL;
+    cmd = virCommandNew(fs->binary);
 
     virCommandAddArgFormat(cmd, "--fd=%d", *fd);
     virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
index 2f2b061fee51f72e0f6bb9d6e4fb887bccff455f..91db0f31eb5d60ef7f29701678c3b2afd11ea67d 100644 (file)
@@ -252,8 +252,7 @@ virTPMGetCaps(virTPMBinaryCapsParse capsParse,
 {
     g_autoptr(virCommand) cmd = NULL;
 
-    if (!(cmd = virCommandNew(exec)))
-        return NULL;
+    cmd = virCommandNew(exec);
 
     if (param1)
         virCommandAddArg(cmd, param1);
index a53a6273b90e9fb5e04c1fe3297f450bb4f401fc..3d297a1db2818ecbe07351216f328b9ccdd54fda 100644 (file)
@@ -116,8 +116,7 @@ testCompareOutputLit(const char *expectData,
     g_autoptr(virCommand) cmd = NULL;
     g_autofree char *errbuf = NULL;
 
-    if (!(cmd = virCommandNewArgs(argv)))
-        return -1;
+    cmd = virCommandNewArgs(argv);
 
     virCommandAddEnvString(cmd, "LANG=C");
     virCommandSetInputBuffer(cmd, empty);