From nobody Mon Feb 9 16:02:30 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=1632496887; cv=none; d=zohomail.com; s=zohoarc; b=m66VXRp3PSJtFpLfX3vjrRD2ly7tEfsEGp9t/aWfl5hQpasSJdTuyB5uJ3b2aC+GP3JM55d7j4nRQ+PCni3GTFaUOnL44oFEl+9EjpH8KXHSkFZZIlQEUBft4EwYl9InY731RmUxK7zvV8pQSMuHhJRDOU9KrXDmd2SNJqCTYS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632496887; 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=Z7SfBFGgU3/qox0M1qsFPx1VWeneNh8U9kUB+LRiC1M=; b=HyF6bnswvxVpcSlztpsR6EziZ0/lCuEky056tvE3EudK84t/YAeptUVdggAEb7IMXVaZKPr2rRWNeA0CxN035YY0Y5CIFcRqI/4eB/8YCJcpH/NevqmTX4r2d6eBTXWWM4t7vaTnnBe6HvcqT7FCdjJKXgCtBi8NF0Z7QBnyUKY= 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 16324968878341018.7537523883486; Fri, 24 Sep 2021 08:21:27 -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-16-Hv3WEgK5Ov2z4wJWve7bKw-1; Fri, 24 Sep 2021 11:21:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E05B104ECFC; Fri, 24 Sep 2021 15:21:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2F205D9DD; Fri, 24 Sep 2021 15:21:19 +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 148941803B30; Fri, 24 Sep 2021 15:21:19 +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 18OFIDTO026594 for ; Fri, 24 Sep 2021 11:18:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A8231800D; Fri, 24 Sep 2021 15:18:12 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 215FF177C0 for ; Fri, 24 Sep 2021 15:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632496886; 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=Z7SfBFGgU3/qox0M1qsFPx1VWeneNh8U9kUB+LRiC1M=; b=Dl72znGMDnc98ZuZ6+9VdUs5o+RkPd4/Eqqysr8Xso1xXJ/pgjXbmGgNRsn3T/kFzbAMGS tlnnaTai0eu0ANYGy3bGY8o9l2VdFZ2ujQBpXAwrLHLiwTzpAetftWo9VN2+mBmcvapFLJ JAuIu8lTxFggh+VBF6I+mvkqoUlHyWA= X-MC-Unique: Hv3WEgK5Ov2z4wJWve7bKw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 3/7] virsh: domain: remove 'ret' variable and use direct return when possible Date: Fri, 24 Sep 2021 17:17:46 +0200 Message-Id: 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.14 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: 1632496888848100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- tools/virsh-domain.c | 62 ++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0d482f9e15..1da9b183bf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2702,7 +2702,6 @@ virshBlockJobAbort(virDomainPtr dom, static bool cmdBlockjob(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; bool raw =3D vshCommandOptBool(cmd, "raw"); bool bytes =3D vshCommandOptBool(cmd, "bytes"); bool abortMode =3D vshCommandOptBool(cmd, "abort"); @@ -2735,13 +2734,10 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) return false; =20 if (bandwidth) - ret =3D virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); - else if (abortMode || pivot || async) - ret =3D virshBlockJobAbort(dom, path, pivot, async); - else - ret =3D virshBlockJobInfo(ctl, dom, path, raw, bytes); - - return ret; + return virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); + if (abortMode || pivot || async) + return virshBlockJobAbort(dom, path, pivot, async); + return virshBlockJobInfo(ctl, dom, path, raw, bytes); } =20 /* @@ -5063,7 +5059,6 @@ cmdSchedInfoUpdateOne(vshControl *ctl, const char *field, const char *value) { virTypedParameterPtr param; - int ret =3D -1; size_t i; =20 for (i =3D 0; i < nsrc_params; i++) { @@ -5078,14 +5073,11 @@ cmdSchedInfoUpdateOne(vshControl *ctl, vshSaveLibvirtError(); return -1; } - ret =3D 0; - break; + return 0; } =20 - if (ret < 0) - vshError(ctl, _("invalid scheduler option: %s"), field); - - return ret; + vshError(ctl, _("invalid scheduler option: %s"), field); + return -1; } =20 static int @@ -5529,7 +5521,6 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, c= onst char *mime) g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); g_autofree char *nowstr =3D NULL; const char *ext =3D NULL; - char *ret =3D NULL; =20 if (!dom) { vshError(ctl, "%s", _("Invalid domain supplied")); @@ -5544,10 +5535,8 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, = const char *mime) =20 nowstr =3D g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); =20 - ret =3D g_strdup_printf("%s-%s%s", virDomainGetName(dom), - nowstr, NULLSTR_EMPTY(ext)); - - return ret; + return g_strdup_printf("%s-%s%s", virDomainGetName(dom), + nowstr, NULLSTR_EMPTY(ext)); } =20 static bool @@ -5686,7 +5675,6 @@ static bool cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -5727,10 +5715,9 @@ cmdSetLifecycleAction(vshControl *ctl, const vshCmd = *cmd) =20 if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) { vshError(ctl, "%s", _("Unable to change lifecycle action.")); - ret =3D false; + return false; } - - return ret; + return true; } =20 /* @@ -6469,15 +6456,14 @@ static bool cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (virDomainAbortJob(dom) < 0) - ret =3D false; + return false; =20 - return ret; + return true; } =20 /* @@ -11926,12 +11912,12 @@ virshDomainDetachInterface(char *doc, xmlNodePtr cur =3D NULL, matchNode =3D NULL; g_autofree char *detach_xml =3D NULL; char buf[64]; - int diff_mac, ret =3D -1; + int diff_mac =3D -1; size_t i; =20 if (!(xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ct= xt))) { vshError(ctl, "%s", _("Failed to get interface information")); - goto cleanup; + return false; } =20 g_snprintf(buf, sizeof(buf), "/domain/devices/interface[@type=3D'%s']"= , type); @@ -11939,13 +11925,13 @@ virshDomainDetachInterface(char *doc, if (obj =3D=3D NULL || obj->type !=3D XPATH_NODESET || obj->nodesetval =3D=3D NULL || obj->nodesetval->nodeNr =3D=3D 0) { vshError(ctl, _("No interface found whose type is %s"), type); - goto cleanup; + return false; } =20 if (!mac && obj->nodesetval->nodeNr > 1) { vshError(ctl, _("Domain has %d interfaces. Please specify which on= e " "to detach using --mac"), obj->nodesetval->nodeNr); - goto cleanup; + return false; } =20 if (!mac) { @@ -11968,7 +11954,7 @@ virshDomainDetachInterface(char *doc, "MAC address %s. You must use deta= ch-device and " "specify the device pci address to= remove it."), mac); - goto cleanup; + return false; } matchNode =3D obj->nodesetval->nodeTab[i]; } @@ -11978,22 +11964,18 @@ virshDomainDetachInterface(char *doc, } if (!matchNode) { vshError(ctl, _("No interface with MAC address %s was found"), mac= ); - goto cleanup; + return false; } =20 hit: if (!(detach_xml =3D virXMLNodeToString(xml, matchNode))) { vshSaveLibvirtError(); - goto cleanup; + return false; } =20 if (flags !=3D 0 || current) - ret =3D virDomainDetachDeviceFlags(dom, detach_xml, flags); - else - ret =3D virDomainDetachDevice(dom, detach_xml); - - cleanup: - return ret =3D=3D 0; + return virDomainDetachDeviceFlags(dom, detach_xml, flags) =3D=3D 0; + return virDomainDetachDevice(dom, detach_xml) =3D=3D 0; } =20 =20 --=20 2.31.1