[PATCH 2/3] setupapi: Get rid of the redundant cDevices parameter to struct device.

Zebediah Figura z.figura12 at gmail.com
Mon Dec 3 18:34:57 CST 2018


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/setupapi/devinst.c | 47 +++++++++++++++--------------------------------
 1 file changed, 15 insertions(+), 32 deletions(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 7638a8bd5b..db0b72fcb5 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -104,7 +104,6 @@ struct DeviceInfoSet
     DWORD magic;        /* if is equal to SETUP_DEVICE_INFO_SET_MAGIC struct is okay */
     GUID ClassGuid;
     HWND hwndParent;
-    DWORD cDevices;
     struct list devices;
 };
 
@@ -670,7 +669,6 @@ static struct device *SETUPDI_CreateDeviceInfo(struct DeviceInfoSet *set,
     device->devnode = alloc_devnode(device);
     device->removed = FALSE;
     list_add_tail(&set->devices, &device->entry);
-    set->cDevices++;
 
     SETUPDI_GuidToString(class, guidstr);
     SETUPDI_SetDeviceRegistryPropertyW(device, SPDRP_CLASSGUID,
@@ -1289,7 +1287,6 @@ SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid,
     memcpy(&list->ClassGuid,
             ClassGuid ? ClassGuid : &GUID_NULL,
             sizeof(list->ClassGuid));
-    list->cDevices = 0;
     list_init(&list->devices);
 
     return list;
@@ -1475,7 +1472,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, const WCHAR *name, const
     if ((flags & DICD_GENERATE_ID))
     {
         static const WCHAR formatW[] = {'R','O','O','T','\\','%','s','\\','%','0','4','d',0};
-        DWORD devId;
+        int instance_id, highest_id = -1;
 
         if (strchrW(name, '\\'))
         {
@@ -1483,29 +1480,20 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, const WCHAR *name, const
             return FALSE;
         }
 
-        if (set->cDevices)
+        LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
         {
-            DWORD highestDevID = 0;
-
-            LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
-            {
-                const WCHAR *devName = strrchrW(device->instanceId, '\\');
-                DWORD id;
-
-                if (devName)
-                    devName++;
-                else
-                    devName = device->instanceId;
-                id = SETUPDI_DevNameToDevID(devName);
-                if (id != 0xffffffff && id > highestDevID)
-                    highestDevID = id;
-            }
-            devId = highestDevID + 1;
+            const WCHAR *instance_str = strrchrW(device->instanceId, '\\');
+
+            if (instance_str)
+                instance_str++;
+            else
+                instance_str = device->instanceId;
+            instance_id = SETUPDI_DevNameToDevID(instance_str);
+            if (instance_id != 0xffffffff && instance_id > highest_id)
+                highest_id = instance_id;
         }
-        else
-            devId = 0;
 
-        if (snprintfW(id, ARRAY_SIZE(id), formatW, name, devId) == -1)
+        if (snprintfW(id, ARRAY_SIZE(id), formatW, name, highest_id + 1) == -1)
         {
             SetLastError(ERROR_INVALID_DEVINST_NAME);
             return FALSE;
@@ -1646,22 +1634,17 @@ BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, SP_DEVINFO_DATA
         return FALSE;
     }
 
-    if (index >= set->cDevices)
-    {
-        SetLastError(ERROR_NO_MORE_ITEMS);
-        return FALSE;
-    }
-
     LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
     {
         if (i++ == index)
         {
             copy_device_data(device_data, device);
-            break;
+            return TRUE;
         }
     }
 
-    return TRUE;
+    SetLastError(ERROR_NO_MORE_ITEMS);
+    return FALSE;
 }
 
 /***********************************************************************
-- 
2.14.1




More information about the wine-devel mailing list