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 28A39740039 for ; Fri, 29 Sep 2023 21:59:28 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=DyZ6DQ7EAGLtA9+1frAKqvFe9jZbLu6GUvA6GmC+H9Y=; 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=1696024766; v=1; b=CFgkfmoot7PQRZN+d+PbTkIrL++VnH0X7O+w0k7CWfHu18IPNnWiPxq5VV7eTdWzFkJTZda8 v9wk/qdJSUyWwsZSSEsb16oOjIn1TjA8hhfwtyPlSyZopHdUB/XTV6tPaOmZMwORM00koh92URN VDeG5DTYmEjUJAbxCSqLGpDI= X-Received: by 127.0.0.2 with SMTP id FbLJYY7687511xnjdhAMy3tn; Fri, 29 Sep 2023 14:59:26 -0700 X-Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by mx.groups.io with SMTP id smtpd.web11.30210.1696024765873045513 for ; Fri, 29 Sep 2023 14:59:26 -0700 X-Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2c1807f3400so14349151fa.1 for ; Fri, 29 Sep 2023 14:59:25 -0700 (PDT) X-Gm-Message-State: eAAQjf9MpZkgKSDvy8F7eilsx7686176AA= X-Google-Smtp-Source: AGHT+IEvgH6Ng0duhuO6steV5spWY7Nn39oS8USZjF4EVKuBrT2wLvz8340CNuvtlkLPQH1LVA5h2g== X-Received: by 2002:a2e:a28d:0:b0:2bd:1f0d:8c07 with SMTP id k13-20020a2ea28d000000b002bd1f0d8c07mr3782186lja.19.1696024763597; Fri, 29 Sep 2023 14:59:23 -0700 (PDT) X-Received: from localhost.localdomain ([185.9.78.108]) by smtp.gmail.com with ESMTPSA id y24-20020a2ebb98000000b002bfe8537f37sm890178lje.33.2023.09.29.14.59.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 Sep 2023 14:59:23 -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] [PATCH 5/9] RedfishClientPkg: reduce identation level by adding early return Date: Sat, 30 Sep 2023 00:59:11 +0300 Message-Id: <20230929215915.46616-6-mike.maslenkin@gmail.com> In-Reply-To: <20230929215915.46616-1-mike.maslenkin@gmail.com> References: <20230929215915.46616-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=CFgkfmoo; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 (#109221): https://edk2.groups.io/g/devel/message/109221 Mute This Topic: https://groups.io/mt/101667464/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-