From patchwork Mon Dec 13 11:15:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 12673767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 713DEC433F5 for ; Mon, 13 Dec 2021 11:24:55 +0000 (UTC) Received: from localhost ([::1]:44260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwjRu-0001Bk-Dj for qemu-devel@archiver.kernel.org; Mon, 13 Dec 2021 06:24:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwjJW-0008WI-Fs for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:15 -0500 Received: from [2a00:1450:4864:20::52f] (port=37457 helo=mail-ed1-x52f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwjJT-0007Fp-9j for qemu-devel@nongnu.org; Mon, 13 Dec 2021 06:16:13 -0500 Received: by mail-ed1-x52f.google.com with SMTP id e3so51520323edu.4 for ; Mon, 13 Dec 2021 03:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7sBF+Qy7/vzAjQ+8VJmnouHX5HxqVw+CgpLyJxT4k1k=; b=NRqDmXorx8tsujvCUJOAt/z7zgkL29eL4O4bpgM4Jotg4Odx33X2p3ICUmSNY25cv2 7QiMBSXHb8+9mxMzhGEWp1CBfZyLYA+H0PQhWTyZM5rWU+BxB2v96CdHZlBT5V8IHhge qhDFaBb6UajJ+aVArA4oMW6+cwqMU8CcxErYZ67uyd0pcPZRQ8Q0Y9yfXfWXre//FeC3 pZhUaxXf/6P7/flMfdladYBnrcN83yydG0Z7nKqsQCaPHC3ogViFcFy97t+i8bD2PRyl gAKrynHNg18+VZiqKmh0rJ+1qteb8ZCCFuYKswbNPK7m6GaOGtbunRzDMh/0Gl4h1Lxv PF1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7sBF+Qy7/vzAjQ+8VJmnouHX5HxqVw+CgpLyJxT4k1k=; b=d2jCkqup0l0JLy8+bC7xyblnMqLOvrssxpX4ZwnWWkx0zMsYrT0f5BrHOaMzvqR4vM b4z8CoBBdI4ZfKZHxmgEcHDEinP8UnQAdxsHgPf/tyoL70Jk/BQMUfzEhX0Qx8AyEuP+ 6DjOEFvMepxjgKdA2nz6+MqZsyGN3PVpEWbGauEXNg+cVTaadJ4uW2sIyy3TQEACa1Z/ aKliwry1SWxg+W3cZjQpCASIPYDz7Q439TWOYCgKpnSBBlt3UO9QnpJisjWBmnl9Le5p jSzxw61LJsOounnGY8LlhBn78IsDJbmLHm7v0N9butENCse6+wO1Mm7m4Lm5UGIE2bPW gz4g== X-Gm-Message-State: AOAM5304vP+LY8Wc+kqYpb3WE+DY4Mvei4ubxoEsZU6exsBRApFvIVhj tA9MR9a2v36Tcf43ETihPbReaKKfS90unw== X-Google-Smtp-Source: ABdhPJyxaZbWeHq0nWOg9jKWpG8hywPhAzhu9QiMaeVHylK8lEQW3sxZtullFO5O//WCL5dFYhh54A== X-Received: by 2002:aa7:d748:: with SMTP id a8mr63669081eds.21.1639394169212; Mon, 13 Dec 2021 03:16:09 -0800 (PST) Received: from kostyanf14nb.Dlink ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id a13sm6139384edk.29.2021.12.13.03.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 03:16:08 -0800 (PST) From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Michael Roth , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 4/5] gqa-win: get_pci_info: Replace 'while' with 2 calls of the function Date: Mon, 13 Dec 2021 13:15:53 +0200 Message-Id: <20211213111554.62394-5-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213111554.62394-1-konstantin@daynix.com> References: <20211213111554.62394-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52f (failed) Received-SPF: none client-ip=2a00:1450:4864:20::52f; envelope-from=konstantin@daynix.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Microsoft suggests this solution in the documentation: https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupdigetdeviceinterfacedetaila Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index cef14a8762..6bde5260e8 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -552,10 +552,10 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) if (SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, &GUID_DEVINTERFACE_DISK, 0, &dev_iface_data)) { - while (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, - pdev_iface_detail_data, - size, &size, - &dev_info_data)) { + if (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, + pdev_iface_detail_data, + size, &size, + &dev_info_data)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { pdev_iface_detail_data = g_malloc(size); pdev_iface_detail_data->cbSize = @@ -567,6 +567,16 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } } + if (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_data, + pdev_iface_detail_data, + size, &size, + &dev_info_data)) { + // pdev_iface_detail_data already is allocated + error_setg_win32(errp, GetLastError(), + "failed to get device interfaces"); + goto cleanup; + } + dev_file = CreateFile(pdev_iface_detail_data->DevicePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); @@ -597,8 +607,8 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) ULONG dev_id_size = 0; size = 0; - while (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, - parent_dev_id, size, &size)) { + if (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, + parent_dev_id, size, &size)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { parent_dev_id = g_malloc(size); } else { @@ -608,6 +618,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } } + if (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, + parent_dev_id, size, &size)) { + // parent_dev_id already is allocated + error_setg_win32(errp, GetLastError(), + "failed to get device instance ID"); + goto cleanup; + } + /* * CM API used here as opposed to * SetupDiGetDeviceProperty(..., DEVPKEY_Device_Parent, ...)