Skip to content

Commit 5adf81d

Browse files
author
Martin Drab
committed
[vioser]: Encapsulate pending read request completion in one function
Signed-Off-By: Martin Drab <[email protected]>
1 parent 1332ad1 commit 5adf81d

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

vioserial/sys/Port.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,26 +1269,38 @@ VOID VIOSerialPortWriteIoStop(IN WDFQUEUE Queue, IN WDFREQUEST Request, IN ULONG
12691269
TraceEvents(TRACE_LEVEL_ERROR, DBG_WRITE, "<-- %s\n", __FUNCTION__);
12701270
}
12711271

1272-
NTSTATUS VIOSerialPortEvtDeviceQueryRemove(WDFDEVICE Device)
1272+
static VOID VIOSerialPortCompletePendingRead(PVIOSERIAL_PORT Port, NTSTATUS Status, LONG_PTR Information)
12731273
{
12741274
WDFREQUEST readRequest = NULL;
1275-
PRAWPDO_VIOSERIAL_PORT pdoData = RawPdoSerialPortGetData(Device);
1276-
PVIOSERIAL_PORT port = pdoData->port;
12771275

12781276
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__);
12791277

1280-
WdfSpinLockAcquire(port->InBufLock);
1281-
readRequest = port->PendingReadRequest;
1282-
port->PendingReadRequest = NULL;
1278+
WdfSpinLockAcquire(Port->InBufLock);
1279+
readRequest = Port->PendingReadRequest;
1280+
Port->PendingReadRequest = NULL;
12831281
if (readRequest != NULL)
12841282
{
12851283
if (WdfRequestUnmarkCancelable(readRequest) != STATUS_CANCELLED)
12861284
{
1287-
WdfRequestCompleteWithInformation(readRequest, STATUS_END_OF_FILE, 0L);
1285+
WdfRequestCompleteWithInformation(readRequest, Status, Information);
12881286
}
12891287
}
12901288

1291-
WdfSpinLockRelease(port->InBufLock);
1289+
WdfSpinLockRelease(Port->InBufLock);
1290+
1291+
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__);
1292+
1293+
return;
1294+
}
1295+
1296+
NTSTATUS VIOSerialPortEvtDeviceQueryRemove(WDFDEVICE Device)
1297+
{
1298+
PRAWPDO_VIOSERIAL_PORT pdoData = RawPdoSerialPortGetData(Device);
1299+
PVIOSERIAL_PORT port = pdoData->port;
1300+
1301+
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__);
1302+
1303+
VIOSerialPortCompletePendingRead(port, STATUS_END_OF_FILE, 0);
12921304

12931305
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__);
12941306

@@ -1297,25 +1309,12 @@ NTSTATUS VIOSerialPortEvtDeviceQueryRemove(WDFDEVICE Device)
12971309

12981310
VOID VIOSerialPortEvtDeviceSurpriseRemoval(WDFDEVICE Device)
12991311
{
1300-
WDFREQUEST readRequest = NULL;
13011312
PRAWPDO_VIOSERIAL_PORT pdoData = RawPdoSerialPortGetData(Device);
13021313
PVIOSERIAL_PORT port = pdoData->port;
13031314

13041315
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__);
13051316

1306-
WdfSpinLockAcquire(port->InBufLock);
1307-
readRequest = port->PendingReadRequest;
1308-
port->PendingReadRequest = NULL;
1309-
if (readRequest != NULL)
1310-
{
1311-
if (WdfRequestUnmarkCancelable(readRequest) != STATUS_CANCELLED)
1312-
{
1313-
WdfRequestCompleteWithInformation(readRequest, STATUS_DELETE_PENDING, 0L);
1314-
}
1315-
}
1316-
1317-
port->Removed = TRUE;
1318-
WdfSpinLockRelease(port->InBufLock);
1317+
VIOSerialPortCompletePendingRead(port, STATUS_DELETE_PENDING, 0);
13191318

13201319
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__);
13211320

0 commit comments

Comments
 (0)