From nobody Mon Feb 9 06:48:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613167685; cv=none; d=zohomail.com; s=zohoarc; b=XewrkRMshDljdL8UCZ4oiFFKGjdbjFIbu8B0hGbCndy1+bdL96ML/2zcYktQyw+RpcSKezY6dUYrZpxu0WcPQeRYwRAOuFXoOJZ0L0g92RLYosiC0Jeb7DVufV5kScQ40Nblag+D0dlSH72zMkgkmkWmyi2gNOxsqpDs84lBakE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613167685; 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=pRUrM8qGtZrciNzTbgbRGzlopDrFT9ozroSgWmvay4U=; b=F2N7iPUdoFC2XNkoRhYy+qpX8gLQTXkzH+Lc32MzUFnwbIFUywxv7VER5ig3+eF3qOkhuWJxc2vZ0Ck9xY4TAIJm7cO0LCGaueHH/fey/cb2tmp6qUNdsAeHmd6npzes83rurRhUWvK88YClJCJLXFmihhE0Nq3QjtrxFr4x1lM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 16131676853451010.2555647683406; Fri, 12 Feb 2021 14:08:05 -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-170-YpKMw_-iNJSHQPJZ8rFOVg-1; Fri, 12 Feb 2021 17:07:52 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBE151966324; Fri, 12 Feb 2021 22:07:45 +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 B1C4019D9F; Fri, 12 Feb 2021 22:07:45 +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 7A93718089C9; Fri, 12 Feb 2021 22:07:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11CM7OP9006176 for ; Fri, 12 Feb 2021 17:07:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 97D57100239A; Fri, 12 Feb 2021 22:07:24 +0000 (UTC) Received: from vhost2.router.laine.org (ovpn-112-48.phx2.redhat.com [10.3.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FB7E1002388 for ; Fri, 12 Feb 2021 22:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613167675; 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=pRUrM8qGtZrciNzTbgbRGzlopDrFT9ozroSgWmvay4U=; b=MCLA4RwOavE5leo39syESZXpd4HbDMqdRKm7oUHJwtMOhwdc9C2arlMu73WFPkUMxzn5QW uB3+4q/xxVCrMy+TBykh1C9xdjxjdQ6t0SHssETzW8TwKmjdWr2cWL3MDcwzC/O/2EAmwH bgVy2fm+lxmp3e56Q53gp4LYNlKrYtM= X-MC-Unique: YpKMw_-iNJSHQPJZ8rFOVg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 8/9] esx: eliminate unnecessary cleanup: labels and result variables Date: Fri, 12 Feb 2021 17:07:16 -0500 Message-Id: <20210212220717.910294-9-laine@redhat.com> In-Reply-To: <20210212220717.910294-1-laine@redhat.com> References: <20210212220717.910294-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.84 on 10.5.11.23 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) Content-Type: text/plain; charset="utf-8" switching to g_autofree left many cleanup: sections empty. Signed-off-by: Laine Stump --- src/esx/esx_driver.c | 22 ++++++--------- src/esx/esx_storage_backend_vmfs.c | 22 +++++---------- src/esx/esx_util.c | 8 ++---- src/esx/esx_vi.c | 45 +++++++++++++----------------- src/esx/esx_vi_types.c | 8 ++---- 5 files changed, 38 insertions(+), 67 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index fe98f90ea9..e49975de86 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -690,7 +690,6 @@ esxConnectToVCenter(esxPrivate *priv, const char *hostname, const char *hostSystemIPAddress) { - int result =3D -1; g_autofree char *ipAddress =3D NULL; g_autofree char *username =3D NULL; g_autofree char *password =3D NULL; @@ -711,11 +710,11 @@ esxConnectToVCenter(esxPrivate *priv, } else { if (!(username =3D virAuthGetUsername(conn, auth, "esx", "administ= rator", hostname))) - goto cleanup; + return -1; } =20 if (!(password =3D virAuthGetPassword(conn, auth, "esx", username, hos= tname))) - goto cleanup; + return -1; =20 url =3D g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport, = hostname, conn->uri->port); @@ -723,7 +722,7 @@ esxConnectToVCenter(esxPrivate *priv, if (esxVI_Context_Alloc(&priv->vCenter) < 0 || esxVI_Context_Connect(priv->vCenter, url, ipAddress, username, password, priv->parsedUri) < 0) { - goto cleanup; + return -1; } =20 if (priv->vCenter->productLine !=3D esxVI_ProductLine_VPX) { @@ -732,25 +731,20 @@ esxConnectToVCenter(esxPrivate *priv, hostname, esxVI_ProductLineToDisplayName(esxVI_ProductLine_VP= X), esxVI_ProductLineToDisplayName(priv->vCenter->produ= ctLine)); - goto cleanup; + return -1; } =20 if (hostSystemIPAddress) { - if (esxVI_Context_LookupManagedObjectsByHostSystemIp - (priv->vCenter, hostSystemIPAddress) < 0) { - goto cleanup; - } + if (esxVI_Context_LookupManagedObjectsByHostSystemIp(priv->vCenter= , hostSystemIPAddress) < 0) + return -1; } else { if (esxVI_Context_LookupManagedObjectsByPath(priv->vCenter, priv->parsedUri->path= ) < 0) { - goto cleanup; + return -1; } } =20 - result =3D 0; - - cleanup: - return result; + return 0; } =20 =20 diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index 95505d6796..cb2be59a33 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -667,7 +667,6 @@ static virStorageVolPtr esxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) { - virStorageVolPtr volume =3D NULL; esxPrivate *priv =3D pool->conn->privateData; g_autofree char *datastorePath =3D NULL; g_autofree char *key =3D NULL; @@ -676,14 +675,11 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, =20 if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, datastorePath, &key) <= 0) { - goto cleanup; + return NULL; } =20 - volume =3D virGetStorageVol(pool->conn, pool->name, name, key, - &esxStorageBackendVMFS, NULL); - - cleanup: - return volume; + return virGetStorageVol(pool->conn, pool->name, name, key, + &esxStorageBackendVMFS, NULL); } =20 =20 @@ -691,7 +687,6 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, static virStorageVolPtr esxStorageVolLookupByPath(virConnectPtr conn, const char *path) { - virStorageVolPtr volume =3D NULL; esxPrivate *priv =3D conn->privateData; g_autofree char *datastoreName =3D NULL; g_autofree char *directoryAndFileName =3D NULL; @@ -699,19 +694,16 @@ esxStorageVolLookupByPath(virConnectPtr conn, const c= har *path) =20 if (esxUtil_ParseDatastorePath(path, &datastoreName, NULL, &directoryAndFileName) < 0) { - goto cleanup; + return NULL; } =20 if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, path, &key) < 0) { - goto cleanup; + return NULL; } =20 - volume =3D virGetStorageVol(conn, datastoreName, directoryAndFileName,= key, - &esxStorageBackendVMFS, NULL); - - cleanup: - return volume; + return virGetStorageVol(conn, datastoreName, directoryAndFileName, key, + &esxStorageBackendVMFS, NULL); } =20 =20 diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index f1e8339fe0..ef070a4f04 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -429,7 +429,6 @@ esxUtil_EscapeDatastoreItem(const char *string) { g_autofree char *replaced =3D NULL; g_autofree char *escaped1 =3D NULL; - char *escaped2 =3D NULL; =20 replaced =3D g_strdup(string); =20 @@ -438,12 +437,9 @@ esxUtil_EscapeDatastoreItem(const char *string) escaped1 =3D virVMXEscapeHexPercent(replaced); =20 if (!escaped1) - goto cleanup; - - escaped2 =3D esxUtil_EscapeBase64(escaped1); + return NULL; =20 - cleanup: - return escaped2; + return esxUtil_EscapeBase64(escaped1); } =20 =20 diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 2a999f1cc1..db5035c035 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -830,7 +830,6 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *u= rl, const char *ipAddress, const char *username, const char *password, esxUtil_ParsedUri *parsedUri) { - int result =3D -1; g_autofree char *escapedPassword =3D NULL; =20 if (!ctx || !url || !ipAddress || !username || @@ -844,12 +843,12 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char = *url, if (!escapedPassword) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to escape password for XML")); - goto cleanup; + return -1; } =20 if (esxVI_CURL_Alloc(&ctx->curl) < 0 || esxVI_CURL_Connect(ctx->curl, parsedUri) < 0) { - goto cleanup; + return -1; } =20 ctx->url =3D g_strdup(url); @@ -863,18 +862,18 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char = *url, if (virMutexInit(ctx->sessionLock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize session mutex")); - goto cleanup; + return -1; } =20 if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) - goto cleanup; + return -1; =20 if (STRNEQ(ctx->service->about->apiType, "HostAgent") && STRNEQ(ctx->service->about->apiType, "VirtualCenter")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Expecting VI API type 'HostAgent' or 'VirtualCen= ter' " "but found '%s'"), ctx->service->about->apiType); - goto cleanup; + return -1; } =20 if (virParseVersionString(ctx->service->about->apiVersion, @@ -882,14 +881,14 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char = *url, virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not parse VI API version '%s'"), ctx->service->about->apiVersion); - goto cleanup; + return -1; } =20 if (ctx->apiVersion < 1000000 * 2 + 1000 * 5 /* 2.5 */) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Minimum supported %s version is %s but found ver= sion '%s'"), "VI API", "2.5", ctx->service->about->apiVersion); - goto cleanup; + return -1; } =20 if (virParseVersionString(ctx->service->about->version, @@ -897,7 +896,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *u= rl, virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not parse product version '%s'"), ctx->service->about->version); - goto cleanup; + return -1; } =20 if (STREQ(ctx->service->about->productLineId, "gsx")) { @@ -906,7 +905,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *u= rl, _("Minimum supported %s version is %s but found= version '%s'"), esxVI_ProductLineToDisplayName(esxVI_ProductLin= e_GSX), "2.0", ctx->service->about->version); - goto cleanup; + return -1; } =20 ctx->productLine =3D esxVI_ProductLine_GSX; @@ -917,7 +916,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *u= rl, _("Minimum supported %s version is %s but found= version '%s'"), esxVI_ProductLineToDisplayName(esxVI_ProductLin= e_ESX), "3.5", ctx->service->about->version); - goto cleanup; + return -1; } =20 ctx->productLine =3D esxVI_ProductLine_ESX; @@ -927,7 +926,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *u= rl, _("Minimum supported %s version is %s but found= version '%s'"), esxVI_ProductLineToDisplayName(esxVI_ProductLin= e_VPX), "2.5", ctx->service->about->version); - goto cleanup; + return -1; } =20 ctx->productLine =3D esxVI_ProductLine_VPX; @@ -936,7 +935,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *u= rl, _("Expecting product 'gsx' or 'esx' or 'embeddedEsx= ' " "or 'vpx' but found '%s'"), ctx->service->about->productLineId); - goto cleanup; + return -1; } =20 if (ctx->productLine =3D=3D esxVI_ProductLine_ESX) { @@ -957,13 +956,10 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char = *url, =20 if (esxVI_Login(ctx, username, escapedPassword, NULL, &ctx->session) <= 0 || esxVI_BuildSelectSetCollection(ctx) < 0) { - goto cleanup; + return -1; } =20 - result =3D 0; - - cleanup: - return result; + return 0; } =20 int @@ -4093,7 +4089,6 @@ esxVI_HandleVirtualMachineQuestion esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer, bool *blocked) { - int result =3D -1; esxVI_ElementDescription *elementDescription =3D NULL; g_auto(virBuffer) buffer =3D VIR_BUFFER_INITIALIZER; esxVI_ElementDescription *answerChoice =3D NULL; @@ -4136,7 +4131,7 @@ esxVI_HandleVirtualMachineQuestion questionInfo->text); =20 *blocked =3D true; - goto cleanup; + return -1; } else if (!answerChoice) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Pending question blocks virtual machine exec= ution, " @@ -4145,7 +4140,7 @@ esxVI_HandleVirtualMachineQuestion possibleAnswers); =20 *blocked =3D true; - goto cleanup; + return -1; } =20 VIR_INFO("Pending question blocks virtual machine execution, " @@ -4155,7 +4150,7 @@ esxVI_HandleVirtualMachineQuestion =20 if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id, answerChoice->key) < 0) { - goto cleanup; + return -1; } } else { if (possibleAnswers) { @@ -4171,13 +4166,11 @@ esxVI_HandleVirtualMachineQuestion } =20 *blocked =3D true; - goto cleanup; + return -1; } =20 - result =3D 0; + return 0; =20 - cleanup: - return result; } =20 =20 diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 1af075813e..4dc7c30680 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -700,7 +700,6 @@ static int esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType, esxVI_Type *actualType) { - int result =3D -1; g_autofree char *type =3D NULL; =20 if (!actualType || *actualType !=3D esxVI_Type_Undefined) { @@ -724,13 +723,10 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type= baseType, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s 'type' property"), type, esxVI_Type_ToString(baseType)); - goto cleanup; + return -1; } =20 - result =3D 0; - - cleanup: - return result; + return 0; } =20 =20 --=20 2.29.2