From nobody Mon Feb 9 20:32:33 2026 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=1632496808; cv=none; d=zohomail.com; s=zohoarc; b=dWhcIrgvHezZ+djDVcexGo0DD2a5ZpFFPv0iUxj1j5dQl8kJlxm5cSYr4OjUCyzM14V6c7y+8EebdZcFOXfKCC4ySX1b3VHCTNpsQYns1BHdqG/nD0EH8t9rMilREjjdv+YYvkZ7YCYrdqJwjEiDJLVgjsODnK10nY8QiEs3smA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496808; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t5n8lz043rTGQYRB5TfmsW+mXz2jDbkl4VkroO8NowI=; b=IsdRG/cewN5EVT8LDsYORZF9LYi11MhkBsDPXXj2340GJWX30mGm892RAY/qUMprs2hdlGaKXeDZZqv2PWqIK4Zxie4hONGDgODm7Yljwbu3UgVJgRNjv6KYBCmr6zIfWL9ig41fxmC15Qt0w9GMx5F/YBzhnXBunH52Js5uMTs= 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 1632496808584266.90001350958016; Fri, 24 Sep 2021 08:20:08 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-510-ZaxyqN8HMleppkui2GPzxw-1; Fri, 24 Sep 2021 11:20:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D549D100C682; Fri, 24 Sep 2021 15:19:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F031B5BAFA; Fri, 24 Sep 2021 15:19:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B48A64EA38; Fri, 24 Sep 2021 15:19:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18OFIKPo026607 for ; Fri, 24 Sep 2021 11:18:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C2A61803B; Fri, 24 Sep 2021 15:18:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA82476608 for ; Fri, 24 Sep 2021 15:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496807; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=t5n8lz043rTGQYRB5TfmsW+mXz2jDbkl4VkroO8NowI=; b=gU6mmbdyDd6BBYLRMGZEd3QWG4yeAGClXgnl8jU75Dme/ksAzCa9lkE6KP6w729KPXdv+S yxiyrZKuLlALQj8h/W1JEH8tBZ0/nLKsC8lsIwVNf6kyV13tTGOI90UL7m8mFLFibXs+PV nBgpRkHMaZ4GlM8zdMAsP0szvTBdswA= X-MC-Unique: ZaxyqN8HMleppkui2GPzxw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 4/7] virsh: domain: remove 'ret' variable, use early return when possible Date: Fri, 24 Sep 2021 17:17:47 +0200 Message-Id: <8c46918e147d0b7a6f40ccf22a808b9bb954e317.1632495763.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1632496809015100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- tools/virsh-domain.c | 84 +++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1da9b183bf..1692197d1a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2923,7 +2923,6 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) const char *path =3D NULL; unsigned long long size =3D 0; unsigned int flags =3D 0; - bool ret =3D false; =20 if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < = 0) return false; @@ -2942,12 +2941,11 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) =20 if (virDomainBlockResize(dom, path, size, flags) < 0) { vshError(ctl, _("Failed to resize block device '%s'"), path); - } else { - vshPrintExtra(ctl, _("Block device '%s' is resized"), path); - ret =3D true; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Block device '%s' is resized"), path); + return true; } =20 #ifndef WIN32 @@ -3421,19 +3419,17 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *name; - bool ret =3D true; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainSuspend(dom) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' suspended\n"), name); - } else { + if (virDomainSuspend(dom) !=3D 0) { vshError(ctl, _("Failed to suspend domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' suspended\n"), name); + return true; } =20 /* @@ -5802,20 +5798,18 @@ static bool cmdResume(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; const char *name; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainResume(dom) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' resumed\n"), name); - } else { + if (virDomainResume(dom) !=3D 0) { vshError(ctl, _("Failed to resume domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' resumed\n"), name); + return true; } =20 /* @@ -5997,20 +5991,18 @@ static bool cmdReset(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; const char *name; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 - if (virDomainReset(dom, 0) =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' was reset\n"), name); - } else { + if (virDomainReset(dom, 0) !=3D 0) { vshError(ctl, _("Failed to reset domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' was reset\n"), name); + return true; } =20 /* @@ -8183,7 +8175,6 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; - bool ret =3D true; char *buffer; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; @@ -8203,14 +8194,14 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) dom =3D virDomainDefineXML(priv->conn, buffer); VIR_FREE(buffer); =20 - if (dom !=3D NULL) { - vshPrintExtra(ctl, _("Domain '%s' defined from %s\n"), - virDomainGetName(dom), from); - } else { + if (!dom) { vshError(ctl, _("Failed to define domain from %s"), from); - ret =3D false; + return false; } - return ret; + + vshPrintExtra(ctl, _("Domain '%s' defined from %s\n"), + virDomainGetName(dom), from); + return true; } =20 /* @@ -8239,7 +8230,6 @@ static bool cmdDestroy(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; const char *name; unsigned int flags =3D 0; int result; @@ -8255,14 +8245,13 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) else result =3D virDomainDestroy(dom); =20 - if (result =3D=3D 0) { - vshPrintExtra(ctl, _("Domain '%s' destroyed\n"), name); - } else { + if (result < 0) { vshError(ctl, _("Failed to destroy domain '%s'"), name); - ret =3D false; + return false; } =20 - return ret; + vshPrintExtra(ctl, _("Domain '%s' destroyed\n"), name); + return true; } =20 /* @@ -9955,7 +9944,6 @@ static bool cmdDumpXML(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; g_autofree char *dump =3D NULL; unsigned int flags =3D 0; bool inactive =3D vshCommandOptBool(cmd, "inactive"); @@ -9975,14 +9963,11 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 - dump =3D virDomainGetXMLDesc(dom, flags); - if (dump !=3D NULL) { - vshPrint(ctl, "%s", dump); - } else { - ret =3D false; - } + if (!(dump =3D virDomainGetXMLDesc(dom, flags))) + return false; =20 - return ret; + vshPrint(ctl, "%s", dump); + return true; } =20 /* @@ -10016,7 +10001,6 @@ static const vshCmdOptDef opts_domxmlfromnative[] = =3D { static bool cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D true; const char *format =3D NULL; const char *configFile =3D NULL; g_autofree char *configData =3D NULL; @@ -10032,13 +10016,11 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd= *cmd) return false; =20 xmlData =3D virConnectDomainXMLFromNative(priv->conn, format, configDa= ta, flags); - if (xmlData !=3D NULL) { - vshPrint(ctl, "%s", xmlData); - } else { - ret =3D false; - } + if (!xmlData) + return false; =20 - return ret; + vshPrint(ctl, "%s", xmlData); + return true; } =20 /* --=20 2.31.1