https://git.reactos.org/?p=reactos.git;a=commitdiff;h=89aff07a671332065c408c23806ee1fd05683e4b

commit 89aff07a671332065c408c23806ee1fd05683e4b
Author:     Hervé Poussineau <[email protected]>
AuthorDate: Mon Mar 16 18:07:24 2020 +0100
Commit:     Hervé Poussineau <[email protected]>
CommitDate: Fri Mar 20 22:40:11 2020 +0100

    [ISAPNP] Extract function to create DOs
---
 drivers/bus/isapnp/fdo.c    | 57 +-------------------------------------
 drivers/bus/isapnp/isapnp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/bus/isapnp/isapnp.h |  6 ++++
 3 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/drivers/bus/isapnp/fdo.c b/drivers/bus/isapnp/fdo.c
index 5e6931d07f0..6417d6e68bc 100644
--- a/drivers/bus/isapnp/fdo.c
+++ b/drivers/bus/isapnp/fdo.c
@@ -44,13 +44,8 @@ IsaFdoQueryDeviceRelations(
     IN PIRP Irp,
     IN PIO_STACK_LOCATION IrpSp)
 {
-    PISAPNP_PDO_EXTENSION PdoExt;
     NTSTATUS Status;
-    PLIST_ENTRY CurrentEntry;
-    PISAPNP_LOGICAL_DEVICE IsaDevice;
-    PDEVICE_RELATIONS DeviceRelations;
     KIRQL OldIrql;
-    ULONG i = 0;
 
     if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
         return Irp->IoStatus.Status;
@@ -64,57 +59,7 @@ IsaFdoQueryDeviceRelations(
         return Status;
     }
 
-    DeviceRelations = ExAllocatePool(NonPagedPool,
-                                     sizeof(DEVICE_RELATIONS) + 
sizeof(DEVICE_OBJECT) * (FdoExt->DeviceCount - 1));
-    if (!DeviceRelations)
-    {
-        return STATUS_NO_MEMORY;
-    }
-
-    CurrentEntry = FdoExt->DeviceListHead.Flink;
-    while (CurrentEntry != &FdoExt->DeviceListHead)
-    {
-        IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, 
ListEntry);
-
-        if (!IsaDevice->Pdo)
-        {
-            Status = IoCreateDevice(FdoExt->DriverObject,
-                                    sizeof(ISAPNP_PDO_EXTENSION),
-                                    NULL,
-                                    FILE_DEVICE_CONTROLLER,
-                                    FILE_DEVICE_SECURE_OPEN | 
FILE_AUTOGENERATED_DEVICE_NAME,
-                                    FALSE,
-                                    &IsaDevice->Pdo);
-            if (!NT_SUCCESS(Status))
-            {
-                break;
-            }
-
-            IsaDevice->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
-
-            //Device->Pdo->Flags |= DO_POWER_PAGABLE;
-
-            PdoExt = (PISAPNP_PDO_EXTENSION)IsaDevice->Pdo->DeviceExtension;
-
-            RtlZeroMemory(PdoExt, sizeof(ISAPNP_PDO_EXTENSION));
-
-            PdoExt->Common.IsFdo = FALSE;
-            PdoExt->Common.Self = IsaDevice->Pdo;
-            PdoExt->Common.State = dsStopped;
-            PdoExt->IsaPnpDevice = IsaDevice;
-        }
-        DeviceRelations->Objects[i++] = IsaDevice->Pdo;
-
-        ObReferenceObject(IsaDevice->Pdo);
-
-        CurrentEntry = CurrentEntry->Flink;
-    }
-
-    DeviceRelations->Count = FdoExt->DeviceCount;
-
-    Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
-
-    return STATUS_SUCCESS;
+    return IsaPnpFillDeviceRelations(FdoExt, Irp);
 }
 
 NTSTATUS
diff --git a/drivers/bus/isapnp/isapnp.c b/drivers/bus/isapnp/isapnp.c
index d3d600a75d3..6fc29e9e70c 100644
--- a/drivers/bus/isapnp/isapnp.c
+++ b/drivers/bus/isapnp/isapnp.c
@@ -10,6 +10,73 @@
 #define NDEBUG
 #include <debug.h>
 
+NTSTATUS
+NTAPI
+IsaPnpFillDeviceRelations(
+  IN PISAPNP_FDO_EXTENSION FdoExt,
+  IN PIRP Irp)
+{
+    PISAPNP_PDO_EXTENSION PdoExt;
+    NTSTATUS Status = STATUS_SUCCESS;
+    PLIST_ENTRY CurrentEntry;
+    PISAPNP_LOGICAL_DEVICE IsaDevice;
+    PDEVICE_RELATIONS DeviceRelations;
+    ULONG i = 0;
+
+    DeviceRelations = ExAllocatePool(NonPagedPool,
+                                     sizeof(DEVICE_RELATIONS) + 
sizeof(DEVICE_OBJECT) * FdoExt->DeviceCount);
+    if (!DeviceRelations)
+    {
+        return STATUS_NO_MEMORY;
+    }
+
+    CurrentEntry = FdoExt->DeviceListHead.Flink;
+    while (CurrentEntry != &FdoExt->DeviceListHead)
+    {
+       IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, 
ListEntry);
+
+       if (!IsaDevice->Pdo)
+       {
+           Status = IoCreateDevice(FdoExt->DriverObject,
+                                   sizeof(ISAPNP_PDO_EXTENSION),
+                                   NULL,
+                                   FILE_DEVICE_CONTROLLER,
+                                   FILE_DEVICE_SECURE_OPEN | 
FILE_AUTOGENERATED_DEVICE_NAME,
+                                   FALSE,
+                                   &IsaDevice->Pdo);
+           if (!NT_SUCCESS(Status))
+           {
+              break;
+           }
+
+           IsaDevice->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
+
+           //Device->Pdo->Flags |= DO_POWER_PAGABLE;
+
+           PdoExt = (PISAPNP_PDO_EXTENSION)IsaDevice->Pdo->DeviceExtension;
+
+           RtlZeroMemory(PdoExt, sizeof(ISAPNP_PDO_EXTENSION));
+
+           PdoExt->Common.IsFdo = FALSE;
+           PdoExt->Common.Self = IsaDevice->Pdo;
+           PdoExt->Common.State = dsStopped;
+           PdoExt->IsaPnpDevice = IsaDevice;
+       }
+       DeviceRelations->Objects[i++] = IsaDevice->Pdo;
+
+       ObReferenceObject(IsaDevice->Pdo);
+
+       CurrentEntry = CurrentEntry->Flink;
+    }
+
+    DeviceRelations->Count = i;
+
+    Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
+
+    return Status;
+}
+
+
 static IO_COMPLETION_ROUTINE ForwardIrpCompletion;
 
 static
diff --git a/drivers/bus/isapnp/isapnp.h b/drivers/bus/isapnp/isapnp.h
index 633341d5f99..e247643112c 100644
--- a/drivers/bus/isapnp/isapnp.h
+++ b/drivers/bus/isapnp/isapnp.h
@@ -51,6 +51,12 @@ typedef struct _ISAPNP_PDO_EXTENSION {
 
 /* isapnp.c */
 
+NTSTATUS
+NTAPI
+IsaPnpFillDeviceRelations(
+    IN PISAPNP_FDO_EXTENSION FdoExt,
+    IN PIRP Irp);
+
 DRIVER_INITIALIZE DriverEntry;
 
 NTSTATUS

Reply via email to