Skip to content
This repository has been archived by the owner on May 17, 2020. It is now read-only.

Commit

Permalink
AudioDxe: Fix use after free on PCI timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Apr 23, 2020
1 parent 384e85f commit 45eed55
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Platform/AudioDxe/HdaController/HdaControllerMem.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ HdaControllerInitStreams(
FreePool(HdaControllerDev->BidirStreams);
FreePool(HdaControllerDev->InputStreams);
FreePool(HdaControllerDev->OutputStreams);
HdaControllerDev->BidirStreams = NULL;
HdaControllerDev->InputStreams = NULL;
HdaControllerDev->OutputStreams = NULL;
HdaControllerDev->TotalStreamsCount = 0;
return Status;
}

Expand Down Expand Up @@ -570,37 +574,31 @@ HdaControllerResetStream(

// Get value of control register.
Status = PciIo->Mem.Read(PciIo, EfiPciIoWidthUint8, PCI_HDA_BAR, HDA_REG_SDNCTL1(HdaStream->Index), 1, &HdaStreamCtl1);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status))
return Status;

// Reset stream and wait for bit to be set.
HdaStreamCtl1 |= HDA_REG_SDNCTL1_SRST;
Status = PciIo->Mem.Write(PciIo, EfiPciIoWidthUint8, PCI_HDA_BAR, HDA_REG_SDNCTL1(HdaStream->Index), 1, &HdaStreamCtl1);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status))
return Status;
Status = PciIo->PollMem(PciIo, EfiPciIoWidthUint8, PCI_HDA_BAR, HDA_REG_SDNCTL1(HdaStream->Index),
HDA_REG_SDNCTL1_SRST, HDA_REG_SDNCTL1_SRST, MS_TO_NANOSECOND(100), &Tmp);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status))
return Status;

// Get value of control register.
Status = PciIo->Mem.Read(PciIo, EfiPciIoWidthUint8, PCI_HDA_BAR, HDA_REG_SDNCTL1(HdaStream->Index), 1, &HdaStreamCtl1);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status))
return Status;

// Docs state we need to clear the bit and wait for it to clear.
HdaStreamCtl1 &= ~HDA_REG_SDNCTL1_SRST;
Status = PciIo->Mem.Write(PciIo, EfiPciIoWidthUint8, PCI_HDA_BAR, HDA_REG_SDNCTL1(HdaStream->Index), 1, &HdaStreamCtl1);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status))
return Status;
Status = PciIo->PollMem(PciIo, EfiPciIoWidthUint8, PCI_HDA_BAR, HDA_REG_SDNCTL1(HdaStream->Index),
HDA_REG_SDNCTL1_SRST, 0, MS_TO_NANOSECOND(100), &Tmp);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status))
return Status;

Expand Down

0 comments on commit 45eed55

Please sign in to comment.