From nobody Sun Feb 8 12:42:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1636730653; cv=none; d=zohomail.com; s=zohoarc; b=RLutMuSprrWL7JnAzcN39pLNuHVlB3NOCDkPKudu4VMv+y5vLWm5jdvLZ4XQIBCye+qZ8oUHigP/vYlu/p4FlWXdev2sRT79TOCKXsXNSMdfcu+ai7WJj4j3r55x8pZMOB6Hypu3kxLSZdFot8VkNRAQ40af3v0uO9/GzyUx1eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636730653; 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=kpyAzvRlfGq8UXNn1TSU+wmaH5reqNyCEcZ6uU6e3jk=; b=ZYAROgbE6JT08NcRbAMqZTgGZUEw7voUw52q5jOIyntks0aGt9Th0sHIM5YvGRmBnGuUN2XId9RxJQYlNKnNOVUeWPrhEG7qRrGnGLd5XsaSizlGoz+Mb4mFaWpVkj1v1msvN45CzzkXbhv77mxQdPXtvQT4ojaa2igEtcskyHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1636730653088550.1653074121361; Fri, 12 Nov 2021 07:24:13 -0800 (PST) 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-249-Ap39GcDTPeq3uH2nDE4H6A-1; Fri, 12 Nov 2021 10:23:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD50281C6DE; Fri, 12 Nov 2021 15:22:54 +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 AFFB16784A; Fri, 12 Nov 2021 15:22:54 +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 7EAF74EA30; Fri, 12 Nov 2021 15:22:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ACFMjW3014396 for ; Fri, 12 Nov 2021 10:22:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id E768360C5F; Fri, 12 Nov 2021 15:22:45 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DB3160C4A for ; Fri, 12 Nov 2021 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636730652; 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=kpyAzvRlfGq8UXNn1TSU+wmaH5reqNyCEcZ6uU6e3jk=; b=GnOUyZhjyW9ppAof39DLfgAOecMz5xdUUrAPeIF/Qe0dkFmy7mwqG5SQj25hbFfqWDtysJ kO6rV1aoQg65Nes7iDk7baO2jPR21GUiffnqvn82MjRo2iEZhzag8ubikdeUh/hoZJbm+B GEiBzUxrgeg0MDz5k1ruGYAO5KIf050= X-MC-Unique: Ap39GcDTPeq3uH2nDE4H6A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] virsh: Remove unnecessary else branches Date: Fri, 12 Nov 2021 16:22:35 +0100 Message-Id: <334a7fbb4383df1ce173513ce9ecbb05ffa5f65e.1636730459.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.11 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: 1636730655599100001 Content-Type: text/plain; charset="utf-8" In a few cases we call a public API, wrapped in an if() statement with both branches written out explicitly. The error branch jumps onto cleanup label, while the successful prints out a message. Right after these ifs there's 'ret =3D true;' and the cleanup label. The code is a bit more readable if only the error branch is kept and printing happens at the same level as setting the ret variable. Signed-off-by: Michal Privoznik --- tools/virsh-nodedev.c | 5 ++--- tools/virsh-volume.c | 32 +++++++++++++++----------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 1ad8db7a3f..424865962f 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1024,13 +1024,12 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd= *cmd G_GNUC_UNUSED) if (!dev) goto cleanup; =20 - if (virNodeDeviceUndefine(dev, 0) =3D=3D 0) { - vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value= ); - } else { + if (virNodeDeviceUndefine(dev, 0) < 0) { vshError(ctl, _("Failed to undefine node device '%s'"), device_val= ue); goto cleanup; } =20 + vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value); ret =3D true; cleanup: return ret; diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 4c8e841701..12773d900b 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -411,14 +411,14 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if ((vol =3D virStorageVolCreateXML(pool, buffer, flags))) { - vshPrintExtra(ctl, _("Vol %s created from %s\n"), - virStorageVolGetName(vol), from); - ret =3D true; - } else { + if (!(vol =3D virStorageVolCreateXML(pool, buffer, flags))) { vshError(ctl, _("Failed to create vol from %s"), from); + goto cleanup; } =20 + vshPrintExtra(ctl, _("Vol %s created from %s\n"), + virStorageVolGetName(vol), from); + ret =3D true; cleanup: return ret; } @@ -489,14 +489,13 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) =20 newvol =3D virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags); =20 - if (newvol !=3D NULL) { - vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"), - virStorageVolGetName(newvol), virStorageVolGetName(i= nputvol)); - } else { + if (!newvol) { vshError(ctl, _("Failed to create vol from %s"), from); goto cleanup; } =20 + vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"), + virStorageVolGetName(newvol), virStorageVolGetName(input= vol)); ret =3D true; cleanup: return ret; @@ -1147,20 +1146,19 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (virStorageVolResize(vol, capacity, flags) =3D=3D 0) { - vshPrintExtra(ctl, - delta ? _("Size of volume '%s' successfully changed = by %s\n") - : _("Size of volume '%s' successfully changed to %s\= n"), - virStorageVolGetName(vol), capacityStr); - ret =3D true; - } else { + if (virStorageVolResize(vol, capacity, flags) < 0) { vshError(ctl, delta ? _("Failed to change size of volume '%s' by %s") : _("Failed to change size of volume '%s' to %s"), virStorageVolGetName(vol), capacityStr); - ret =3D false; + goto cleanup; } =20 + vshPrintExtra(ctl, + delta ? _("Size of volume '%s' successfully changed by %= s\n") + : _("Size of volume '%s' successfully changed to %s\n"), + virStorageVolGetName(vol), capacityStr); + ret =3D true; cleanup: return ret; } --=20 2.32.0