From 42cb5353b8ce9c85c04615beca9bab6245454153 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 15 Oct 2017 00:06:22 +0200 Subject: [PATCH] [STORORT] Allocate the miniport device extension and use it the calls to HwFindAdapter and HwInitialize. CORE-13866 --- drivers/storage/port/storport/fdo.c | 11 +++++--- drivers/storage/port/storport/miniport.c | 32 +++++++++++++++++++++--- drivers/storage/port/storport/precomp.h | 14 ++++++++--- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/drivers/storage/port/storport/fdo.c b/drivers/storage/port/storport/fdo.c index be6b6936941..6338c48d121 100644 --- a/drivers/storage/port/storport/fdo.c +++ b/drivers/storage/port/storport/fdo.c @@ -38,9 +38,14 @@ PortFdoStartMiniport( return STATUS_NO_SUCH_DEVICE; /* Initialize the miniport */ - MiniportInitialize(&DeviceExtension->Miniport, - DeviceExtension, - InitData); + Status = MiniportInitialize(&DeviceExtension->Miniport, + DeviceExtension, + InitData); + if (!NT_SUCCESS(Status)) + { + DPRINT1("MiniportInitialize() failed (Status 0x%08lx)\n", Status); + return Status; + } /* Call the miniports FindAdapter function */ Status = MiniportFindAdapter(&DeviceExtension->Miniport); diff --git a/drivers/storage/port/storport/miniport.c b/drivers/storage/port/storport/miniport.c index 8e1346fe8b4..4e0b37e1823 100644 --- a/drivers/storage/port/storport/miniport.c +++ b/drivers/storage/port/storport/miniport.c @@ -15,14 +15,38 @@ /* FUNCTIONS ******************************************************************/ -VOID +NTSTATUS MiniportInitialize( _In_ PMINIPORT Miniport, _In_ PFDO_DEVICE_EXTENSION DeviceExtension, _In_ PHW_INITIALIZATION_DATA InitData) { + PMINIPORT_DEVICE_EXTENSION MiniportExtension; + ULONG Size; + + DPRINT1("MiniportInitialize(%p %p %p)\n", + Miniport, DeviceExtension, InitData); + Miniport->DeviceExtension = DeviceExtension; Miniport->InitData = InitData; + + /* Calculate the miniport device extension size */ + Size = sizeof(MINIPORT_DEVICE_EXTENSION) + + Miniport->InitData->DeviceExtensionSize; + + /* Allocate and initialize the miniport device extension */ + MiniportExtension = ExAllocatePoolWithTag(NonPagedPool, + Size, + TAG_MINIPORT_DATA); + if (MiniportExtension == NULL) + return STATUS_NO_MEMORY; + + RtlZeroMemory(MiniportExtension, Size); + + MiniportExtension->Miniport = Miniport; + Miniport->MiniportExtension = MiniportExtension; + + return STATUS_SUCCESS; } @@ -36,7 +60,8 @@ MiniportFindAdapter( DPRINT1("MiniportFindAdapter(%p)\n", Miniport); - Result = Miniport->InitData->HwFindAdapter(NULL, + /* Call the miniport HwFindAdapter routine */ + Result = Miniport->InitData->HwFindAdapter(&Miniport->MiniportExtension->HwDeviceExtension, NULL, NULL, NULL, @@ -84,7 +109,8 @@ MiniportHwInitialize( DPRINT1("MiniportHwInitialize(%p)\n", Miniport); - Status = Miniport->InitData->HwInitialize(NULL); + /* Call the miniport HwInitialize routine */ + Status = Miniport->InitData->HwInitialize(&Miniport->MiniportExtension->HwDeviceExtension); DPRINT1("HwInitialize() returned 0x%08lx\n", Status); return Status; diff --git a/drivers/storage/port/storport/precomp.h b/drivers/storage/port/storport/precomp.h index fc1224e8513..350ca6854df 100644 --- a/drivers/storage/port/storport/precomp.h +++ b/drivers/storage/port/storport/precomp.h @@ -23,8 +23,9 @@ #include /* Memory Tags */ -#define TAG_GLOBAL_DATA 'DGtS' -#define TAG_INIT_DATA 'DItS' +#define TAG_GLOBAL_DATA 'DGtS' +#define TAG_INIT_DATA 'DItS' +#define TAG_MINIPORT_DATA 'DMtS' typedef enum { @@ -61,10 +62,17 @@ typedef struct _DRIVER_OBJECT_EXTENSION LIST_ENTRY InitDataListHead; } DRIVER_OBJECT_EXTENSION, *PDRIVER_OBJECT_EXTENSION; +typedef struct _MINIPORT_DEVICE_EXTENSION +{ + struct _MINIPORT *Miniport; + UCHAR HwDeviceExtension[0]; +} MINIPORT_DEVICE_EXTENSION, *PMINIPORT_DEVICE_EXTENSION; + typedef struct _MINIPORT { struct _FDO_DEVICE_EXTENSION *DeviceExtension; PHW_INITIALIZATION_DATA InitData; + PMINIPORT_DEVICE_EXTENSION MiniportExtension; } MINIPORT, *PMINIPORT; typedef struct _FDO_DEVICE_EXTENSION @@ -107,7 +115,7 @@ PortFdoPnp( /* miniport.c */ -VOID +NTSTATUS MiniportInitialize( _In_ PMINIPORT Miniport, _In_ PFDO_DEVICE_EXTENSION DeviceExtension,