From nobody Mon Feb 9 01:48:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1564561955; cv=none; d=zoho.com; s=zohoarc; b=ALAwh9/i4FGy5wZl2lDZk1xPwIyBje9Tu1dAWRYLuViReyPOnrKXvMoL5JbnOuPV14Crv4aP+i4sc4tVZvB5cIwl7lavfkO6erL0JobdB1y17PWJlBcvkqvwurZCBOFP6oBWkf27uwaXPU4A0LidQj8IZD0joLdEpk9vxCKe7Ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564561955; 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:ARC-Authentication-Results; bh=sb13M90SxENTluzcSyyGczdFMzZFkmD1vMCUB4ACbt8=; b=P6QA1SHQ4ziBIV1V6VMzr4NFcGFpTO4EKFMjmqakBUeb2DGrlwQBH0cLe6IuZ9VR9eZcMXKwY6mNRSxHw7E8VL76+DiNtbzWyTn6WO91M3slZS8/Rzg5k6NQx6GJU713MxPlI+o+PHHDE7GBqJ3GpxawQkisdTZdgCOyanulrrE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1564561955544100.29786247812353; Wed, 31 Jul 2019 01:32:35 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0E26181F31; Wed, 31 Jul 2019 08:32:34 +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 D7B205D9E1; Wed, 31 Jul 2019 08:32:33 +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 5C0B7180B536; Wed, 31 Jul 2019 08:32:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6V8WU73027374 for ; Wed, 31 Jul 2019 04:32:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id A7B6B5D712; Wed, 31 Jul 2019 08:32:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 333785D70D for ; Wed, 31 Jul 2019 08:32:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 31 Jul 2019 10:32:20 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] virPCIDeviceNew: Prefer VIR_RETURN_PTR 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 31 Jul 2019 08:32:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function declares @ret variable and then uses VIR_STEAL_PTR() to avoid freeing temporary variable @dev which is constructed. Well, as of 267f1e6da53 we have VIR_RETURN_PTR() macro so that we can avoid this pattern. Signed-off-by: Michal Privoznik --- src/util/virpci.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 6dc0a2711c..1a3d316399 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1749,7 +1749,6 @@ virPCIDeviceNew(unsigned int domain, unsigned int slot, unsigned int function) { - virPCIDevicePtr ret =3D NULL; VIR_AUTOPTR(virPCIDevice) dev =3D NULL; VIR_AUTOFREE(char *) vendor =3D NULL; VIR_AUTOFREE(char *) product =3D NULL; @@ -1767,17 +1766,17 @@ virPCIDeviceNew(unsigned int domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("dev->name buffer overflow: %.4x:%.2x:%.2x.%.1x"), domain, bus, slot, function); - goto cleanup; + return NULL; } if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config", dev->name) < 0) - goto cleanup; + return NULL; =20 if (!virFileExists(dev->path)) { virReportSystemError(errno, _("Device %s not found: could not access %s"), dev->name, dev->path); - goto cleanup; + return NULL; } =20 vendor =3D virPCIDeviceReadID(dev, "vendor"); @@ -1787,7 +1786,7 @@ virPCIDeviceNew(unsigned int domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to read product/vendor ID for %s"), dev->name); - goto cleanup; + return NULL; } =20 /* strings contain '0x' prefix */ @@ -1796,15 +1795,12 @@ virPCIDeviceNew(unsigned int domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("dev->id buffer overflow: %s %s"), &vendor[2], &product[2]); - goto cleanup; + return NULL; } =20 VIR_DEBUG("%s %s: initialized", dev->id, dev->name); =20 - VIR_STEAL_PTR(ret, dev); - - cleanup: - return ret; + VIR_RETURN_PTR(dev); } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list