From nobody Mon Feb 9 18:43:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110150+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110150+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1698364444; cv=none; d=zohomail.com; s=zohoarc; b=RY0Vjw4tG07jnYENjAn2sLYmvgW5g2QBkXvbFag6HYqa09L/sTysqvXgH03lfYtBpXSkUBo7V3HlsDhiJagAoNmFhaYYvJ782adaiiRsn75mSC2a+pmVtAPD6uZL/n3uKCIWsULOKo3DjCbagB9TrNmKufBp5xvZFuu0v80t38k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698364444; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=BUNHWiRJRuTHLwXOa8lr2Rb56Nz6I+a1qhPfxA0W7CU=; b=geJOK/h/VMkPsHSGAhmi//x/KovZWi9tzSVbxvZQhq18fgxk9Vjsp2w+QXN1PqRK6eDs1O+d81uVc38hj/ADQYQUIaErS5qoUJN1s06xTlXHflk0hI9SQ75KLbP3uzD/qRrAvfdEMGhhwu8rt9a5/riU3O3SV+COGuL5AVrn8+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110150+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1698364444421465.054903648077; Thu, 26 Oct 2023 16:54:04 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=+n4NqtS+SGsnF5QfRfdW4W6KzkYWCjAn5+jSMZGCZ20=; 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=rQCCbKWigJwiCQIHtUMgmoWNlMg7vgGc+x+HfutRlWoNfBgW6YpkY5soih+rypKw1kDtCFMN T6l79qBsp7FFVDOdn4MVDu7kcQAFhJ600y8cteQxX9Kf5OiRXH8IXDN9xDhr8FL/RDGrnzj+lz2 wvk/ZFDPaBhEz6AgfDNcodc8= X-Received: by 127.0.0.2 with SMTP id PsDQYY1788612xpu11SQdo4S; 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: k1SBjhwSBb9qcxWinEB9Ni1Sx1787277AA= 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-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698364445699100023 Content-Type: text/plain; charset="utf-8" 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); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Ve= rsion, ConfigureLang, Status)); - } else { - if (RedfishValue.Type !=3D RedfishValueTypeStringArray) { - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n"= , __func__, Schema, Version, ConfigureLang)); - return EFI_DEVICE_ERROR; - } + return Status; + } + + if (RedfishValue.Type !=3D RedfishValueTypeStringArray) { + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", = __func__, Schema, Version, ConfigureLang)); + return EFI_DEVICE_ERROR; + } =20 + // + // If there is no change in array, do nothing + // + if (!CompareRedfishStringArrayValues (ArrayHead, RedfishValue.Value.Stri= ngArray, RedfishValue.ArrayCount)) { // - // If there is no change in array, do nothing + // Apply settings from redfish // - if (!CompareRedfishStringArrayValues (ArrayHead, RedfishValue.Value.St= ringArray, RedfishValue.ArrayCount)) { - // - // Apply settings from redfish - // - DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __fun= c__, Schema, Version, ConfigureLang)); - FreeArrayTypeRedfishValue (&RedfishValue); + DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func_= _, Schema, Version, ConfigureLang)); + FreeArrayTypeRedfishValue (&RedfishValue); =20 - // - // Convert array from RedfishCS_char_Array to EDKII_REDFISH_VALUE - // - RedfishValue.ArrayCount =3D 0; - Buffer =3D ArrayHead; - while (Buffer !=3D NULL) { - RedfishValue.ArrayCount +=3D 1; - Buffer =3D Buffer->Next; - } + // + // Convert array from RedfishCS_char_Array to EDKII_REDFISH_VALUE + // + RedfishValue.ArrayCount =3D 0; + Buffer =3D ArrayHead; + while (Buffer !=3D NULL) { + RedfishValue.ArrayCount +=3D 1; + Buffer =3D Buffer->Next; + } =20 - // - // Allocate pool for new values - // - RedfishValue.Value.StringArray =3D AllocatePool (RedfishValue.ArrayC= ount *sizeof (CHAR8 *)); - if (RedfishValue.Value.StringArray =3D=3D NULL) { + // + // Allocate pool for new values + // + RedfishValue.Value.StringArray =3D AllocatePool (RedfishValue.ArrayCou= nt *sizeof (CHAR8 *)); + if (RedfishValue.Value.StringArray =3D=3D NULL) { + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; + } + + Buffer =3D ArrayHead; + Index =3D 0; + while (Buffer !=3D NULL) { + RedfishValue.Value.StringArray[Index] =3D AllocateCopyPool (AsciiStr= Size (Buffer->ArrayValue), Buffer->ArrayValue); + if (RedfishValue.Value.StringArray[Index] =3D=3D NULL) { ASSERT (FALSE); return EFI_OUT_OF_RESOURCES; } =20 - Buffer =3D ArrayHead; - Index =3D 0; - while (Buffer !=3D NULL) { - RedfishValue.Value.StringArray[Index] =3D AllocateCopyPool (AsciiS= trSize (Buffer->ArrayValue), Buffer->ArrayValue); - if (RedfishValue.Value.StringArray[Index] =3D=3D NULL) { - ASSERT (FALSE); - return EFI_OUT_OF_RESOURCES; - } - - Buffer =3D Buffer->Next; - Index++; - } + Buffer =3D Buffer->Next; + Index++; + } =20 - ASSERT (Index <=3D RedfishValue.ArrayCount); + ASSERT (Index <=3D RedfishValue.ArrayCount); =20 - Status =3D RedfishPlatformConfigSetValue (Schema, Version, Configure= Lang, RedfishValue); - if (!EFI_ERROR (Status)) { - // - // Configuration changed. Enable system reboot flag. - // - REDFISH_ENABLE_SYSTEM_REBOOT (); - } else { - DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, = ConfigureLang, Status)); - } + Status =3D RedfishPlatformConfigSetValue (Schema, Version, ConfigureLa= ng, RedfishValue); + if (!EFI_ERROR (Status)) { + // + // Configuration changed. Enable system reboot flag. + // + REDFISH_ENABLE_SYSTEM_REBOOT (); } else { - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __f= unc__, Schema, Version, ConfigureLang)); + DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, Co= nfigureLang, Status)); } + } else { + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __fun= c__, Schema, Version, ConfigureLang)); } =20 return Status; @@ -866,63 +867,64 @@ ApplyFeatureSettingsNumericArrayType ( Status =3D RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang= , &RedfishValue); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Ve= rsion, ConfigureLang, Status)); - } else { - if (RedfishValue.Type !=3D RedfishValueTypeIntegerArray) { - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n"= , __func__, Schema, Version, ConfigureLang)); - return EFI_DEVICE_ERROR; - } + return Status; + } + + if (RedfishValue.Type !=3D RedfishValueTypeIntegerArray) { + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", = __func__, Schema, Version, ConfigureLang)); + return EFI_DEVICE_ERROR; + } =20 + // + // If there is no change in array, do nothing + // + if (!CompareRedfishNumericArrayValues (ArrayHead, RedfishValue.Value.Int= egerArray, RedfishValue.ArrayCount)) { // - // If there is no change in array, do nothing + // Apply settings from redfish // - if (!CompareRedfishNumericArrayValues (ArrayHead, RedfishValue.Value.I= ntegerArray, RedfishValue.ArrayCount)) { - // - // Apply settings from redfish - // - DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __fun= c__, Schema, Version, ConfigureLang)); - FreeArrayTypeRedfishValue (&RedfishValue); + DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func_= _, Schema, Version, ConfigureLang)); + FreeArrayTypeRedfishValue (&RedfishValue); =20 - // - // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE - // - RedfishValue.ArrayCount =3D 0; - Buffer =3D ArrayHead; - while (Buffer !=3D NULL) { - RedfishValue.ArrayCount +=3D 1; - Buffer =3D Buffer->Next; - } + // + // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE + // + RedfishValue.ArrayCount =3D 0; + Buffer =3D ArrayHead; + while (Buffer !=3D NULL) { + RedfishValue.ArrayCount +=3D 1; + Buffer =3D Buffer->Next; + } =20 - // - // Allocate pool for new values - // - RedfishValue.Value.IntegerArray =3D AllocatePool (RedfishValue.Array= Count * sizeof (INT64)); - if (RedfishValue.Value.IntegerArray =3D=3D NULL) { - ASSERT (FALSE); - return EFI_OUT_OF_RESOURCES; - } + // + // Allocate pool for new values + // + RedfishValue.Value.IntegerArray =3D AllocatePool (RedfishValue.ArrayCo= unt * sizeof (INT64)); + if (RedfishValue.Value.IntegerArray =3D=3D NULL) { + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; + } =20 - Buffer =3D ArrayHead; - Index =3D 0; - while (Buffer !=3D NULL) { - RedfishValue.Value.IntegerArray[Index] =3D (INT64)*Buffer->ArrayVa= lue; - Buffer =3D Buffer->Next; - Index++; - } + Buffer =3D ArrayHead; + Index =3D 0; + while (Buffer !=3D NULL) { + RedfishValue.Value.IntegerArray[Index] =3D (INT64)*Buffer->ArrayValu= e; + Buffer =3D Buffer->Next; + Index++; + } =20 - ASSERT (Index <=3D RedfishValue.ArrayCount); + ASSERT (Index <=3D RedfishValue.ArrayCount); =20 - Status =3D RedfishPlatformConfigSetValue (Schema, Version, Configure= Lang, RedfishValue); - if (!EFI_ERROR (Status)) { - // - // Configuration changed. Enable system reboot flag. - // - REDFISH_ENABLE_SYSTEM_REBOOT (); - } else { - DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, = ConfigureLang, Status)); - } + Status =3D RedfishPlatformConfigSetValue (Schema, Version, ConfigureLa= ng, RedfishValue); + if (!EFI_ERROR (Status)) { + // + // Configuration changed. Enable system reboot flag. + // + REDFISH_ENABLE_SYSTEM_REBOOT (); } else { - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __f= unc__, Schema, Version, ConfigureLang)); + DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, Co= nfigureLang, Status)); } + } else { + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __fun= c__, Schema, Version, ConfigureLang)); } =20 return Status; @@ -964,63 +966,64 @@ ApplyFeatureSettingsBooleanArrayType ( Status =3D RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang= , &RedfishValue); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Ve= rsion, ConfigureLang, Status)); - } else { - if (RedfishValue.Type !=3D RedfishValueTypeBooleanArray) { - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n"= , __func__, Schema, Version, ConfigureLang)); - return EFI_DEVICE_ERROR; - } + return Status; + } + + if (RedfishValue.Type !=3D RedfishValueTypeBooleanArray) { + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", = __func__, Schema, Version, ConfigureLang)); + return EFI_DEVICE_ERROR; + } =20 + // + // If there is no change in array, do nothing + // + if (!CompareRedfishBooleanArrayValues (ArrayHead, RedfishValue.Value.Boo= leanArray, RedfishValue.ArrayCount)) { // - // If there is no change in array, do nothing + // Apply settings from redfish // - if (!CompareRedfishBooleanArrayValues (ArrayHead, RedfishValue.Value.B= ooleanArray, RedfishValue.ArrayCount)) { - // - // Apply settings from redfish - // - DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __fun= c__, Schema, Version, ConfigureLang)); - FreeArrayTypeRedfishValue (&RedfishValue); + DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func_= _, Schema, Version, ConfigureLang)); + FreeArrayTypeRedfishValue (&RedfishValue); =20 - // - // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE - // - RedfishValue.ArrayCount =3D 0; - Buffer =3D ArrayHead; - while (Buffer !=3D NULL) { - RedfishValue.ArrayCount +=3D 1; - Buffer =3D Buffer->Next; - } + // + // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE + // + RedfishValue.ArrayCount =3D 0; + Buffer =3D ArrayHead; + while (Buffer !=3D NULL) { + RedfishValue.ArrayCount +=3D 1; + Buffer =3D Buffer->Next; + } =20 - // - // Allocate pool for new values - // - RedfishValue.Value.BooleanArray =3D AllocatePool (RedfishValue.Array= Count * sizeof (BOOLEAN)); - if (RedfishValue.Value.BooleanArray =3D=3D NULL) { - ASSERT (FALSE); - return EFI_OUT_OF_RESOURCES; - } + // + // Allocate pool for new values + // + RedfishValue.Value.BooleanArray =3D AllocatePool (RedfishValue.ArrayCo= unt * sizeof (BOOLEAN)); + if (RedfishValue.Value.BooleanArray =3D=3D NULL) { + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; + } =20 - Buffer =3D ArrayHead; - Index =3D 0; - while (Buffer !=3D NULL) { - RedfishValue.Value.BooleanArray[Index] =3D (BOOLEAN)*Buffer->Array= Value; - Buffer =3D Buffer->Next; - Index++; - } + Buffer =3D ArrayHead; + Index =3D 0; + while (Buffer !=3D NULL) { + RedfishValue.Value.BooleanArray[Index] =3D (BOOLEAN)*Buffer->ArrayVa= lue; + Buffer =3D Buffer->Next; + Index++; + } =20 - ASSERT (Index <=3D RedfishValue.ArrayCount); + ASSERT (Index <=3D RedfishValue.ArrayCount); =20 - Status =3D RedfishPlatformConfigSetValue (Schema, Version, Configure= Lang, RedfishValue); - if (!EFI_ERROR (Status)) { - // - // Configuration changed. Enable system reboot flag. - // - REDFISH_ENABLE_SYSTEM_REBOOT (); - } else { - DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, = ConfigureLang, Status)); - } + Status =3D RedfishPlatformConfigSetValue (Schema, Version, ConfigureLa= ng, RedfishValue); + if (!EFI_ERROR (Status)) { + // + // Configuration changed. Enable system reboot flag. + // + REDFISH_ENABLE_SYSTEM_REBOOT (); } else { - DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __f= unc__, Schema, Version, ConfigureLang)); + DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, Co= nfigureLang, Status)); } + } else { + DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __fun= c__, Schema, Version, ConfigureLang)); } =20 return Status; --=20 2.32.0 (Apple Git-132) -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-