https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2a8fc2b411ad7b9676ed7…
commit 2a8fc2b411ad7b9676ed776dd25773289a141dbd
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Fri Jun 28 02:38:10 2019 +0300
Commit: Victor Perevertkin <victor(a)perevertkin.ru>
CommitDate: Fri Aug 16 19:08:04 2019 +0200
[USBOHCI_NEW] Refactor OHCI_AbortTransfer function
- Added SAL annotation
- Simplified local variables
- Replace counterintuitive `do {} while ()` loops with nice `for` loops
- Get rid of goto and its label, it can be simply avoided
---
drivers/usb/usbohci_new/usbohci.c | 111 ++++++++++++++------------------------
1 file changed, 40 insertions(+), 71 deletions(-)
diff --git a/drivers/usb/usbohci_new/usbohci.c b/drivers/usb/usbohci_new/usbohci.c
index b68cc4081cc..39986e47070 100644
--- a/drivers/usb/usbohci_new/usbohci.c
+++ b/drivers/usb/usbohci_new/usbohci.c
@@ -1660,6 +1660,14 @@ OHCI_ProcessDoneIsoTD(IN POHCI_EXTENSION OhciExtension,
DPRINT1("OHCI_ProcessDoneIsoTD: UNIMPLEMENTED. FIXME\n");
}
+/**
+ * @brief Aborts the transfer descriptor chain in a given endpoint
+ *
+ * @param[in] ohciExtension The ohci extension
+ * @param[in] ohciEndpoint The ohci endpoint
+ * @param[in] ohciTransfer The ohci transfer
+ * @param[out] CompletedLength
+ */
VOID
NTAPI
OHCI_AbortTransfer(IN PVOID ohciExtension,
@@ -1670,32 +1678,19 @@ OHCI_AbortTransfer(IN PVOID ohciExtension,
POHCI_EXTENSION OhciExtension = ohciExtension;
POHCI_ENDPOINT OhciEndpoint = ohciEndpoint;
POHCI_TRANSFER OhciTransfer = ohciTransfer;
- POHCI_TRANSFER TmpTransfer;
- POHCI_HCD_ED ED;
+ POHCI_HCD_ED ED = OhciEndpoint->HcdED;
ULONG_PTR NextTdPA;
- POHCI_HCD_TD NextTD;
- POHCI_HCD_TD TD;
- POHCI_HCD_TD PrevTD;
- POHCI_HCD_TD LastTD;
- POHCI_HCD_TD td = NULL;
+ POHCI_HCD_TD TD, NextTD, LastTD;
ULONG ix;
- BOOLEAN IsIsoEndpoint = FALSE;
+ BOOLEAN IsIsoEndpoint;
BOOLEAN IsProcessed = FALSE;
DPRINT("OHCI_AbortTransfer: ohciEndpoint - %p, ohciTransfer - %p\n",
OhciEndpoint,
OhciTransfer);
- if (OhciEndpoint->EndpointProperties.TransferType ==
- USBPORT_TRANSFER_TYPE_ISOCHRONOUS)
- {
- IsIsoEndpoint = TRUE;
- }
-
- ED = OhciEndpoint->HcdED;
- NextTdPA = ED->HwED.HeadPointer & OHCI_ED_HEAD_POINTER_MASK;
-
- NextTD = RegPacket.UsbPortGetMappedVirtualAddress(NextTdPA,
+ IsIsoEndpoint = (OhciEndpoint->EndpointProperties.TransferType ==
USBPORT_TRANSFER_TYPE_ISOCHRONOUS);
+ NextTD = RegPacket.UsbPortGetMappedVirtualAddress(ED->HwED.HeadPointer &
OHCI_ED_HEAD_POINTER_MASK,
OhciExtension,
OhciEndpoint);
@@ -1703,6 +1698,7 @@ OHCI_AbortTransfer(IN PVOID ohciExtension,
{
LastTD = OhciTransfer->NextTD;
+ /* Keeping the carry bit from previous pointer value */
ED->HwED.HeadPointer = LastTD->PhysicalAddress |
(ED->HwED.HeadPointer &
OHCI_ED_HEAD_POINTER_CARRY);
@@ -1712,94 +1708,67 @@ OHCI_AbortTransfer(IN PVOID ohciExtension,
{
TD = &OhciEndpoint->FirstTD[ix];
- if (TD->OhciTransfer == OhciTransfer)
- {
- if (IsIsoEndpoint)
- OHCI_ProcessDoneIsoTD(OhciExtension, TD, FALSE);
- else
- OHCI_ProcessDoneTD(OhciExtension, TD, FALSE);
- }
+ if (TD->OhciTransfer != OhciTransfer)
+ continue;
+
+ if (IsIsoEndpoint)
+ OHCI_ProcessDoneIsoTD(OhciExtension, TD, FALSE);
+ else
+ OHCI_ProcessDoneTD(OhciExtension, TD, FALSE);
}
*CompletedLength = OhciTransfer->TransferLen;
return;
}
- TD = OhciEndpoint->HcdHeadP;
-
- if (TD == NextTD)
- goto Exit;
+ if (NextTD == OhciEndpoint->HcdHeadP)
+ IsProcessed = TRUE;
- do
+ for (TD = OhciEndpoint->HcdHeadP; TD != NextTD; TD = TD->NextTDVa)
{
- if (TD->OhciTransfer == ohciTransfer)
- {
- PrevTD = TD;
- TD = TD->NextTDVa;
-
- if (PrevTD == OhciEndpoint->HcdHeadP)
- OhciEndpoint->HcdHeadP = TD;
+ if (TD->OhciTransfer != OhciTransfer)
+ continue;
- if (IsIsoEndpoint)
- OHCI_ProcessDoneIsoTD(OhciExtension, PrevTD, FALSE);
- else
- OHCI_ProcessDoneTD(OhciExtension, PrevTD, FALSE);
+ if (OhciEndpoint->HcdHeadP == TD)
+ OhciEndpoint->HcdHeadP = TD->NextTDVa;
- IsProcessed = TRUE;
- }
+ if (IsIsoEndpoint)
+ OHCI_ProcessDoneIsoTD(OhciExtension, TD, FALSE);
else
- {
- TD = TD->NextTDVa;
- }
+ OHCI_ProcessDoneTD(OhciExtension, TD, FALSE);
+
+ IsProcessed = TRUE;
}
- while (TD != NextTD);
if (!IsProcessed)
{
- TD = OhciEndpoint->HcdHeadP;
-
- LastTD = TD;
- td = NULL;
-
- while (TD != OhciEndpoint->HcdTailP)
+ for (TD = OhciEndpoint->HcdHeadP; TD->OhciTransfer != OhciTransfer; TD =
TD->NextTDVa)
{
- if (TD->OhciTransfer == OhciTransfer)
+ if (TD == OhciEndpoint->HcdTailP)
{
- td = TD;
+ TD = NULL;
break;
}
-
LastTD = TD;
-
- TD = TD->NextTDVa;
}
- TD = td;
-
- do
+ for (; TD->OhciTransfer == OhciTransfer; TD = TD->NextTDVa)
{
if (TD == OhciEndpoint->HcdTailP)
break;
- PrevTD = TD;
- TD = TD->NextTDVa;
-
if (IsIsoEndpoint)
- OHCI_ProcessDoneIsoTD(OhciExtension, PrevTD, FALSE);
+ OHCI_ProcessDoneIsoTD(OhciExtension, TD, FALSE);
else
- OHCI_ProcessDoneTD(OhciExtension, PrevTD, FALSE);
+ OHCI_ProcessDoneTD(OhciExtension, TD, FALSE);
}
- while (TD->OhciTransfer == OhciTransfer);
- TmpTransfer = LastTD->OhciTransfer;
- TmpTransfer->NextTD = TD;
+ LastTD->OhciTransfer->NextTD = TD;
LastTD->NextTDVa = TD;
LastTD->HwTD.gTD.NextTD = TD->PhysicalAddress;
}
-Exit:
-
*CompletedLength = OhciTransfer->TransferLen;
if (OhciTransfer->TransferLen)