[PATCH v2 2/3] setupapi: Create only one driver per driver id match.

Rémi Bernon rbernon at codeweavers.com
Wed Aug 18 02:40:11 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/setupapi/devinst.c       | 26 +++++++++++++++-----------
 dlls/setupapi/tests/devinst.c |  9 +--------
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index baef28ac130..13e52f4534a 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -4648,6 +4648,7 @@ static void enum_compat_drivers_from_file(struct device *device, const WCHAR *pa
     DWORD i, j, k, driver_count = device->driver_count;
     struct driver driver, *drivers = device->drivers;
     INFCONTEXT ctx;
+    BOOL found;
     HINF hinf;
 
     TRACE("Enumerating drivers from %s.\n", debugstr_w(path));
@@ -4687,20 +4688,23 @@ static void enum_compat_drivers_from_file(struct device *device, const WCHAR *pa
 
         for (j = 0; SetupGetLineByIndexW(hinf, driver.mfg_key, j, &ctx); ++j)
         {
-            for (k = 2; SetupGetStringFieldW(&ctx, k, id, ARRAY_SIZE(id), NULL); ++k)
+            for (k = 2, found = FALSE; SetupGetStringFieldW(&ctx, k, id, ARRAY_SIZE(id), NULL); ++k)
             {
-                if (device_matches_id(device, HardwareId, id) || device_matches_id(device, CompatibleIDs, id))
-                {
-                    SetupGetStringFieldW(&ctx, 0, driver.description, ARRAY_SIZE(driver.description), NULL);
-                    SetupGetStringFieldW(&ctx, 1, driver.section, ARRAY_SIZE(driver.section), NULL);
+                if ((found = device_matches_id(device, HardwareId, id))) break;
+                if ((found = device_matches_id(device, CompatibleIDs, id))) break;
+            }
 
-                    TRACE("Found compatible driver: manufacturer %s, desc %s.\n",
-                            debugstr_w(driver.manufacturer), debugstr_w(driver.description));
+            if (found)
+            {
+                SetupGetStringFieldW(&ctx, 0, driver.description, ARRAY_SIZE(driver.description), NULL);
+                SetupGetStringFieldW(&ctx, 1, driver.section, ARRAY_SIZE(driver.section), NULL);
 
-                    driver_count++;
-                    drivers = heap_realloc(drivers, driver_count * sizeof(*drivers));
-                    drivers[driver_count - 1] = driver;
-                }
+                TRACE("Found compatible driver: manufacturer %s, desc %s.\n",
+                        debugstr_w(driver.manufacturer), debugstr_w(driver.description));
+
+                driver_count++;
+                drivers = heap_realloc(drivers, driver_count * sizeof(*drivers));
+                drivers[driver_count - 1] = driver;
             }
         }
     }
diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c
index 73e0086081d..677d6bda02a 100644
--- a/dlls/setupapi/tests/devinst.c
+++ b/dlls/setupapi/tests/devinst.c
@@ -2458,14 +2458,7 @@ static void test_driver_list(void)
     ret = SetupDiEnumDriverInfoA(set, &device, SPDIT_COMPATDRIVER, idx++, &driver);
     ok(ret, "Failed to enumerate drivers, error %#x.\n", GetLastError());
     ok(driver.DriverType == SPDIT_COMPATDRIVER, "Got wrong type %#x.\n", driver.DriverType);
-    todo_wine ok(!strcmp(driver.Description, "desc1"), "Got wrong description '%s'.\n", driver.Description);
-    if (strcmp(driver.Description, "desc1"))
-    {
-        ret = SetupDiEnumDriverInfoA(set, &device, SPDIT_COMPATDRIVER, idx++, &driver);
-        ok(ret, "Failed to enumerate drivers, error %#x.\n", GetLastError());
-        ok(driver.DriverType == SPDIT_COMPATDRIVER, "Got wrong type %#x.\n", driver.DriverType);
-        ok(!strcmp(driver.Description, "desc1"), "Got wrong description '%s'.\n", driver.Description);
-    }
+    ok(!strcmp(driver.Description, "desc1"), "Got wrong description '%s'.\n", driver.Description);
     ok(!strcmp(driver.MfgName, wow64 ? "mfg1_wow" : "mfg1"), "Got wrong manufacturer '%s'.\n", driver.MfgName);
     ok(!strcmp(driver.ProviderName, ""), "Got wrong provider '%s'.\n", driver.ProviderName);
 
-- 
2.32.0




More information about the wine-devel mailing list