From nobody Fri May 17 11:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661262723; cv=none; d=zohomail.com; s=zohoarc; b=DVSrMdE2GI7DgqN56crTG07TrQVLacbyRoIHEPCh/dTRMXjUHw7Eiru73qQs8YNWYtjdu8kqrc0jM5MeGqoegPaHqfH8A+p588S49Wa+hkwwqVvtp73hG3y7LwC2O0e+LYxl7m0iPKpnt/ZMc5aATNTVj//fTrH1ykhGU//szlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661262723; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=JuvVMb3CuLjErFRjLUR631Fqs5Z8ztVohmVHfzcdA0o=; b=HaBq+qMuCmrf6S/bHuuCrLz5DhD28wXjUt2yFZCMZ05VlYJabB0GohwK3jQB2yFwl6uVpxaGdYEW/4nypnmU4jAbIAcHflXoQAfcqB+aNt2LMIQmVY2lFGGDbje38MvGuaML8hr1EtA5dmM08aHl8iRh/iAQ8Ie899w06S4CH4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661262723406453.58324555507807; Tue, 23 Aug 2022 06:52:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-NFanI82uPXWoUdWqGv2peQ-1; Tue, 23 Aug 2022 09:51:43 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 489958037B7; Tue, 23 Aug 2022 13:51:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A74CA492CA4; Tue, 23 Aug 2022 13:51:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9368A1946A47; Tue, 23 Aug 2022 13:51:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 28A5D1946A40 for ; Tue, 23 Aug 2022 13:51:36 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 14F6A492C3B; Tue, 23 Aug 2022 13:51:36 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5C3B403349 for ; Tue, 23 Aug 2022 13:51:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661262722; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JuvVMb3CuLjErFRjLUR631Fqs5Z8ztVohmVHfzcdA0o=; b=GEEsnAb3ux7BheFbFSW1Cj4MtFplGue3wO6DHkOb74TWw6AWioQX6PWmTOSTyPbticibaT uU681whdruSoTyCBt4j1bI0mKh9KtObSztZWPAgltm7HPPwQDfI8sf5ECZqJHsgMd1m7HD KxdAoj0+rtKq42P3sHfUeIRONMsZEpM= X-MC-Unique: NFanI82uPXWoUdWqGv2peQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] lib: Don't check for retval for virCommandNew*() Date: Tue, 23 Aug 2022 15:51:32 +0200 Message-Id: <79961da52ec1b86192e4b85b0d30b2278b3dbb61.1661262692.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661262725100100001 Content-Type: text/plain; charset="utf-8"; x-default="true" 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 Reviewed-by: Laine Stump --- src/qemu/qemu_slirp.c | 3 +-- src/qemu/qemu_tpm.c | 10 ---------- src/qemu/qemu_vhost_user_gpu.c | 2 -- src/qemu/qemu_virtiofs.c | 3 +-- src/util/virtpm.c | 3 +-- tests/virshtest.c | 3 +-- 6 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c index c802ef7fa8..3f83db03bf 100644 --- a/src/qemu/qemu_slirp.c +++ b/src/qemu/qemu_slirp.c @@ -268,8 +268,7 @@ qemuSlirpStart(virDomainObj *vm, if (!(pidfile =3D qemuSlirpCreatePidFilename(cfg, vm->def, net->info.a= lias))) return -1; =20 - if (!(cmd =3D virCommandNew(cfg->slirpHelperName))) - return -1; + cmd =3D virCommandNew(cfg->slirpHelperName); =20 virCommandClearCaps(cmd); virCommandSetPidFile(cmd, pidfile); diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 584c787b70..d0aed7fa2e 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -279,8 +279,6 @@ qemuTPMCreateConfigFiles(const char *swtpm_setup) return 0; =20 cmd =3D virCommandNew(swtpm_setup); - if (!cmd) - return -1; =20 virCommandAddArgList(cmd, "--create-config-files", "skip-if-exist", NU= LL); virCommandClearCaps(cmd); @@ -388,8 +386,6 @@ qemuTPMEmulatorRunSetup(const char *storagepath, return -1; =20 cmd =3D virCommandNew(swtpm_setup); - if (!cmd) - return -1; =20 virUUIDFormat(vmuuid, uuid); vmid =3D g_strdup_printf("%s:%s", vmname, uuid); @@ -500,8 +496,6 @@ qemuTPMEmulatorReconfigure(const char *storagepath, return 0; =20 cmd =3D virCommandNew(swtpm_setup); - if (!cmd) - return -1; =20 virCommandSetUID(cmd, swtpm_user); virCommandSetGID(cmd, swtpm_group); @@ -592,8 +586,6 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, unlink(tpm->data.emulator.source->data.nix.path); =20 cmd =3D virCommandNew(swtpm); - if (!cmd) - goto error; =20 virCommandClearCaps(cmd); =20 @@ -806,8 +798,6 @@ qemuTPMEmulatorStop(const char *swtpmStateDir, return; =20 cmd =3D virCommandNew(swtpm_ioctl); - if (!cmd) - return; =20 virCommandAddArgList(cmd, "--unix", pathname, "-s", NULL); =20 diff --git a/src/qemu/qemu_vhost_user_gpu.c b/src/qemu/qemu_vhost_user_gpu.c index 7c5be4098e..bc5a1dc3ec 100644 --- a/src/qemu/qemu_vhost_user_gpu.c +++ b/src/qemu/qemu_vhost_user_gpu.c @@ -133,8 +133,6 @@ int qemuExtVhostUserGPUStart(virQEMUDriver *driver, goto error; =20 cmd =3D virCommandNew(video->driver->vhost_user_binary); - if (!cmd) - goto error; =20 virCommandClearCaps(cmd); virCommandSetPidFile(cmd, pidfile); diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c index ce55286ab5..a04aa08e39 100644 --- a/src/qemu/qemu_virtiofs.c +++ b/src/qemu/qemu_virtiofs.c @@ -132,8 +132,7 @@ qemuVirtioFSBuildCommandLine(virQEMUDriverConfig *cfg, g_autoptr(virCommand) cmd =3D NULL; g_auto(virBuffer) opts =3D VIR_BUFFER_INITIALIZER; =20 - if (!(cmd =3D virCommandNew(fs->binary))) - return NULL; + cmd =3D virCommandNew(fs->binary); =20 virCommandAddArgFormat(cmd, "--fd=3D%d", *fd); virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 2f2b061fee..91db0f31eb 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -252,8 +252,7 @@ virTPMGetCaps(virTPMBinaryCapsParse capsParse, { g_autoptr(virCommand) cmd =3D NULL; =20 - if (!(cmd =3D virCommandNew(exec))) - return NULL; + cmd =3D virCommandNew(exec); =20 if (param1) virCommandAddArg(cmd, param1); diff --git a/tests/virshtest.c b/tests/virshtest.c index a53a6273b9..3d297a1db2 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -116,8 +116,7 @@ testCompareOutputLit(const char *expectData, g_autoptr(virCommand) cmd =3D NULL; g_autofree char *errbuf =3D NULL; =20 - if (!(cmd =3D virCommandNewArgs(argv))) - return -1; + cmd =3D virCommandNewArgs(argv); =20 virCommandAddEnvString(cmd, "LANG=3DC"); virCommandSetInputBuffer(cmd, empty); --=20 2.35.1