From nobody Mon Apr 29 11:45:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518190187247123.81126587381914; Fri, 9 Feb 2018 07:29:47 -0800 (PST) Received: from localhost ([::1]:33362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAcS-0005UG-8n for importer@patchew.org; Fri, 09 Feb 2018 10:29:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAXI-0001bf-GT for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:24:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekAXH-0007Zn-Ht for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:24:24 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50270 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekAX9-0007Sg-P2; Fri, 09 Feb 2018 10:24:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58C6C40FB630; Fri, 9 Feb 2018 15:24:15 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-203.ams2.redhat.com [10.36.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1F81101307D; Fri, 9 Feb 2018 15:24:12 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 9 Feb 2018 16:24:12 +0100 Message-Id: <20180209152412.23626-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Feb 2018 15:24:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Feb 2018 15:24:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] block/nvme: fix Coverity reports X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 1) string not null terminated in sysfs_find_group_file 2) NULL pointer dereference and dead local variable in nvme_init. Signed-off-by: Paolo Bonzini --- block/nvme.c | 14 ++++++-------- util/vfio-helpers.c | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e9d0e218fc..ce217ffc81 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -553,7 +553,6 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, uint64_t cap; uint64_t timeout_ms; uint64_t deadline, now; - Error *local_err =3D NULL; =20 qemu_co_mutex_init(&s->dma_map_lock); qemu_co_queue_init(&s->dma_flush_queue); @@ -645,11 +644,6 @@ static int nvme_init(BlockDriverState *bs, const char = *device, int namespace, false, nvme_handle_event, nvme_poll_cb); =20 nvme_identify(bs, namespace, errp); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EIO; - goto fail_handler; - } =20 /* Set up command queues. */ if (!nvme_add_io_queue(bs, errp)) { @@ -665,8 +659,12 @@ fail_queue: nvme_free_queue_pair(bs, s->queues[0]); fail: g_free(s->queues); - qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE); - qemu_vfio_close(s->vfio); + if (s->regs) { + qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_S= IZE); + } + if (s->vfio) { + qemu_vfio_close(s->vfio); + } event_notifier_cleanup(&s->irq_notifier); return ret; } diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index f478b68400..006674c916 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -104,7 +104,7 @@ static char *sysfs_find_group_file(const char *device, = Error **errp) char *path =3D NULL; =20 sysfs_link =3D g_strdup_printf("/sys/bus/pci/devices/%s/iommu_group", = device); - sysfs_group =3D g_malloc(PATH_MAX); + sysfs_group =3D g_malloc0(PATH_MAX); if (readlink(sysfs_link, sysfs_group, PATH_MAX - 1) =3D=3D -1) { error_setg_errno(errp, errno, "Failed to find iommu group sysfs pa= th"); goto out; --=20 2.14.3