From nobody Sat Feb 7 09:59:15 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; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1612180043; cv=none; d=zohomail.com; s=zohoarc; b=LhGg3IkyTOZRdtCdLSnBv1hxhkT9U55/VWYqxgP0LOL/kKgSt65IT3gj+2DMcnTC4vVFolvanqi0Iv3k1fhpfWVTLKbwA2D7mFTzpYoU7AuGEnq2pF3O8SECSqDbzeJD1uUSDh0S/3mj/Qhq7oVjYkOFWUrh3cvTt7Non/mj5u8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180043; 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=Iy9ULqnIm3gnWkB6tP0q7WW+Z4qltrn1rzXVMVHJZns=; b=RJeL33FehbAc6Qy1JZE4dmfShbSYQ/gONjkDYMJm1kxIU/VedpH2NFoKJQO9RFSd0NhhVFiebZgn3O48+UtKgT6YqwQOf34GjlG8dYa3DqU8Hyrf/t/IWyekMKm5K9B2wCXxNYbvt2mh5Bymhgv9tcHbiISjHRoSE3or97h7rhw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail 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 1612180043460384.2819727087042; Mon, 1 Feb 2021 03:47:23 -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-494-MWNW_9itM6-QhP47-rfYMA-1; Mon, 01 Feb 2021 06:47:20 -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 2ACBE107ACE4; Mon, 1 Feb 2021 11:47:15 +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 079391346F; Mon, 1 Feb 2021 11:47:15 +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 C495950040; Mon, 1 Feb 2021 11:47:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111Bl8Ef005798 for ; Mon, 1 Feb 2021 06:47:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id E49422166B2A; Mon, 1 Feb 2021 11:47:07 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF0962166B27 for ; Mon, 1 Feb 2021 11:47:03 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72711101A562 for ; Mon, 1 Feb 2021 11:47:03 +0000 (UTC) Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-vHBx22jgOVmUQxz_PIx3Bw-1; Mon, 01 Feb 2021 06:47:01 -0500 Received: by mail-qv1-f45.google.com with SMTP id u16so7931160qvo.9 for ; Mon, 01 Feb 2021 03:47:00 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:59 -0800 (PST) X-MC-Unique: MWNW_9itM6-QhP47-rfYMA-1 X-MC-Unique: vHBx22jgOVmUQxz_PIx3Bw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Iy9ULqnIm3gnWkB6tP0q7WW+Z4qltrn1rzXVMVHJZns=; b=JfNGmh7ZWQ5jObFrYQ8K8cEUSXwL0iT/6cqjQlRqFVaRtPbiSQn7rtTiljj4A3limH u3bPSz58doygzqGyPRmYqETP772ROf9VcVjGODVItf0SVR5jAmtV+R5YcTR8cIGjObQE LYq7ET2jClOXqA+qkf2f8nm6I0k7PFqwk1vNG/xVnCEYCGeQhRREMEezr0VWHWpnLsj4 fgIsbPVr4J+aojlp1bsezbIzah1LFgcy01nmptiKkIocnwimeSgLpIPmfRxggShh2v/i iWl4aa+jt9kmJiH8UfRPh9bSzI5TlnBg6/PYJJlSgMOm/UTUA72e5VFb+v7Vi/fJVGI+ EVFA== X-Gm-Message-State: AOAM530M1qaKtgf0zike25f3mZApt8bPrS5KxCYfBuAe8GBTJB7lsE1i 1XqN+t6+SweJvjvY2x9aWgbRuMVGGy8= X-Google-Smtp-Source: ABdhPJx5xCOkZCitd3VAcykaFy3iYR+h2lIxRJTLB10RnUZeiIncWit88uA+l/AnIPXhgjHMnix9tw== X-Received: by 2002:a0c:f986:: with SMTP id t6mr14910502qvn.15.1612180020290; Mon, 01 Feb 2021 03:47:00 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 7/9] qemu_driver.c: validate 'driverName' earlier in qemuNodeDeviceDetachFlags() Date: Mon, 1 Feb 2021 08:46:40 -0300 Message-Id: <20210201114642.1947595-8-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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 Content-Type: text/plain; charset="utf-8" The validation of 'driverName' does not depend on any other state and can be done right on the start of the function. We can fail earlier while avoiding a cleanup jump. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 64ae8fafc0..c6ba33e4ad 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11982,6 +11982,25 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, =20 virCheckFlags(0, -1); =20 + if (!driverName) + driverName =3D "vfio"; + + if (STREQ(driverName, "vfio") && !vfio) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("VFIO device assignment is currently not " + "supported on this system")); + return -1; + } else if (STREQ(driverName, "kvm")) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("KVM device assignment is no longer " + "supported on this system")); + return -1; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown driver name '%s'"), driverName); + return -1; + } + if (!(nodeconn =3D virGetConnectNodeDev())) goto cleanup; =20 @@ -12013,27 +12032,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (!pci) goto cleanup; =20 - if (!driverName) - driverName =3D "vfio"; - - if (STREQ(driverName, "vfio")) { - if (!vfio) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("VFIO device assignment is currently not " - "supported on this system")); - goto cleanup; - } - virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); - } else if (STREQ(driverName, "kvm")) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("KVM device assignment is no longer " - "supported on this system")); - goto cleanup; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown driver name '%s'"), driverName); - goto cleanup; - } + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); =20 ret =3D virHostdevPCINodeDeviceDetach(hostdev_mgr, pci); cleanup: --=20 2.26.2