From patchwork Tue Dec 14 12:41:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 1567724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20210112.gappssmtp.com header.i=@daynix-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=ykj18jfn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCysW6vbLz9s3q for ; Tue, 14 Dec 2021 23:50:39 +1100 (AEDT) Received: from localhost ([::1]:52330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx7GP-00087u-Kh for incoming@patchwork.ozlabs.org; Tue, 14 Dec 2021 07:50:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx77U-0001ni-5X for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:25 -0500 Received: from [2a00:1450:4864:20::531] (port=34560 helo=mail-ed1-x531.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx77Q-0004bG-So for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:22 -0500 Received: by mail-ed1-x531.google.com with SMTP id x15so63504298edv.1 for ; Tue, 14 Dec 2021 04:41:20 -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=UOq7HXf+K8oMudzzz7NHQ+jQVflm2qA+bj7AzU+PASI=; b=ykj18jfn+i5yELX7qLNrB1fWm6daiqqzoH0PPG0x0fWVckYn5oJAhs61jn+sezDO9u 1mfYuOsCU7UidIapHHi1yauco7RVllb4o4LoHPCZvYp2rAazIJxNRCq5r/StbxJy2oou SZnyCvWlAYaZ0jXFa9yG++WkiDrApP2usyQSMIWR+VjsRMTPJT9OdNZYgwEmgA5KAiSK c+3Sr/as6F06aLlWaJM+eCCBUxaQdUdzHx8eoSc5HwWOboUlCc+r0whxt6xwBvV5omQ6 C8GVUBulaS7jfQwQ5DoOQYQ341voNE6j+JRj/HZf2+jns+pkTwYC+6QtamjXHog/JfiV PV2Q== 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=UOq7HXf+K8oMudzzz7NHQ+jQVflm2qA+bj7AzU+PASI=; b=0iPPEP5jvsMBYXt0G3Z8fQePyRzZBBCsIvp1dlSYp+cM4kWdWZT3GLOWBixFU4A+9Z gKbp6BGcjI1J1ax9b3rLNROuDR9kpQO7BoeLoos9q1U4Z3Va06FncZzuFTwLkeFALdCd Xo0/0K2yzvB5CNMEGSsjBsSdNuNHSO+A0F3zxmgyl32JsRkPE+h/GTQQcmwn+RylQ+RY CifWFBh+Eri2mXsmMqWUKX1qohjA+ZGzt2MMRNFJvZ11gYE4TAVWscmS5te0oiszMT6v VMAo86Z4j2v/dTj25HXWaIyC61n88uQ6vqKtrI++M/8w34aDNTcEjLQKlr5j6tc9PIDy CA5w== X-Gm-Message-State: AOAM531LupPGncoVVl5sieqG5HWkJzJJBa8ns9dd9PUej+RJHqy0el2x 9Fd/efuZfxX395X6XUTDK7zBd8QTeVmzvqpf X-Google-Smtp-Source: ABdhPJzObnOo6O67XxBlh20xziH5L8t0Tvp2lTFSOGu31LB9DSt7Ixae5XlQXv9/FGpq6HarfjIs1A== X-Received: by 2002:a05:6402:8d0:: with SMTP id d16mr7404570edz.403.1639485677696; Tue, 14 Dec 2021 04:41:17 -0800 (PST) Received: from localhost.localdomain ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id e4sm1025351ejl.196.2021.12.14.04.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 04:41:17 -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 v2 1/6] gqa-win: get_pci_info: Clean dev_info if handle is valid Date: Tue, 14 Dec 2021 14:41:04 +0200 Message-Id: <20211214124109.103102-2-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214124109.103102-1-konstantin@daynix.com> References: <20211214124109.103102-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::531 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::531; envelope-from=konstantin@daynix.com; helo=mail-ed1-x531.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4e84afd83b..3dd74fe225 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -514,7 +514,7 @@ DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT, static GuestPCIAddress *get_pci_info(int number, Error **errp) { - HDEVINFO dev_info; + HDEVINFO dev_info = INVALID_HANDLE_VALUE; SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DATA dev_iface_data; HANDLE dev_file; @@ -749,7 +749,9 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } free_dev_info: - SetupDiDestroyDeviceInfoList(dev_info); + if (dev_info != INVALID_HANDLE_VALUE) { + SetupDiDestroyDeviceInfoList(dev_info); + } out: return pci; } From patchwork Tue Dec 14 12:41:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 1567719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20210112.gappssmtp.com header.i=@daynix-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=dETOUBtL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCykJ26qTz9sXM for ; Tue, 14 Dec 2021 23:44:24 +1100 (AEDT) Received: from localhost ([::1]:43508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx7AM-0001q5-48 for incoming@patchwork.ozlabs.org; Tue, 14 Dec 2021 07:44:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx77U-0001nn-A3 for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:26 -0500 Received: from [2a00:1450:4864:20::531] (port=40632 helo=mail-ed1-x531.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx77Q-0004bF-Sv for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:23 -0500 Received: by mail-ed1-x531.google.com with SMTP id r25so62031695edq.7 for ; Tue, 14 Dec 2021 04:41:20 -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=7pcB4DRk1ERh5GRKO+vkAyITUzW1FVVPgQ5iX8HuiIg=; b=dETOUBtLN9MZUX7zXQ+ZD1sg+Tvh5l2KtPqBr2FDBV57j3GCJ9VrkKKb9yO0JDwOYZ 2YG0LxZcXKf8O2+UVOGrNpBevX9EQI64B3wP7MqjxNuf6IcjFYXSJxZGUymyBLvzidjo SQF4uhjH2ucF+kW0LFwGBUrWENSaXYPrfSEspEd0xyMkbb1Relg8Whr4PTnn0wlbgxRc ttKQHu1/l+2Y8Lw0RYY9LjsdZHi/woxFUKZr7ctCDMaQzL6sxpGlZWPyJJknEKJvDvBv i2ITG6pTn30v27gmo0hbAEpduuvcb+Poa0UwiGjZ8clHozkoNQhVFQw+kdqVy/hSmTLM 0TVw== 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=7pcB4DRk1ERh5GRKO+vkAyITUzW1FVVPgQ5iX8HuiIg=; b=32B3tDx+raTkJigp3amsQKIAV+sDnN1kpDomW8BOg6K2Pby1qGVKEQuzT1V15q2y6X k7Bkez9UvSzpKjlT7JWVXvpYzsRKEyvj+LkkAa99QUKBNZjCBI/7u3HTu9Y8ebopk5eA 46gH0UEC6yGzLcYevfJQJK/2OzzvYM1Gq27zf6/8FVkjkaTd8nFhJ0RC1tR2kxfrLw3g sF1JgJimeGd9AV/J8UC+ax0td8w+AdGsd0Qsk2xHRkm0l0h/E3utd4YPKF+eTVpN8ogs BZDRwiIxLe4MQaqmBPdcdKogZ6Aqy27qV2OusoV4vLLiNpV3FlOkfIvaGk7/mH8UmRnn 2XXA== X-Gm-Message-State: AOAM532Qbh738qMV1IVAqYX8prI33M+9Vtk/sN0hRDfkZC6frQRQ2EuU aAkzdy0kN6cCAkhEPH1ym5W+T3JIJSvG+hKp X-Google-Smtp-Source: ABdhPJxLp7IcbKSxd1nntQLT937LIhY0gZE8uqGGGn5nURR8QtTML1yy3jRq6sLVvx+l+bOy4Ppmqw== X-Received: by 2002:a50:ce51:: with SMTP id k17mr7521261edj.356.1639485678610; Tue, 14 Dec 2021 04:41:18 -0800 (PST) Received: from localhost.localdomain ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id e4sm1025351ejl.196.2021.12.14.04.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 04:41:18 -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 v2 2/6] gqa-win: get_pci_info: Use common 'end' label Date: Tue, 14 Dec 2021 14:41:05 +0200 Message-Id: <20211214124109.103102-3-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214124109.103102-1-konstantin@daynix.com> References: <20211214124109.103102-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::531 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::531; envelope-from=konstantin@daynix.com; helo=mail-ed1-x531.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" To prevent memory leaks, always try to free initialized variables. Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 3dd74fe225..93c5375132 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -532,7 +532,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to get devices tree"); - goto out; + goto end; } g_debug("enumerating devices"); @@ -562,7 +562,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } else { error_setg_win32(errp, GetLastError(), "failed to get device interfaces"); - goto free_dev_info; + goto end; } } @@ -576,7 +576,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) CloseHandle(dev_file); error_setg_win32(errp, GetLastError(), "failed to get device slot number"); - goto free_dev_info; + goto end; } CloseHandle(dev_file); @@ -586,7 +586,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } else { error_setg_win32(errp, GetLastError(), "failed to get device interfaces"); - goto free_dev_info; + goto end; } g_debug("found device slot %d. Getting storage controller", number); @@ -603,7 +603,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) } else { error_setg_win32(errp, GetLastError(), "failed to get device instance ID"); - goto out; + goto end; } } @@ -617,14 +617,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) g_error("CM_Locate_DevInst failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get device instance"); - goto out; + goto end; } cr = CM_Get_Parent(&parent_dev_inst, dev_inst, 0); if (cr != CR_SUCCESS) { g_error("CM_Get_Parent failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get parent device instance"); - goto out; + goto end; } cr = CM_Get_Device_ID_Size(&dev_id_size, parent_dev_inst, 0); @@ -632,7 +632,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) g_error("CM_Get_Device_ID_Size failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get parent device ID length"); - goto out; + goto end; } ++dev_id_size; @@ -647,7 +647,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) g_error("CM_Get_Device_ID failed with code %lx", cr); error_setg_win32(errp, GetLastError(), "failed to get parent device ID"); - goto out; + goto end; } } @@ -661,14 +661,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) if (parent_dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to get parent device"); - goto out; + goto end; } parent_dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); if (!SetupDiEnumDeviceInfo(parent_dev_info, 0, &parent_dev_info_data)) { error_setg_win32(errp, GetLastError(), "failed to get parent device data"); - goto out; + goto end; } for (j = 0; @@ -748,11 +748,10 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) break; } -free_dev_info: +end: if (dev_info != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(dev_info); } -out: return pci; } From patchwork Tue Dec 14 12:41:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 1567718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20210112.gappssmtp.com header.i=@daynix-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=cAhTbJCB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCykF2YbRz9sXM for ; Tue, 14 Dec 2021 23:44:21 +1100 (AEDT) Received: from localhost ([::1]:43554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx7AI-0001rz-TX for incoming@patchwork.ozlabs.org; Tue, 14 Dec 2021 07:44:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx77U-0001nm-9w for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:26 -0500 Received: from [2a00:1450:4864:20::530] (port=43710 helo=mail-ed1-x530.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx77R-0004bM-17 for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:23 -0500 Received: by mail-ed1-x530.google.com with SMTP id o20so62933638eds.10 for ; Tue, 14 Dec 2021 04:41:20 -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=ozLp8qidPWvcuUkEzZS3Ucr/MZjXiK9zmEUDFCSdFOY=; b=cAhTbJCBGxsbLlVqFZd0fvHZ3zMUxStRUIkb/lUHZSgNIysgVdJHh51xJBSG3FwTpU 66dwTOaGlxujUZ0T7z3SMM7A91+jY7pnu4g6/KsleQyxmMowLovTdfQuQ1q2BlP6xu5N nslLQ3t44tdzE3waLTwL9pNlY1dluUw13w0Ae0KKydS26P7UkJ/0i4d088qnJ4z4P/Yv 6HtSFyD1MQglF1xlh48M8fFrZlAifY6VOFLQ8FS/vvSeKo/Cqttx4aXV3nF4i0XER611 Jh5JnyvyZ/+o1oBpS9T7AJKZ8vlpVJ+XkV6eErf9O49XbsFXOrSDlkMz2ukIXHkeAl6T 96mA== 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=ozLp8qidPWvcuUkEzZS3Ucr/MZjXiK9zmEUDFCSdFOY=; b=U800akB/KJeUIswz1i9d3Wji6WRrRFMucH0xYO0GRSR8Eyji05cCtuvma4ue2VsL26 YZd7QbB/obOvuNqhfYnZkm34oep+QJQ3BJUUsb1ysM2sOmSf5S9Nc3n6TTpvgIdbOb1h 9U1sGg28OLr7K9HssoSjgAwN/MUF60FBPbLg0pFlKmr6tnmna9BYsuecNwE1ScGb5Bpe yQl+8AvxvLC2IKW0tC3HceG5hNgEr2HoGA9azsDajTXAR2Bt1B5QqBet0pWM8HfN8wsO 1IAfr+AdC0mdXltRMfikR9JsvavoSkqb+VKbv6UHMdZ3Lt0l1858T0f8UR5sjt7p3OBk Gd/g== X-Gm-Message-State: AOAM533yK7Sdap2xw+O84+xqihqc7UQP1zCXFUYGGbHBMe6xOtg0gGjR 7Dusqv2lve1Q45EBWGUeZ+9zPLOpodBsJFcD X-Google-Smtp-Source: ABdhPJw+7v5x8kt0wfD+96MlgHrjIu55gNXjYHREu9l3ci4qDo1UST3OmR35RwPYVgxc0Q5tErZrIw== X-Received: by 2002:a05:6402:174c:: with SMTP id v12mr7679375edx.168.1639485679516; Tue, 14 Dec 2021 04:41:19 -0800 (PST) Received: from localhost.localdomain ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id e4sm1025351ejl.196.2021.12.14.04.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 04:41:19 -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 v2 3/6] gqa-win: get_pci_info: Free parent_dev_info properly Date: Tue, 14 Dec 2021 14:41:06 +0200 Message-Id: <20211214124109.103102-4-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214124109.103102-1-konstantin@daynix.com> References: <20211214124109.103102-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::530 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::530; envelope-from=konstantin@daynix.com; helo=mail-ed1-x530.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In case when the function fails to get parent device data, the parent_dev_info variable will be initialized, but not freed. Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 93c5375132..f6de9e2676 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -515,6 +515,8 @@ DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT, static GuestPCIAddress *get_pci_info(int number, Error **errp) { HDEVINFO dev_info = INVALID_HANDLE_VALUE; + HDEVINFO parent_dev_info = INVALID_HANDLE_VALUE; + SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DATA dev_iface_data; HANDLE dev_file; @@ -542,7 +544,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL; STORAGE_DEVICE_NUMBER sdn; char *parent_dev_id = NULL; - HDEVINFO parent_dev_info; SP_DEVINFO_DATA parent_dev_info_data; DWORD j; DWORD size = 0; @@ -744,11 +745,13 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) break; } } - SetupDiDestroyDeviceInfoList(parent_dev_info); break; } end: + if (parent_dev_info != INVALID_HANDLE_VALUE) { + SetupDiDestroyDeviceInfoList(parent_dev_info); + } if (dev_info != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(dev_info); } From patchwork Tue Dec 14 12:41:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 1567721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20210112.gappssmtp.com header.i=@daynix-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=G+Y6mGFz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCyp14TZDz9sRR for ; Tue, 14 Dec 2021 23:47:36 +1100 (AEDT) Received: from localhost ([::1]:48152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx7DR-0005Fp-5E for incoming@patchwork.ozlabs.org; Tue, 14 Dec 2021 07:47:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx77W-0001pC-JQ for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:28 -0500 Received: from [2a00:1450:4864:20::534] (port=44585 helo=mail-ed1-x534.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx77S-0004bz-DC for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:26 -0500 Received: by mail-ed1-x534.google.com with SMTP id z7so1399440edc.11 for ; Tue, 14 Dec 2021 04:41:22 -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=f/W7/VwO6j4MnJ8SawZpEZqcFMZTX0S/EkbM3JmnkUI=; b=G+Y6mGFzyasbSG/WTgEjtjdRYUUl30q98Py3m1zQVKebAOZwwj5r91pLc2kf74ho+m ZahdBv/h7MJzY4C6DL1UplQaE8ZI7h9mV2cpx7s/AUjvvTQiCQedPPcSEVvakefT2tUj Hs6Ey04DjtZtGbp0a0jiwRd+f1VQkXRwPwjPVx06GU0NoIEkV91GaCV1BcFJ9Sv8EC4p Nuq9sAvQmCj3meijMAzG1TYlnjRStkEpbVRzvzAc30wqbB+zi2ewPlzozoicc0hyiEAY Yp/OYbTdj6iXZpvKpWV8LPQDPQ+164uEygnDC9HIsfbY76j6IaN1IiIoRZ4wy85O0CRI b+QA== 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=f/W7/VwO6j4MnJ8SawZpEZqcFMZTX0S/EkbM3JmnkUI=; b=XfOP7XaATnIAn47+EPxMEvRCz34OJ8E7Wk/zcWCXHMgUipENJBvkv6H2Z50nWJ3LqI iewKGElWWESwm7Ym/Bztsritc9hc9N9+IXZwbtnrU5AOaZkGdA9/ZhGqNMtZI7LiQ/RH viTwEb+htm6hY/gn70I7P6+biy/vGrKZIwQ9F29ZlCfpq0Z6A2b1y7Z6IHOZKXJoC0fY 04SBRKrzaAD9gj4uHozLfRR3fjfWONjKGYynZfE8cvajiUul5l25FEVIZO8B6J8Eu7fZ 5GWtukrYWkMuKnkZ8AUXgHrhR4daMa1kUQSqeIToN+DBQCmvMZamYPBdDME/CvkQNE5o jvGg== X-Gm-Message-State: AOAM531B9PuVyaspEL0JTnZF1WBoFtEaNeWh2ySR0mCW4XYOZsbktr7c 4Qve6fevRIlGqXr472IAZy104Ii5FLPTIs+g X-Google-Smtp-Source: ABdhPJy5wT6pqBjRJRfdxF9ZiUl6/+/OUSzLL0CauLBlAG9XIBgSBkDU2ZOEhGDkB4uFLXppLuVYOQ== X-Received: by 2002:a05:6402:1768:: with SMTP id da8mr7720764edb.252.1639485680684; Tue, 14 Dec 2021 04:41:20 -0800 (PST) Received: from localhost.localdomain ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id e4sm1025351ejl.196.2021.12.14.04.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 04:41:20 -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 v2 4/6] gqa-win: get_pci_info: Split logic to separate functions Date: Tue, 14 Dec 2021 14:41:07 +0200 Message-Id: <20211214124109.103102-5-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214124109.103102-1-konstantin@daynix.com> References: <20211214124109.103102-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::534 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::534; envelope-from=konstantin@daynix.com; helo=mail-ed1-x534.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 161 +++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 74 deletions(-) -- 2.25.1 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index f6de9e2676..8588fa8633 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -512,6 +512,92 @@ DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT, 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b); +static void get_pci_address_for_device(GuestPCIAddress *pci, + HDEVINFO dev_info) +{ + SP_DEVINFO_DATA dev_info_data; + DWORD j; + DWORD size; + bool partial_pci = false; + + dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); + + for (j = 0; + SetupDiEnumDeviceInfo(dev_info, j, &dev_info_data); + j++) { + DWORD addr, bus, ui_slot, type; + int func, slot; + size = sizeof(DWORD); + + /* + * There is no need to allocate buffer in the next functions. The + * size is known and ULONG according to + * https://msdn.microsoft.com/en-us/library/windows/hardware/ff543095(v=vs.85).aspx + */ + if (!SetupDiGetDeviceRegistryProperty( + dev_info, &dev_info_data, SPDRP_BUSNUMBER, + &type, (PBYTE)&bus, size, NULL)) { + debug_error("failed to get PCI bus"); + bus = -1; + partial_pci = true; + } + + /* + * The function retrieves the device's address. This value will be + * transformed into device function and number + */ + if (!SetupDiGetDeviceRegistryProperty( + dev_info, &dev_info_data, SPDRP_ADDRESS, + &type, (PBYTE)&addr, size, NULL)) { + debug_error("failed to get PCI address"); + addr = -1; + partial_pci = true; + } + + /* + * This call returns UINumber of DEVICE_CAPABILITIES structure. + * This number is typically a user-perceived slot number. + */ + if (!SetupDiGetDeviceRegistryProperty( + dev_info, &dev_info_data, SPDRP_UI_NUMBER, + &type, (PBYTE)&ui_slot, size, NULL)) { + debug_error("failed to get PCI slot"); + ui_slot = -1; + partial_pci = true; + } + + /* + * SetupApi gives us the same information as driver with + * IoGetDeviceProperty. According to Microsoft: + * + * FunctionNumber = (USHORT)((propertyAddress) & 0x0000FFFF) + * DeviceNumber = (USHORT)(((propertyAddress) >> 16) & 0x0000FFFF) + * SPDRP_ADDRESS is propertyAddress, so we do the same. + * + * https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdigetdeviceregistrypropertya + */ + if (partial_pci) { + pci->domain = -1; + pci->slot = -1; + pci->function = -1; + pci->bus = -1; + continue; + } else { + func = ((int)addr == -1) ? -1 : addr & 0x0000FFFF; + slot = ((int)addr == -1) ? -1 : (addr >> 16) & 0x0000FFFF; + if ((int)ui_slot != slot) { + g_debug("mismatch with reported slot values: %d vs %d", + (int)ui_slot, slot); + } + pci->domain = 0; + pci->slot = (int)ui_slot; + pci->function = func; + pci->bus = (int)bus; + return; + } + } +} + static GuestPCIAddress *get_pci_info(int number, Error **errp) { HDEVINFO dev_info = INVALID_HANDLE_VALUE; @@ -522,7 +608,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) HANDLE dev_file; int i; GuestPCIAddress *pci = NULL; - bool partial_pci = false; pci = g_malloc0(sizeof(*pci)); pci->domain = -1; @@ -545,7 +630,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) STORAGE_DEVICE_NUMBER sdn; char *parent_dev_id = NULL; SP_DEVINFO_DATA parent_dev_info_data; - DWORD j; DWORD size = 0; g_debug("getting device path"); @@ -672,79 +756,8 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) goto end; } - for (j = 0; - SetupDiEnumDeviceInfo(parent_dev_info, j, &parent_dev_info_data); - j++) { - DWORD addr, bus, ui_slot, type; - int func, slot; + get_pci_address_for_device(pci, parent_dev_info); - /* - * There is no need to allocate buffer in the next functions. The - * size is known and ULONG according to - * https://msdn.microsoft.com/en-us/library/windows/hardware/ff543095(v=vs.85).aspx - */ - if (!SetupDiGetDeviceRegistryProperty( - parent_dev_info, &parent_dev_info_data, SPDRP_BUSNUMBER, - &type, (PBYTE)&bus, size, NULL)) { - debug_error("failed to get PCI bus"); - bus = -1; - partial_pci = true; - } - - /* - * The function retrieves the device's address. This value will be - * transformed into device function and number - */ - if (!SetupDiGetDeviceRegistryProperty( - parent_dev_info, &parent_dev_info_data, SPDRP_ADDRESS, - &type, (PBYTE)&addr, size, NULL)) { - debug_error("failed to get PCI address"); - addr = -1; - partial_pci = true; - } - - /* - * This call returns UINumber of DEVICE_CAPABILITIES structure. - * This number is typically a user-perceived slot number. - */ - if (!SetupDiGetDeviceRegistryProperty( - parent_dev_info, &parent_dev_info_data, SPDRP_UI_NUMBER, - &type, (PBYTE)&ui_slot, size, NULL)) { - debug_error("failed to get PCI slot"); - ui_slot = -1; - partial_pci = true; - } - - /* - * SetupApi gives us the same information as driver with - * IoGetDeviceProperty. According to Microsoft: - * - * FunctionNumber = (USHORT)((propertyAddress) & 0x0000FFFF) - * DeviceNumber = (USHORT)(((propertyAddress) >> 16) & 0x0000FFFF) - * SPDRP_ADDRESS is propertyAddress, so we do the same. - * - * https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdigetdeviceregistrypropertya - */ - if (partial_pci) { - pci->domain = -1; - pci->slot = -1; - pci->function = -1; - pci->bus = -1; - continue; - } else { - func = ((int)addr == -1) ? -1 : addr & 0x0000FFFF; - slot = ((int)addr == -1) ? -1 : (addr >> 16) & 0x0000FFFF; - if ((int)ui_slot != slot) { - g_debug("mismatch with reported slot values: %d vs %d", - (int)ui_slot, slot); - } - pci->domain = 0; - pci->slot = (int)ui_slot; - pci->function = func; - pci->bus = (int)bus; - break; - } - } break; } From patchwork Tue Dec 14 12:41:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 1567722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20210112.gappssmtp.com header.i=@daynix-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=hd2FwTfO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCysL6vp6z9s3q for ; Tue, 14 Dec 2021 23:50:30 +1100 (AEDT) Received: from localhost ([::1]:52000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx7GF-0007u4-Pt for incoming@patchwork.ozlabs.org; Tue, 14 Dec 2021 07:50:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx77W-0001og-9M for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:26 -0500 Received: from [2a00:1450:4864:20::533] (port=33762 helo=mail-ed1-x533.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx77U-0004cL-2N for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:25 -0500 Received: by mail-ed1-x533.google.com with SMTP id t5so62347068edd.0 for ; Tue, 14 Dec 2021 04:41:22 -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=dtsh7aTiptfdoEl+40W5A3ttiw5rsibSMoGvl8oqbN4=; b=hd2FwTfOjyqfZ31y4rsu+JcX9D2iqqMXH6PotnAJSvK3tTu2JS8/D9OrExgZ5uVYJQ 85skFZR8Kd2HXSorO/Zh0lAhMeTO/czx/16A+YbEq5bdVUZVsQn+r53n4U2+w/KL9JTe mo5c34bVoqaIuj1soSH260AVuw//BC//58HmxBVwZKRklY5F+RWMqpvpTM4UzVOHjF6G ZkUwFJsePwVuPNdzVJt77DNZAgNViOkoC4Xy2s0a4SCpkxws5qb9EdkQVbQahSUusBkL E5Vskz75L5zMk9gml+TlexKUfVQeImqi8BEfi6w1LuzNgwRH1/weuGxLvjCon4xUy7K4 +Lrg== 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=dtsh7aTiptfdoEl+40W5A3ttiw5rsibSMoGvl8oqbN4=; b=boBYKBer+/MrymYJyHkwx2AB1HwJY5J18Zw98D34ZyvycstDyPPoBP8ohs/wXWDLJF prrdvs9yNAtA8M6AFfmwgQkikuLJH4XZlNKFR83MF1GbXDcEclOMfNwXcT+BOwtFznwQ nYijec4hVLasdkbJUA6NKhx1/GVYEXfH5TObMoKH4a7jN8ezC87jE3ayeiHTrH/Gmqmf n+jMxAa0uOMhtc6nxNyKG5WFWydAiMOzbxg2zW0W27nNTX19KONoME5qJE6pSxp19aZm abYHFXudk13ZtC6LonTbVm8GPqs3CkZ9BjZVKKmhSQuRgJKoRX3tS/GgHUCgX2Cnp8/1 K/ag== X-Gm-Message-State: AOAM532ay42ZNBp4KesOkJSvv1dhy1jZ8MsYeC8VeQmwqUgsZo14Heyy jHJ7179FqJLyP6bNne3MinEfgjNWipkPnOPE X-Google-Smtp-Source: ABdhPJyd83xxpmQIfAikie71MvnaeGALwjJ/JoIKIH5Z+uzCfI80Lwdt2qF6IBx+yyGpLDd5uv+I0g== X-Received: by 2002:a50:d741:: with SMTP id i1mr7563875edj.37.1639485681615; Tue, 14 Dec 2021 04:41:21 -0800 (PST) Received: from localhost.localdomain ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id e4sm1025351ejl.196.2021.12.14.04.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 04:41:21 -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 v2 5/6] gqa-win: get_pci_info: Add g_autofree for few variables Date: Tue, 14 Dec 2021 14:41:08 +0200 Message-Id: <20211214124109.103102-6-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214124109.103102-1-konstantin@daynix.com> References: <20211214124109.103102-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::533 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::533; envelope-from=konstantin@daynix.com; helo=mail-ed1-x533.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk Reviewed-by: Marc-André Lureau --- qga/commands-win32.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 8588fa8633..3092566313 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -626,9 +626,9 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); dev_iface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) { - PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL; + g_autofree PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL; STORAGE_DEVICE_NUMBER sdn; - char *parent_dev_id = NULL; + g_autofree char *parent_dev_id = NULL; SP_DEVINFO_DATA parent_dev_info_data; DWORD size = 0; @@ -654,7 +654,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) dev_file = CreateFile(pdev_iface_detail_data->DevicePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - g_free(pdev_iface_detail_data); if (!DeviceIoControl(dev_file, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &size, NULL)) { @@ -741,7 +740,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp) parent_dev_info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_STORAGEPORT, parent_dev_id, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - g_free(parent_dev_id); if (parent_dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), From patchwork Tue Dec 14 12:41:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 1567723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20210112.gappssmtp.com header.i=@daynix-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=XZst7yR3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCysP5Rbsz9s3q for ; Tue, 14 Dec 2021 23:50:33 +1100 (AEDT) Received: from localhost ([::1]:52186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx7GJ-00081i-Hd for incoming@patchwork.ozlabs.org; Tue, 14 Dec 2021 07:50:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx77Y-0001pL-Ev for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:28 -0500 Received: from [2a00:1450:4864:20::534] (port=39918 helo=mail-ed1-x534.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx77U-0004cg-4g for qemu-devel@nongnu.org; Tue, 14 Dec 2021 07:41:27 -0500 Received: by mail-ed1-x534.google.com with SMTP id b7so3310053edd.6 for ; Tue, 14 Dec 2021 04:41:23 -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=UnZlWzVci/8A7koWYfCugs/CcDlIcJ+u1vqVZ6kvKA0=; b=XZst7yR3E3eIyafAJarFJGJxCGh+rT41yhrO6rebvRqoqSv2A09F0JCEUnkD3+Bz8q aAPVhFAQl5fMaN5uYAEvQBaoeGbeByYDFXozBqz/qflZv9GpBcy88EMSsuJCdaZvVA9Q BcJSZcGhsW19KTeE6jF+ImOwE1fJNxfMMtEiMjgzhvei1N5UaHreFl9hCtDVqBBYlgzF sBp22l6FAT72Ta1J7Yh9W8myteISeqEmS9EA/n09+z8IyCSkm8nYmaYuZPn1L9+fxhRF bXGc/aTcf6ZA+Oh2IQ6oXtyS0iMdhbopPoL7i949gt+ac8ejFsKOhDUYQ1ftQhcVFprS 9neA== 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=UnZlWzVci/8A7koWYfCugs/CcDlIcJ+u1vqVZ6kvKA0=; b=lAdH4FuwGUmA+B8IryX294hjbsawrlsUCqIWXzTpIVFd+e0gbeVjKYS6wKY9zXw/79 DoA3hf92ODeqv5sDmDYF8s8RWRBbZrvTEOd+i0x3XqiiL6iijNnUNGJ6rjDJPMnx8S4Y uLVVNyVa8mT7b/I5EVZ+beuxKH8pXXxdGOYzJt0Mbfo/Iw0+H/MTicMyW/GKCnVR+5qt 7+E/O8LcBw+B4ac6HoJEfqdLRXGzV0dr5xO4C+Nul6Q9pVqzJN24JBB0XkuDywg+DGzy Lby+VVp9TamE4hbSN0q6BgU4iE7XHeacHoYEWoDE7O0sFu/4T4L9MwH4AJgYceSHoRJA S7UA== X-Gm-Message-State: AOAM533q9aaIU1vKAjoWVJDMyO3xhb/sqG+tpzBbjw9qhQF5AVMggPKU pQG/IQVVzggaggT00De7qyQ3p2Nt+JiEFlWx X-Google-Smtp-Source: ABdhPJx2Qdcuqr7ksB11uQRixSUKXosM00tCb26/pU0tMT4fAFTpH3R30QdJIp6o+dgHbLo329Pa3g== X-Received: by 2002:a05:6402:34cf:: with SMTP id w15mr7372717edc.63.1639485682601; Tue, 14 Dec 2021 04:41:22 -0800 (PST) Received: from localhost.localdomain ([37.72.42.118]) by smtp.gmail.com with ESMTPSA id e4sm1025351ejl.196.2021.12.14.04.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 04:41:22 -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 v2 6/6] gqa-win: get_pci_info: Replace 'while' with 2 calls of the function Date: Tue, 14 Dec 2021 14:41:09 +0200 Message-Id: <20211214124109.103102-7-konstantin@daynix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214124109.103102-1-konstantin@daynix.com> References: <20211214124109.103102-1-konstantin@daynix.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::534 (failed) Received-SPF: none client-ip=2a00:1450:4864:20::534; envelope-from=konstantin@daynix.com; helo=mail-ed1-x534.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+incoming=patchwork.ozlabs.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(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 3092566313..892082504f 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -636,10 +636,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 = @@ -651,6 +651,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 end; + } + dev_file = CreateFile(pdev_iface_detail_data->DevicePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); @@ -680,8 +690,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 { @@ -691,6 +701,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 end; + } + /* * CM API used here as opposed to * SetupDiGetDeviceProperty(..., DEVPKEY_Device_Parent, ...)