From nobody Mon Feb 9 16:01:33 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+109221+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+109221+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1696024767; cv=none; d=zohomail.com; s=zohoarc; b=N1XsNBixKSJsNJZ2RW7Qcda+uJQR7lKMjRNx7x9hpdognUqXJAIZP5Vq36Dr9Lg7L2gh4/XxG8IBivjSGrfhBN9hE3PNsgANipuSHXVQWsuC3bANb9suICWDNpjlKZNaCCHGkgrDDPxvGSl2/qcLH2bvS05nra+JRPNRa2UUDoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696024767; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=9jsrJ0D95zRVCLVI/70/7zoHL9RBBH48VrGE9W4fYb8=; b=iHFMmbRUjs5nFjTpf0ARcnyDceC6XCcFzFosjZLcKJxY7876GqgmWlH/zEcq8im7GdptCTBiq4eVrdx/ArjN8MtEafgqTK+rWL9xi3O2EP+6Sk2DUNP8ux7WNkETveCCSffEmYNGZq1LTKytzOcbG+7sRWgOWQGefVaBn+ySzKk= 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+109221+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 1696024767096114.6645346432955; Fri, 29 Sep 2023 14:59:27 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Uud86Q/Yndv5/ofJW0rnLyDiwvJBg+5D9LVykcjW5Mo=; 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=u7vnuJ1DErZdx+uX6lO2jq94lVPCPwmlvNof4sP4V+/qkUS9XQuolBdkb0FTJI4Wcye21K5F 6CF/l0UCgfSgmx9dKNAYPaI1qqNndpOssnMhhE3ZuOu+cP2ctXOet4FP8XueN3KbvjBbypjezw6 QTD1YacfaB9xxwASfUtnAQvI= X-Received: by 127.0.0.2 with SMTP id pIIuYY1788612x93MNqHEIf1; 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: HGtAt4vqRrcWMMLWIZQFBmWbx1787277AA= 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-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1696024769317100025 Content-Type: text/plain; charset="utf-8" This functions contain memory leaks. Less identation helps to solve this issues. Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang --- .../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 (#109221): https://edk2.groups.io/g/devel/message/109221 Mute This Topic: https://groups.io/mt/101667464/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-