]> xenbits.xensource.com Git - pvdrivers/win/xenvif.git/commitdiff
Allow PdoResume() to fail
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 15 Apr 2015 15:10:08 +0000 (16:10 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Mon, 20 Apr 2015 16:08:41 +0000 (17:08 +0100)
At the moment FrontendResume() can fail, but PdoResume() cannot and hence
the error status is ignored. This is problematic because it is not safe to
call FrontendSuspend() if FrontendResume() did not complete successfully.
This patch, therefore, wires through the failure of FrontendResume() into
PdoResume() and on into FdoAddPhysicalDeviceObject().

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenvif/fdo.c
src/xenvif/fdo.h
src/xenvif/pdo.c
src/xenvif/pdo.h

index 4b40777b27ae5e141f88eb0d51619f9a140f4e26..3f6713ba61c5186a32f7492a56b93dda64dae535 100644 (file)
@@ -614,7 +614,7 @@ FdoForwardIrpSynchronously(
     return status;
 }
 
-VOID
+NTSTATUS
 FdoAddPhysicalDeviceObject(
     IN  PXENVIF_FDO     Fdo,
     IN  PXENVIF_PDO     Pdo
@@ -622,17 +622,30 @@ FdoAddPhysicalDeviceObject(
 {
     PDEVICE_OBJECT      DeviceObject;
     PXENVIF_DX          Dx;
+    NTSTATUS            status;
 
     DeviceObject = PdoGetDeviceObject(Pdo);
     Dx = (PXENVIF_DX)DeviceObject->DeviceExtension;
     ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
 
+    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD3)
+        goto done;
+
+    status = PdoResume(Pdo);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+done:
     InsertTailList(&Fdo->Dx->ListEntry, &Dx->ListEntry);
     ASSERT3U(Fdo->References, !=, 0);
     Fdo->References++;
 
-    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD0)
-        PdoResume(Pdo);
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
 }
 
 VOID
@@ -648,9 +661,12 @@ FdoRemovePhysicalDeviceObject(
     Dx = (PXENVIF_DX)DeviceObject->DeviceExtension;
     ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
 
-    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD0)
-        PdoSuspend(Pdo);
+    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD3)
+        goto done;
 
+    PdoSuspend(Pdo);
+
+done:
     RemoveEntryList(&Dx->ListEntry);
     ASSERT3U(Fdo->References, !=, 0);
     --Fdo->References;
@@ -1176,7 +1192,8 @@ FdoD3ToD0(
 
         ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
 
-        PdoResume(Pdo);
+        status = PdoResume(Pdo);
+        ASSERT(NT_SUCCESS(status));
     }
 
     __FdoReleaseMutex(Fdo);
