Skip to content

Commit

Permalink
qga-win: fsinfo: pci-info: allow partial info
Browse files Browse the repository at this point in the history
The call to SetupDiGetDeviceRegistryProperty might fail because the
value doesn't exist in the registry, in this case we shouldn't exit from
the loop but instead continue to look for other available values in the
registry and set this value as unavailable (-1).

Signed-off-by: Sameeh Jubran <sjubran@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
(cherry picked from commit d42f51de2d10b318d396f4f439f7a3995fdc0f65)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
Sameeh Jubran authored and mdroth committed Sep 26, 2018
1 parent 89f145d commit d5f5f7e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions qga/commands-win32.c
Expand Up @@ -506,7 +506,8 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp)

dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) {
DWORD addr, bus, slot, func, dev, data, size2;
DWORD addr, bus, slot, data, size2;
int func, dev;
while (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data,
SPDRP_PHYSICAL_DEVICE_OBJECT_NAME,
&data, (PBYTE)buffer, size,
Expand Down Expand Up @@ -536,21 +537,21 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp)
*/
if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data,
SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, NULL)) {
break;
bus = -1;
}

/* 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, &data, (PBYTE)&addr, size, NULL)) {
break;
addr = -1;
}

/* 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, &data, (PBYTE)&slot, size, NULL)) {
break;
slot = -1;
}

/* SetupApi gives us the same information as driver with
Expand All @@ -560,12 +561,12 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp)
* DeviceNumber = (USHORT)(((propertyAddress) >> 16) & 0x0000FFFF);
* SPDRP_ADDRESS is propertyAddress, so we do the same.*/

func = addr & 0x0000FFFF;
dev = (addr >> 16) & 0x0000FFFF;
func = ((int) addr == -1) ? -1 : addr & 0x0000FFFF;
dev = ((int) addr == -1) ? -1 : (addr >> 16) & 0x0000FFFF;
pci->domain = dev;
pci->slot = slot;
pci->slot = (int) slot;
pci->function = func;
pci->bus = bus;
pci->bus = (int) bus;
break;
}

Expand Down

0 comments on commit d5f5f7e

Please sign in to comment.