[USBSTOR] Properly handle IRP_MN_QUERY_DEVICE_RELATIONS(BusRelations) for FDO.
authorVictor Perevertkin <victor@perevertkin.ru>
Mon, 10 Jun 2019 23:50:43 +0000 (02:50 +0300)
committerVictor Perevertkin <victor@perevertkin.ru>
Tue, 11 Jun 2019 01:39:43 +0000 (04:39 +0300)
This fixes Driver Verifier warnings

drivers/usb/usbstor/fdo.c

index 6879b4e..a8a1a4d 100644 (file)
@@ -5,6 +5,7 @@
  * COPYRIGHT:   2005-2006 James Tabor
  *              2011-2012 Michael Martin (michael.martin@reactos.org)
  *              2011-2013 Johannes Anderwald (johannes.anderwald@reactos.org)
+ *              2019 Victor Perevertkin (victor.perevertkin@reactos.org)
  */
 
 #include "usbstor.h"
@@ -45,46 +46,49 @@ USBSTOR_FdoHandleDeviceRelations(
 
     IoStack = IoGetCurrentIrpStackLocation(Irp);
 
-    // check if relation type is BusRelations
-    if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations)
+    // FDO always only handles bus relations
+    if (IoStack->Parameters.QueryDeviceRelations.Type == BusRelations)
     {
-        // FDO always only handles bus relations
-        return USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp);
-    }
-
-    // go through array and count device objects
-    for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++)
-    {
-        if (DeviceExtension->ChildPDO[Index])
+        // go through array and count device objects
+        for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++)
         {
-            DeviceCount++;
+            if (DeviceExtension->ChildPDO[Index])
+            {
+                DeviceCount++;
+            }
         }
-    }
 
-    DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0));
-    if (!DeviceRelations)
-    {
-        return STATUS_INSUFFICIENT_RESOURCES;
-    }
+        DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0));
+        if (!DeviceRelations)
+        {
+            Irp->IoStatus.Information = 0;
+            Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
+            IoCompleteRequest(Irp, IO_NO_INCREMENT);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
-    // add device objects
-    for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++)
-    {
-        if (DeviceExtension->ChildPDO[Index])
+        // add device objects
+        for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++)
         {
-            // store child pdo
-            DeviceRelations->Objects[DeviceRelations->Count] = DeviceExtension->ChildPDO[Index];
+            if (DeviceExtension->ChildPDO[Index])
+            {
+                // store child pdo
+                DeviceRelations->Objects[DeviceRelations->Count] = DeviceExtension->ChildPDO[Index];
 
-            // add reference
-            ObReferenceObject(DeviceExtension->ChildPDO[Index]);
+                // add reference
+                ObReferenceObject(DeviceExtension->ChildPDO[Index]);
 
-            DeviceRelations->Count++;
+                DeviceRelations->Count++;
+            }
         }
+
+        Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
+        Irp->IoStatus.Status = STATUS_SUCCESS;
     }
 
-    Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
+    IoCopyCurrentIrpStackLocationToNext(Irp);
 
-    return STATUS_SUCCESS;
+    return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
 }
 
 NTSTATUS
@@ -291,9 +295,8 @@ USBSTOR_FdoHandlePnp(
         }
         case IRP_MN_QUERY_DEVICE_RELATIONS:
         {
-            DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p\n", DeviceObject);
-            Status = USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp);
-            break;
+            DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p Type: %u\n", DeviceObject, IoStack->Parameters.QueryDeviceRelations.Type);
+            return USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp);
         }
         case IRP_MN_STOP_DEVICE:
         {