@@ -2881,6 +2898,8 @@ FdoCreate(
     if (!NT_SUCCESS(status))
         goto fail13;
 
+    Dx->Fdo = Fdo;
+
     InitializeMutex(&Fdo->Mutex);
     InitializeListHead(&Dx->ListEntry);
     Fdo->References = 1;
@@ -2889,9 +2908,7 @@ FdoCreate(
          FunctionDeviceObject,
          __FdoGetName(Fdo));
 
-    Dx->Fdo = Fdo;
     FunctionDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
-
     return STATUS_SUCCESS;
 
 fail13:
@@ -2996,10 +3013,10 @@ FdoDestroy(
          FunctionDeviceObject,
          __FdoGetName(Fdo));
 
-    Dx->Fdo = NULL;
-
     RtlZeroMemory(&Fdo->Mutex, sizeof (MUTEX));
 
+    Dx->Fdo = NULL;
+
     RtlZeroMemory(&Fdo->GnttabInterface,
                   sizeof (XENBUS_GNTTAB_INTERFACE));
 
index 78cfbfb8482ac5f5ebe8970e2f28f4e58a21d9e8..68d7b4a9503569de9aeb9d988fa3f568c09258ee 100644 (file)
@@ -55,7 +55,7 @@ FdoGetName(
     IN  PXENVIF_FDO Fdo
     );
 
-extern VOID
+extern NTSTATUS
 FdoAddPhysicalDeviceObject(
     IN  PXENVIF_FDO     Fdo,
     IN  PXENVIF_PDO     Pdo
index 9352594125023eb342d9865c9e5c1eb00fd59de8..dc7eacd011768c8d2b42edf941ab376d872a922e 100644 (file)
@@ -2552,16 +2552,12 @@ PdoDispatch(
     return status;
 }
 
-VOID
+NTSTATUS
 PdoResume(
-    IN  PXENVIF_PDO     Pdo
+    IN  PXENVIF_PDO Pdo
     )
 {
-    Trace("====>\n");
-
-    FrontendResume(__PdoGetFrontend(Pdo));
-
-    Trace("<====\n");
+    return FrontendResume(__PdoGetFrontend(Pdo));
 }
 
 VOID
@@ -2569,11 +2565,7 @@ PdoSuspend(
     IN  PXENVIF_PDO     Pdo
     )
 {
-    Trace("====>\n");
-
     FrontendSuspend(__PdoGetFrontend(Pdo));
-
-    Trace("<====\n");
 }
 
 NTSTATUS
@@ -2654,6 +2646,14 @@ PdoCreate(
 
     FdoGetSuspendInterface(Fdo,&Pdo->SuspendInterface);
 
+    Dx->Pdo = Pdo;
+
+    KeInitializeSpinLock(&Pdo->EjectLock);
+
+    status = FdoAddPhysicalDeviceObject(Fdo, Pdo);
+    if (!NT_SUCCESS(status))
+        goto fail11;
+
     for (Index = 0; Index < Pdo->Count; Index++) {
         Info("%p (%s %08X)\n",
              PhysicalDeviceObject,
@@ -2661,14 +2661,22 @@ PdoCreate(
              Pdo->Revision[Index]);
     }
 
-    Dx->Pdo = Pdo;
     PhysicalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
+    return STATUS_SUCCESS;
 
-    KeInitializeSpinLock(&Pdo->EjectLock);
+fail11:
+    Error("fail11\n");
 
-    FdoAddPhysicalDeviceObject(Fdo, Pdo);
+    (VOID) __PdoClearEjectRequested(Pdo);
+    RtlZeroMemory(&Pdo->EjectLock, sizeof (KSPIN_LOCK));
 
-    return STATUS_SUCCESS;
+    Dx->Pdo = NULL;
+
+    RtlZeroMemory(&Pdo->SuspendInterface,
+                  sizeof (XENBUS_SUSPEND_INTERFACE));
+
+    FrontendTeardown(__PdoGetFrontend(Pdo));
+    Pdo->Frontend = NULL;
 
 fail10:
     Error("fail10\n");
@@ -2762,17 +2770,20 @@ PdoDestroy(
 
     FdoRemovePhysicalDeviceObject(Fdo, Pdo);
 
+    (VOID) __PdoClearEjectRequested(Pdo);
+    RtlZeroMemory(&Pdo->EjectLock, sizeof (KSPIN_LOCK));
+
     Dx->Pdo = NULL;
 
     RtlZeroMemory(&Pdo->SuspendInterface,
                   sizeof (XENBUS_SUSPEND_INTERFACE));
 
-    VifTeardown(Pdo->VifContext);
-    Pdo->VifContext = NULL;
-    
     FrontendTeardown(__PdoGetFrontend(Pdo));
     Pdo->Frontend = NULL;    
 
+    VifTeardown(Pdo->VifContext);
+    Pdo->VifContext = NULL;
+
     BusTeardown(&Pdo->BusInterface);
 
     for (Index = 0; Index < Pdo->Count; Index++)
index 76ff3a42bb447507bc5f48e67638f090a123f0ad..13dbe81eaa18b3e3857c54756ca2a85823c5897a 100644 (file)
@@ -144,7 +144,7 @@ PdoCreate(
     IN  PCHAR       Address
     );
 
-extern VOID
+extern NTSTATUS
 PdoResume(
     IN  PXENVIF_PDO Pdo
     );