From nobody Sun May 19 21:02:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659439654; cv=none; d=zohomail.com; s=zohoarc; b=jQnD0lw6V6q0muYrS2huBoVhUSc9F4+lBC2tNN2nzoyDNPuHbDNOSnxsmZ5g4o1EKJ2GXxDVcM5iVGIUS+5HM+pEVlP78C5O40/yHabGLNGhu2zGm0k4ugdAWVuu5DtlxLJRDIFYLA8x3YitiTI+z20yduF34YbvAM56vIOtpQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659439654; h=Content-Type:Content-Transfer-Encoding:Cc: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=TZ83/2iKBYgUumgQVCnyKZLgWLPFYMPqVj7+h/Iq+ts=; b=BrcjyvT7Uw3lqZVkTIxzy5vMbS6ffICYwZPUFPanixiWTWnIwrFICH/AW8aX0ujJtfFElC3NMKxmDatnBbaklX2QY9bj9ZfeZG4PHax+2PkU4TpnMTpUt9hpkG0Ti4RevkS15CGWPuqpJ88EFez5xe+2SaJAi8HnUqfTaHQrat4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659439654073156.74756006711561; Tue, 2 Aug 2022 04:27:34 -0700 (PDT) Received: from localhost ([::1]:58278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIq3f-0007y7-0q for importer@patchew.org; Tue, 02 Aug 2022 07:27:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIq1L-0004Kb-Cd for qemu-devel@nongnu.org; Tue, 02 Aug 2022 07:25:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:31904) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIq1I-0007Ba-ON for qemu-devel@nongnu.org; Tue, 02 Aug 2022 07:25:07 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-6goJY07LPsqLpb6R5PmlpA-1; Tue, 02 Aug 2022 07:24:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C13A18A0161; Tue, 2 Aug 2022 11:24:53 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB2F42026D07; Tue, 2 Aug 2022 11:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659439496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TZ83/2iKBYgUumgQVCnyKZLgWLPFYMPqVj7+h/Iq+ts=; b=SWkNqukzMNJcbEOmzWNVaVH66auxwHf7yu53jQB93UgRK9wrbVFEs78+TNcFl0LCR3KhDX hViTDu7uOyTth0BCwwGvMvMY8IWngF9prrsTRtQSgvy+Z2UZDZH02SFIuMAbf9Iax1J0uT MxFSYIfp/ckbBjGPLM0kWAEGwjlNPW4= X-MC-Unique: 6goJY07LPsqLpb6R5PmlpA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Peter Maydell , qemu-trivial@nongnu.org, Jason Wang , "Michael S . Tsirkin" Subject: [PATCH 1/2] vdpa: Fix file descriptor leak on get features error Date: Tue, 2 Aug 2022 13:24:46 +0200 Message-Id: <20220802112447.249436-2-eperezma@redhat.com> In-Reply-To: <20220802112447.249436-1-eperezma@redhat.com> References: <20220802112447.249436-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659439654752100003 File descriptor vdpa_device_fd is not free in the case of returning error from vhost_vdpa_get_features. Fixing it by making all errors go to the same error path. Resolves: Coverity CID 1490785 Fixes: 8170ab3f43 ("vdpa: Extract get features part from vhost_vdpa_get_max= _queue_pairs") Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Laurent Vivier Reviewed-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6abad276a6..303447a68e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -566,7 +566,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, g_autofree NetClientState **ncs =3D NULL; g_autoptr(VhostIOVATree) iova_tree =3D NULL; NetClientState *nc; - int queue_pairs, r, i, has_cvq =3D 0; + int queue_pairs, r, i =3D 0, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -582,7 +582,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, =20 r =3D vhost_vdpa_get_features(vdpa_device_fd, &features, errp); if (unlikely(r < 0)) { - return r; + goto err; } =20 queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, feature= s, --=20 2.31.1 From nobody Sun May 19 21:02:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659439637; cv=none; d=zohomail.com; s=zohoarc; b=N5nD3Tf7D71yywstlAolcjrBJ3nQfqsYxpD73w1FU3BV+agcOpQOT8230ecVSAIKV34OBUP3sv3+GqdOhoaVw2qOl1uhwVXF46pGmHOLPQuue9oAv55n/E6kFHeTMuYkrPas3e0D4AzAyus4fEsis7ZDsAq6MlG7DAycjUiCnBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659439637; h=Content-Type:Content-Transfer-Encoding:Cc: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=HBmdb2nVaXkPu/i1BQa972mRLyq1hHMLWo9xO7GswXE=; b=j1Tcnsxw/wdrVRijAf7H/xKNmzVSgzrFQuBjfhBMKRHXLnQzwzgVysJ0+1bOV4PUdQkjqe2HZnPtfUiRvYQuoZU9KSbrhKPLI1KEZBAnDjLY182ouAMPrFClSh/MBjyK6zh2VI2TtHVL5qDb+yRLQ0IrbVTFOsbMwfa177/KpEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659439637101486.1034784922581; Tue, 2 Aug 2022 04:27:17 -0700 (PDT) Received: from localhost ([::1]:57334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIq3P-0007Hq-Km for importer@patchew.org; Tue, 02 Aug 2022 07:27:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIq1L-0004Kc-Cb for qemu-devel@nongnu.org; Tue, 02 Aug 2022 07:25:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIq1H-0007Bk-GI for qemu-devel@nongnu.org; Tue, 02 Aug 2022 07:25:06 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-s2GnBqb4O0WiF-X48kkgRw-1; Tue, 02 Aug 2022 07:24:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8BBE8811E75; Tue, 2 Aug 2022 11:24:54 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64D672026D4C; Tue, 2 Aug 2022 11:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659439498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HBmdb2nVaXkPu/i1BQa972mRLyq1hHMLWo9xO7GswXE=; b=L0F29umTbukV+5R32DNjlNXmEAW4B0Qa19bqpxfNDWYJmhFqGN1Cexm9QaNBDH1aRPwF7U yOTAcrFgC1JPICux33Tk/u1jSHZjtx/kYjrGhbAe4ycFPl9R1WS7DIw7cHzTp2P3fc5chi uGRPW7ssf0hKhSswVRju9l2x+HYX0xc= X-MC-Unique: s2GnBqb4O0WiF-X48kkgRw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Peter Maydell , qemu-trivial@nongnu.org, Jason Wang , "Michael S . Tsirkin" Subject: [PATCH 2/2] vdpa: Merge all net_init_vhost_vdpa error goto Date: Tue, 2 Aug 2022 13:24:47 +0200 Message-Id: <20220802112447.249436-3-eperezma@redhat.com> In-Reply-To: <20220802112447.249436-1-eperezma@redhat.com> References: <20220802112447.249436-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659439638646100001 Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one. Signed-off-by: Eugenio P=C3=A9rez Reviewed-by: Laurent Vivier Reviewed-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 303447a68e..ac1810723c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, feature= s, &has_cvq, errp); if (queue_pairs < 0) { - qemu_close(vdpa_device_fd); - return queue_pairs; + goto err; } =20 if (opts->x_svq) { @@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, if (invalid_dev_features) { error_setg(errp, "vdpa svq does not work with features 0x%" PR= Ix64, invalid_dev_features); - goto err_svq; + goto err; } =20 vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); @@ -640,7 +639,6 @@ err: } } =20 -err_svq: qemu_close(vdpa_device_fd); =20 return -1; --=20 2.31.1