https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8653bb1b322afff64f0361b0d4e801f2ab889e7f

commit 8653bb1b322afff64f0361b0d4e801f2ab889e7f
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Sun Jan 5 18:06:45 2025 +0100
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Sun Jan 5 20:10:26 2025 +0100

    [PARTMGR] Few code enhancements.
    
    - PartMgrAddDevice(): If IoAttachDeviceToDeviceStack() fails, bail out
      immediately, instead of continuing initializing the device extension
      then deciding to fail.
    
    - PartitionCreateDevice(): Initialize the fields pertaining to parent
      device linking in the partition device extension, before the other fields
      (following in a similar way what's done in PartMgrAddDevice).
---
 drivers/storage/partmgr/partition.c | 6 +++---
 drivers/storage/partmgr/partmgr.c   | 9 ++++-----
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/storage/partmgr/partition.c 
b/drivers/storage/partmgr/partition.c
index f54ccf55596..e8a38e728ca 100644
--- a/drivers/storage/partmgr/partition.c
+++ b/drivers/storage/partmgr/partition.c
@@ -52,6 +52,9 @@ PartitionCreateDevice(
     PPARTITION_EXTENSION partExt = partitionDevice->DeviceExtension;
     RtlZeroMemory(partExt, sizeof(*partExt));
 
+    partExt->DeviceObject = partitionDevice;
+    partExt->LowerDevice = FDObject;
+
     partitionDevice->StackSize = FDObject->StackSize;
     partitionDevice->Flags |= DO_DIRECT_IO;
 
@@ -77,9 +80,6 @@ PartitionCreateDevice(
     partExt->DetectedNumber = PdoNumber; // counts only partitions with PDO 
created
     partExt->VolumeNumber = volumeNum;
 
-    partExt->DeviceObject = partitionDevice;
-    partExt->LowerDevice = FDObject;
-
     // The device is initialized
     partitionDevice->Flags &= ~DO_DEVICE_INITIALIZING;
 
diff --git a/drivers/storage/partmgr/partmgr.c 
b/drivers/storage/partmgr/partmgr.c
index fd3fd89c247..b1c37b5d964 100644
--- a/drivers/storage/partmgr/partmgr.c
+++ b/drivers/storage/partmgr/partmgr.c
@@ -1201,16 +1201,15 @@ PartMgrAddDevice(
     deviceExtension->IsFDO = TRUE;
     deviceExtension->DeviceObject = deviceObject;
     deviceExtension->LowerDevice = IoAttachDeviceToDeviceStack(deviceObject, 
PhysicalDeviceObject);
-    deviceExtension->PhysicalDiskDO = PhysicalDeviceObject;
-    KeInitializeEvent(&deviceExtension->SyncEvent, SynchronizationEvent, TRUE);
-
-    // the the attaching failed
     if (!deviceExtension->LowerDevice)
     {
+        // The attachment failed
         IoDeleteDevice(deviceObject);
-
         return STATUS_DEVICE_REMOVED;
     }
+    deviceExtension->PhysicalDiskDO = PhysicalDeviceObject;
+    KeInitializeEvent(&deviceExtension->SyncEvent, SynchronizationEvent, TRUE);
+
     deviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
 
     // The device is initialized

Reply via email to