[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).
This commit is contained in:
Hermès Bélusca-Maïto 2025-01-05 18:06:45 +01:00
parent e1b835bdbf
commit 8653bb1b32
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 9 additions and 10 deletions

View file

@ -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;

View file

@ -1201,16 +1201,15 @@ PartMgrAddDevice(
deviceExtension->IsFDO = TRUE;
deviceExtension->DeviceObject = deviceObject;
deviceExtension->LowerDevice = IoAttachDeviceToDeviceStack(deviceObject, PhysicalDeviceObject);
if (!deviceExtension->LowerDevice)
{
// The attachment failed
IoDeleteDevice(deviceObject);
return STATUS_DEVICE_REMOVED;
}
deviceExtension->PhysicalDiskDO = PhysicalDeviceObject;
KeInitializeEvent(&deviceExtension->SyncEvent, SynchronizationEvent, TRUE);
// the the attaching failed
if (!deviceExtension->LowerDevice)
{
IoDeleteDevice(deviceObject);
return STATUS_DEVICE_REMOVED;
}
deviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
// The device is initialized