https://git.reactos.org/?p=reactos.git;a=commitdiff;h=da1b08e842c65553cd357…
commit da1b08e842c65553cd3576e9396d4f62cd86cb96
Author: Victor Perevertkin <victor(a)perevertkin.ru>
AuthorDate: Tue Jun 11 02:50:43 2019 +0300
Commit: Victor Perevertkin <victor(a)perevertkin.ru>
CommitDate: Tue Jun 11 04:39:43 2019 +0300
[USBSTOR] Properly handle IRP_MN_QUERY_DEVICE_RELATIONS(BusRelations) for FDO.
This fixes Driver Verifier warnings
---
drivers/usb/usbstor/fdo.c | 65 +++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 31 deletions(-)
diff --git a/drivers/usb/usbstor/fdo.c b/drivers/usb/usbstor/fdo.c
index 6879b4efe8f..a8a1a4d37b3 100644
--- a/drivers/usb/usbstor/fdo.c
+++ b/drivers/usb/usbstor/fdo.c
@@ -5,6 +5,7 @@
* COPYRIGHT: 2005-2006 James Tabor
* 2011-2012 Michael Martin (michael.martin(a)reactos.org)
* 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org)
+ * 2019 Victor Perevertkin (victor.perevertkin(a)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:
{