From 37b5fc992878c343fa5f375862e4544119775cd1 Mon Sep 17 00:00:00 2001 From: Goldfish64 Date: Mon, 18 Jan 2021 20:38:07 -0600 Subject: [PATCH] OcAudioLib: Fix previous commit --- Library/OcAudioLib/OcAudioDump.c | 34 ++++++++++++------- Staging/AudioDxe/HdaCodec/HdaCodecInfo.c | 5 +-- .../HdaController/HdaControllerInfo.c | 10 +++--- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Library/OcAudioLib/OcAudioDump.c b/Library/OcAudioLib/OcAudioDump.c index 0819a3f4..3a2bad36 100644 --- a/Library/OcAudioLib/OcAudioDump.c +++ b/Library/OcAudioLib/OcAudioDump.c @@ -176,6 +176,7 @@ CHAR8 *mColors[HDA_CONFIG_DEFAULT_COLOR_OTHER + 1] = }; STATIC +EFIAPI VOID PrintHdaBuffer ( IN OUT CHAR8 **AsciiBuffer, @@ -190,14 +191,14 @@ PrintHdaBuffer ( CHAR8 *NewBuffer; UINTN NewBufferSize; - VA_START (Marker, FormatString); - AsciiVSPrint (Tmp, sizeof (Tmp), FormatString, Marker); - VA_END (Marker); - if (*AsciiBuffer == NULL) { return; } + VA_START (Marker, FormatString); + AsciiVSPrint (Tmp, sizeof (Tmp), FormatString, Marker); + VA_END (Marker); + Status = AsciiStrCatS (*AsciiBuffer, *AsciiBufferSize, Tmp); if (Status == EFI_BUFFER_TOO_SMALL) { if (OcOverflowMulUN (*AsciiBufferSize, 2, &NewBufferSize)) { @@ -205,6 +206,11 @@ PrintHdaBuffer ( } NewBuffer = ReallocatePool (*AsciiBufferSize, NewBufferSize, *AsciiBuffer); if (NewBuffer == NULL) { + FreePool (*AsciiBuffer); + + *AsciiBuffer = NULL; + *AsciiBufferSize = 0; + return; } @@ -616,11 +622,13 @@ OcAudioDump ( // // Save dumped controller data to file. // - UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"Controller%u.txt", Index); - Status = SetFileData (Root, TmpFileName, FileBuffer, AsciiStrSize (FileBuffer)); - DEBUG ((DEBUG_INFO, "OCAU: Dumped HDA controller %u info result - %r\n", Index, Status)); + if (FileBuffer != NULL) { + UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"Controller%u.txt", Index); + Status = SetFileData (Root, TmpFileName, FileBuffer, (UINT32) AsciiStrSize (FileBuffer)); + DEBUG ((DEBUG_INFO, "OCAU: Dumped HDA controller %u info result - %r\n", Index, Status)); - FreePool (FileBuffer); + FreePool (FileBuffer); + } } // @@ -714,11 +722,13 @@ OcAudioDump ( // // Save dumped codec data to file. // - UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"Codec%u.txt", Index); - Status = SetFileData (Root, TmpFileName, FileBuffer, AsciiStrSize (FileBuffer)); - DEBUG ((DEBUG_INFO, "OCAU: Dumped HDA codec %u info result - %r\n", Index, Status)); + if (FileBuffer != NULL) { + UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"Codec%u.txt", Index); + Status = SetFileData (Root, TmpFileName, FileBuffer, (UINT32) AsciiStrSize (FileBuffer)); + DEBUG ((DEBUG_INFO, "OCAU: Dumped HDA codec %u info result - %r\n", Index, Status)); - FreePool (FileBuffer); + FreePool (FileBuffer); + } } return EFI_SUCCESS; diff --git a/Staging/AudioDxe/HdaCodec/HdaCodecInfo.c b/Staging/AudioDxe/HdaCodec/HdaCodecInfo.c index 40770d3a..bca5f0be 100644 --- a/Staging/AudioDxe/HdaCodec/HdaCodecInfo.c +++ b/Staging/AudioDxe/HdaCodec/HdaCodecInfo.c @@ -33,8 +33,9 @@ HdaCodecInfoGetAddress ( { HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData; - ASSERT (This != NULL); - ASSERT (Address != NULL); + if (This == NULL || Address == NULL) { + return EFI_INVALID_PARAMETER; + } HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This); diff --git a/Staging/AudioDxe/HdaController/HdaControllerInfo.c b/Staging/AudioDxe/HdaController/HdaControllerInfo.c index 399e389e..fb9fbeb4 100644 --- a/Staging/AudioDxe/HdaController/HdaControllerInfo.c +++ b/Staging/AudioDxe/HdaController/HdaControllerInfo.c @@ -33,8 +33,9 @@ HdaControllerInfoGetName ( { HDA_CONTROLLER_INFO_PRIVATE_DATA *HdaPrivateData; - ASSERT (This != NULL); - ASSERT (Name != NULL); + if (This == NULL || Name == NULL) { + return EFI_INVALID_PARAMETER; + } HdaPrivateData = HDA_CONTROLLER_INFO_PRIVATE_DATA_FROM_THIS (This); *Name = HdaPrivateData->HdaControllerDev->Name; @@ -51,8 +52,9 @@ HdaControllerInfoGetVendorId ( { HDA_CONTROLLER_INFO_PRIVATE_DATA *HdaPrivateData; - ASSERT (This != NULL); - ASSERT (VendorId != NULL); + if (This == NULL || VendorId == NULL) { + return EFI_INVALID_PARAMETER; + } HdaPrivateData = HDA_CONTROLLER_INFO_PRIVATE_DATA_FROM_THIS (This); *VendorId = HdaPrivateData->HdaControllerDev->VendorId; -- GitLab