From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id CA5B7D8023C for ; Thu, 26 Oct 2023 23:54:05 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=8pZIqjI97wah7LnWptr5M4dKYQd1vL8O3Ahbvo2O1SM=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698364444; v=1; b=bezPOiibY3CUFBblLdJXgyQI3+WW5/MScLpfx2bYO6nN2Ua3hYnZlGj9BLpirM0AtYb692ap EGWrsd1CXL4BdzP12PVCu73F7WSQv7DoTOF1Ia8ZAgM/Sjg34AUH3XgiydGu8fAxfnZ37c/kxNL oR2L/qQwHDH84TZPgoixk25w= X-Received: by 127.0.0.2 with SMTP id uZ2vYY7687511x8EmzJUZqR1; Thu, 26 Oct 2023 16:54:04 -0700 X-Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by mx.groups.io with SMTP id smtpd.web11.86066.1698364443182308202 for ; Thu, 26 Oct 2023 16:54:03 -0700 X-Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5079f3f3d7aso2337110e87.1 for ; Thu, 26 Oct 2023 16:54:02 -0700 (PDT) X-Gm-Message-State: dfTilcaYJouJ1RWJisSNOTB6x7686176AA= X-Google-Smtp-Source: AGHT+IHwE8WYPe5u46yPJ9XaT76x69Y9WVvSVr1Twd8S5asFjcQ/drcJLEPcOoRC+dIG8XRQ/lsZxQ== X-Received: by 2002:ac2:58ca:0:b0:507:9fa0:e244 with SMTP id u10-20020ac258ca000000b005079fa0e244mr562115lfo.65.1698364441082; Thu, 26 Oct 2023 16:54:01 -0700 (PDT) X-Received: from localhost.localdomain ([79.164.221.98]) by smtp.gmail.com with ESMTPSA id u8-20020a056512040800b00507a8789b43sm39389lfk.269.2023.10.26.16.54.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 26 Oct 2023 16:54:00 -0700 (PDT) From: "Mike Maslenkin" To: devel@edk2.groups.io Cc: abner.chang@amd.com, nicklew@nvidia.com, igork@ami.com, Mike Maslenkin Subject: [edk2-devel] [edk2-redfish-client][PATCH v2 05/11] RedfishClientPkg: reduce identation level by adding early return Date: Fri, 27 Oct 2023 02:53:48 +0300 Message-Id: <20231026235354.67625-6-mike.maslenkin@gmail.com> In-Reply-To: <20231026235354.67625-1-mike.maslenkin@gmail.com> References: <20231026235354.67625-1-mike.maslenkin@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mike.maslenkin@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=bezPOiib; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) This functions contain memory leaks. Less identation helps to solve this issues. Signed-off-by: Mike Maslenkin --- .../RedfishFeatureUtilityLib.c | 289 +++++++++--------- 1 file changed, 146 insertions(+), 143 deletions(-) diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatu= reUtilityLib.c b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishF= eatureUtilityLib.c index 8fa1dc2c3535..0941f33fd73a 100644 --- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.c +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.c @@ -763,68 +763,69 @@ ApplyFeatureSettingsStringArrayType ( Status =3D RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang= , &RedfishValue);=0D if (EFI_ERROR (Status)) {=0D DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Ve= rsion, ConfigureLang, Status));=0D - } else {=0D - if (RedfishValue.Type !=3D RedfishValueTypeStringArray) {=0D - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n"= , __func__, Schema, Version, ConfigureLang));=0D - return EFI_DEVICE_ERROR;=0D - }=0D + return Status;=0D + }=0D +=0D + if (RedfishValue.Type !=3D RedfishValueTypeStringArray) {=0D + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", = __func__, Schema, Version, ConfigureLang));=0D + return EFI_DEVICE_ERROR;=0D + }=0D =0D + //=0D + // If there is no change in array, do nothing=0D + //=0D + if (!CompareRedfishStringArrayValues (ArrayHead, RedfishValue.Value.Stri= ngArray, RedfishValue.ArrayCount)) {=0D //=0D - // If there is no change in array, do nothing=0D + // Apply settings from redfish=0D //=0D - if (!CompareRedfishStringArrayValues (ArrayHead, RedfishValue.Value.St= ringArray, RedfishValue.ArrayCount)) {=0D - //=0D - // Apply settings from redfish=0D - //=0D - DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __fun= c__, Schema, Version, ConfigureLang));=0D - FreeArrayTypeRedfishValue (&RedfishValue);=0D + DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func_= _, Schema, Version, ConfigureLang));=0D + FreeArrayTypeRedfishValue (&RedfishValue);=0D =0D - //=0D - // Convert array from RedfishCS_char_Array to EDKII_REDFISH_VALUE=0D - //=0D - RedfishValue.ArrayCount =3D 0;=0D - Buffer =3D ArrayHead;=0D - while (Buffer !=3D NULL) {=0D - RedfishValue.ArrayCount +=3D 1;=0D - Buffer =3D Buffer->Next;=0D - }=0D + //=0D + // Convert array from RedfishCS_char_Array to EDKII_REDFISH_VALUE=0D + //=0D + RedfishValue.ArrayCount =3D 0;=0D + Buffer =3D ArrayHead;=0D + while (Buffer !=3D NULL) {=0D + RedfishValue.ArrayCount +=3D 1;=0D + Buffer =3D Buffer->Next;=0D + }=0D =0D - //=0D - // Allocate pool for new values=0D - //=0D - RedfishValue.Value.StringArray =3D AllocatePool (RedfishValue.ArrayC= ount *sizeof (CHAR8 *));=0D - if (RedfishValue.Value.StringArray =3D=3D NULL) {=0D + //=0D + // Allocate pool for new values=0D + //=0D + RedfishValue.Value.StringArray =3D AllocatePool (RedfishValue.ArrayCou= nt *sizeof (CHAR8 *));=0D + if (RedfishValue.Value.StringArray =3D=3D NULL) {=0D + ASSERT (FALSE);=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + Buffer =3D ArrayHead;=0D + Index =3D 0;=0D + while (Buffer !=3D NULL) {=0D + RedfishValue.Value.StringArray[Index] =3D AllocateCopyPool (AsciiStr= Size (Buffer->ArrayValue), Buffer->ArrayValue);=0D + if (RedfishValue.Value.StringArray[Index] =3D=3D NULL) {=0D ASSERT (FALSE);=0D return EFI_OUT_OF_RESOURCES;=0D }=0D =0D - Buffer =3D ArrayHead;=0D - Index =3D 0;=0D - while (Buffer !=3D NULL) {=0D - RedfishValue.Value.StringArray[Index] =3D AllocateCopyPool (AsciiS= trSize (Buffer->ArrayValue), Buffer->ArrayValue);=0D - if (RedfishValue.Value.StringArray[Index] =3D=3D NULL) {=0D - ASSERT (FALSE);=0D - return EFI_OUT_OF_RESOURCES;=0D - }=0D -=0D - Buffer =3D Buffer->Next;=0D - Index++;=0D - }=0D + Buffer =3D Buffer->Next;=0D + Index++;=0D + }=0D =0D - ASSERT (Index <=3D RedfishValue.ArrayCount);=0D + ASSERT (Index <=3D RedfishValue.ArrayCount);=0D =0D - Status =3D RedfishPlatformConfigSetValue (Schema, Version, Configure= Lang, RedfishValue);=0D - if (!EFI_ERROR (Status)) {=0D - //=0D - // Configuration changed. Enable system reboot flag.=0D - //=0D - REDFISH_ENABLE_SYSTEM_REBOOT ();=0D - } else {=0D - DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, = ConfigureLang, Status));=0D - }=0D + Status =3D RedfishPlatformConfigSetValue (Schema, Version, ConfigureLa= ng, RedfishValue);=0D + if (!EFI_ERROR (Status)) {=0D + //=0D + // Configuration changed. Enable system reboot flag.=0D + //=0D + REDFISH_ENABLE_SYSTEM_REBOOT ();=0D } else {=0D - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __f= unc__, Schema, Version, ConfigureLang));=0D + DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, Co= nfigureLang, Status));=0D }=0D + } else {=0D + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __fun= c__, Schema, Version, ConfigureLang));=0D }=0D =0D return Status;=0D @@ -866,63 +867,64 @@ ApplyFeatureSettingsNumericArrayType ( Status =3D RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang= , &RedfishValue);=0D if (EFI_ERROR (Status)) {=0D DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Ve= rsion, ConfigureLang, Status));=0D - } else {=0D - if (RedfishValue.Type !=3D RedfishValueTypeIntegerArray) {=0D - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n"= , __func__, Schema, Version, ConfigureLang));=0D - return EFI_DEVICE_ERROR;=0D - }=0D + return Status;=0D + }=0D +=0D + if (RedfishValue.Type !=3D RedfishValueTypeIntegerArray) {=0D + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", = __func__, Schema, Version, ConfigureLang));=0D + return EFI_DEVICE_ERROR;=0D + }=0D =0D + //=0D + // If there is no change in array, do nothing=0D + //=0D + if (!CompareRedfishNumericArrayValues (ArrayHead, RedfishValue.Value.Int= egerArray, RedfishValue.ArrayCount)) {=0D //=0D - // If there is no change in array, do nothing=0D + // Apply settings from redfish=0D //=0D - if (!CompareRedfishNumericArrayValues (ArrayHead, RedfishValue.Value.I= ntegerArray, RedfishValue.ArrayCount)) {=0D - //=0D - // Apply settings from redfish=0D - //=0D - DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __fun= c__, Schema, Version, ConfigureLang));=0D - FreeArrayTypeRedfishValue (&RedfishValue);=0D + DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func_= _, Schema, Version, ConfigureLang));=0D + FreeArrayTypeRedfishValue (&RedfishValue);=0D =0D - //=0D - // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE=0D - //=0D - RedfishValue.ArrayCount =3D 0;=0D - Buffer =3D ArrayHead;=0D - while (Buffer !=3D NULL) {=0D - RedfishValue.ArrayCount +=3D 1;=0D - Buffer =3D Buffer->Next;=0D - }=0D + //=0D + // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE=0D + //=0D + RedfishValue.ArrayCount =3D 0;=0D + Buffer =3D ArrayHead;=0D + while (Buffer !=3D NULL) {=0D + RedfishValue.ArrayCount +=3D 1;=0D + Buffer =3D Buffer->Next;=0D + }=0D =0D - //=0D - // Allocate pool for new values=0D - //=0D - RedfishValue.Value.IntegerArray =3D AllocatePool (RedfishValue.Array= Count * sizeof (INT64));=0D - if (RedfishValue.Value.IntegerArray =3D=3D NULL) {=0D - ASSERT (FALSE);=0D - return EFI_OUT_OF_RESOURCES;=0D - }=0D + //=0D + // Allocate pool for new values=0D + //=0D + RedfishValue.Value.IntegerArray =3D AllocatePool (RedfishValue.ArrayCo= unt * sizeof (INT64));=0D + if (RedfishValue.Value.IntegerArray =3D=3D NULL) {=0D + ASSERT (FALSE);=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D =0D - Buffer =3D ArrayHead;=0D - Index =3D 0;=0D - while (Buffer !=3D NULL) {=0D - RedfishValue.Value.IntegerArray[Index] =3D (INT64)*Buffer->ArrayVa= lue;=0D - Buffer =3D Buffer->Next;=0D - Index++;=0D - }=0D + Buffer =3D ArrayHead;=0D + Index =3D 0;=0D + while (Buffer !=3D NULL) {=0D + RedfishValue.Value.IntegerArray[Index] =3D (INT64)*Buffer->ArrayValu= e;=0D + Buffer =3D Buffer->Next;=0D + Index++;=0D + }=0D =0D - ASSERT (Index <=3D RedfishValue.ArrayCount);=0D + ASSERT (Index <=3D RedfishValue.ArrayCount);=0D =0D - Status =3D RedfishPlatformConfigSetValue (Schema, Version, Configure= Lang, RedfishValue);=0D - if (!EFI_ERROR (Status)) {=0D - //=0D - // Configuration changed. Enable system reboot flag.=0D - //=0D - REDFISH_ENABLE_SYSTEM_REBOOT ();=0D - } else {=0D - DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, = ConfigureLang, Status));=0D - }=0D + Status =3D RedfishPlatformConfigSetValue (Schema, Version, ConfigureLa= ng, RedfishValue);=0D + if (!EFI_ERROR (Status)) {=0D + //=0D + // Configuration changed. Enable system reboot flag.=0D + //=0D + REDFISH_ENABLE_SYSTEM_REBOOT ();=0D } else {=0D - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __f= unc__, Schema, Version, ConfigureLang));=0D + DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, Co= nfigureLang, Status));=0D }=0D + } else {=0D + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __fun= c__, Schema, Version, ConfigureLang));=0D }=0D =0D return Status;=0D @@ -964,63 +966,64 @@ ApplyFeatureSettingsBooleanArrayType ( Status =3D RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang= , &RedfishValue);=0D if (EFI_ERROR (Status)) {=0D DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Ve= rsion, ConfigureLang, Status));=0D - } else {=0D - if (RedfishValue.Type !=3D RedfishValueTypeBooleanArray) {=0D - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n"= , __func__, Schema, Version, ConfigureLang));=0D - return EFI_DEVICE_ERROR;=0D - }=0D + return Status;=0D + }=0D +=0D + if (RedfishValue.Type !=3D RedfishValueTypeBooleanArray) {=0D + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", = __func__, Schema, Version, ConfigureLang));=0D + return EFI_DEVICE_ERROR;=0D + }=0D =0D + //=0D + // If there is no change in array, do nothing=0D + //=0D + if (!CompareRedfishBooleanArrayValues (ArrayHead, RedfishValue.Value.Boo= leanArray, RedfishValue.ArrayCount)) {=0D //=0D - // If there is no change in array, do nothing=0D + // Apply settings from redfish=0D //=0D - if (!CompareRedfishBooleanArrayValues (ArrayHead, RedfishValue.Value.B= ooleanArray, RedfishValue.ArrayCount)) {=0D - //=0D - // Apply settings from redfish=0D - //=0D - DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __fun= c__, Schema, Version, ConfigureLang));=0D - FreeArrayTypeRedfishValue (&RedfishValue);=0D + DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func_= _, Schema, Version, ConfigureLang));=0D + FreeArrayTypeRedfishValue (&RedfishValue);=0D =0D - //=0D - // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE=0D - //=0D - RedfishValue.ArrayCount =3D 0;=0D - Buffer =3D ArrayHead;=0D - while (Buffer !=3D NULL) {=0D - RedfishValue.ArrayCount +=3D 1;=0D - Buffer =3D Buffer->Next;=0D - }=0D + //=0D + // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE=0D + //=0D + RedfishValue.ArrayCount =3D 0;=0D + Buffer =3D ArrayHead;=0D + while (Buffer !=3D NULL) {=0D + RedfishValue.ArrayCount +=3D 1;=0D + Buffer =3D Buffer->Next;=0D + }=0D =0D - //=0D - // Allocate pool for new values=0D - //=0D - RedfishValue.Value.BooleanArray =3D AllocatePool (RedfishValue.Array= Count * sizeof (BOOLEAN));=0D - if (RedfishValue.Value.BooleanArray =3D=3D NULL) {=0D - ASSERT (FALSE);=0D - return EFI_OUT_OF_RESOURCES;=0D - }=0D + //=0D + // Allocate pool for new values=0D + //=0D + RedfishValue.Value.BooleanArray =3D AllocatePool (RedfishValue.ArrayCo= unt * sizeof (BOOLEAN));=0D + if (RedfishValue.Value.BooleanArray =3D=3D NULL) {=0D + ASSERT (FALSE);=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D =0D - Buffer =3D ArrayHead;=0D - Index =3D 0;=0D - while (Buffer !=3D NULL) {=0D - RedfishValue.Value.BooleanArray[Index] =3D (BOOLEAN)*Buffer->Array= Value;=0D - Buffer =3D Buffer->Next;=0D - Index++;=0D - }=0D + Buffer =3D ArrayHead;=0D + Index =3D 0;=0D + while (Buffer !=3D NULL) {=0D + RedfishValue.Value.BooleanArray[Index] =3D (BOOLEAN)*Buffer->ArrayVa= lue;=0D + Buffer =3D Buffer->Next;=0D + Index++;=0D + }=0D =0D - ASSERT (Index <=3D RedfishValue.ArrayCount);=0D + ASSERT (Index <=3D RedfishValue.ArrayCount);=0D =0D - Status =3D RedfishPlatformConfigSetValue (Schema, Version, Configure= Lang, RedfishValue);=0D - if (!EFI_ERROR (Status)) {=0D - //=0D - // Configuration changed. Enable system reboot flag.=0D - //=0D - REDFISH_ENABLE_SYSTEM_REBOOT ();=0D - } else {=0D - DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, = ConfigureLang, Status));=0D - }=0D + Status =3D RedfishPlatformConfigSetValue (Schema, Version, ConfigureLa= ng, RedfishValue);=0D + if (!EFI_ERROR (Status)) {=0D + //=0D + // Configuration changed. Enable system reboot flag.=0D + //=0D + REDFISH_ENABLE_SYSTEM_REBOOT ();=0D } else {=0D - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __f= unc__, Schema, Version, ConfigureLang));=0D + DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, Co= nfigureLang, Status));=0D }=0D + } else {=0D + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __fun= c__, Schema, Version, ConfigureLang));=0D }=0D =0D return Status;=0D --=20 2.32.0 (Apple Git-132) -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110150): https://edk2.groups.io/g/devel/message/110150 Mute This Topic: https://groups.io/mt/102211774/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-