From d1c21f8d557f01cd82e06d6b9b6900dec8e6b373 Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Thu, 14 Dec 2023 03:18:57 +0300 Subject: RedfishDiscoverDxe: refine InitInformationData() function Cache size of ASCII string in local variable. Cc: Nickle Wang Cc: Igor Kulchytskyy Signed-off-by: Mike Maslenkin Reviewed-by: Abner Chang --- RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c index 7260efe6ad..e673de8ef7 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c @@ -738,39 +738,47 @@ InitInformationData ( IN CONST CHAR8 *ProductVer OPTIONAL ) { + UINTN AllocationSize; + if (RedfishVersion != NULL) { Information->RedfishVersion = *RedfishVersion; DEBUG ((DEBUG_MANAGEABILITY, "Redfish service version: %d.\n", Information->RedfishVersion)); } if (RedfishLocation != NULL) { - Information->Location = AllocatePool (AsciiStrSize (RedfishLocation) * sizeof (CHAR16)); - AsciiStrToUnicodeStrS (RedfishLocation, Information->Location, AsciiStrSize (RedfishLocation) * sizeof (CHAR16)); + AllocationSize = AsciiStrSize (RedfishLocation) * sizeof (CHAR16); + Information->Location = AllocatePool (AllocationSize); + AsciiStrToUnicodeStrS (RedfishLocation, Information->Location, AllocationSize); DEBUG ((DEBUG_MANAGEABILITY, "Redfish service location: %s.\n", Information->Location)); } if (Uuid != NULL) { - Information->Uuid = AllocatePool (AsciiStrSize (Uuid) * sizeof (CHAR16)); - AsciiStrToUnicodeStrS (Uuid, Information->Uuid, AsciiStrSize (Uuid) * sizeof (CHAR16)); + AllocationSize = AsciiStrSize (Uuid) * sizeof (CHAR16); + Information->Uuid = AllocatePool (AllocationSize); + AsciiStrToUnicodeStrS (Uuid, Information->Uuid, AllocationSize); DEBUG ((DEBUG_MANAGEABILITY, "Service UUID: %s.\n", Information->Uuid)); } if (Os != NULL) { - Information->Os = AllocatePool (AsciiStrSize (Os) * sizeof (CHAR16)); - AsciiStrToUnicodeStrS (Os, Information->Os, AsciiStrSize (Os) * sizeof (CHAR16)); - DEBUG ((DEBUG_MANAGEABILITY, "Redfish service OS: %s, Version:%s.\n", Information->Os, Information->OsVersion)); + AllocationSize = AsciiStrSize (Os) * sizeof (CHAR16); + Information->Os = AllocatePool (AllocationSize); + AsciiStrToUnicodeStrS (Os, Information->Os, AllocationSize); } if (OsVer != NULL) { - Information->OsVersion = AllocatePool (AsciiStrSize (OsVer) * sizeof (CHAR16)); - AsciiStrToUnicodeStrS (OsVer, Information->OsVersion, AsciiStrSize (OsVer) * sizeof (CHAR16)); + AllocationSize = AsciiStrSize (OsVer) * sizeof (CHAR16); + Information->OsVersion = AllocatePool (AllocationSize); + AsciiStrToUnicodeStrS (OsVer, Information->OsVersion, AllocationSize); + DEBUG ((DEBUG_MANAGEABILITY, "Redfish service OS: %s, Version:%s.\n", Information->Os, Information->OsVersion)); } if ((Product != NULL) && (ProductVer != NULL)) { - Information->Product = AllocatePool (AsciiStrSize (Product) * sizeof (CHAR16)); - AsciiStrToUnicodeStrS (Product, Information->Product, AsciiStrSize (Product) * sizeof (CHAR16)); - Information->ProductVer = AllocatePool (AsciiStrSize (ProductVer) * sizeof (CHAR16)); - AsciiStrToUnicodeStrS (ProductVer, Information->ProductVer, AsciiStrSize (ProductVer) * sizeof (CHAR16)); + AllocationSize = AsciiStrSize (Product) * sizeof (CHAR16); + Information->Product = AllocatePool (AllocationSize); + AsciiStrToUnicodeStrS (Product, Information->Product, AllocationSize); + AllocationSize = AsciiStrSize (ProductVer) * sizeof (CHAR16); + Information->ProductVer = AllocatePool (AllocationSize); + AsciiStrToUnicodeStrS (ProductVer, Information->ProductVer, AllocationSize); DEBUG ((DEBUG_MANAGEABILITY, "Redfish service product: %s, Version:%s.\n", Information->Product, Information->ProductVer)); } } -- cgit v1.2.3