From: "Mike Maslenkin" <mike.maslenkin@gmail.com>
To: devel@edk2.groups.io
Cc: abner.chang@amd.com, nicklew@nvidia.com, igork@ami.com,
Mike Maslenkin <mike.maslenkin@gmail.com>
Subject: [edk2-devel] [PATCH 5/9] RedfishClientPkg: reduce identation level by adding early return
Date: Sat, 30 Sep 2023 00:59:11 +0300 [thread overview]
Message-ID: <20230929215915.46616-6-mike.maslenkin@gmail.com> (raw)
In-Reply-To: <20230929215915.46616-1-mike.maslenkin@gmail.com>
This functions contain memory leaks.
Less identation helps to solve this issues.
Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
---
.../RedfishFeatureUtilityLib.c | 289 +++++++++---------
1 file changed, 146 insertions(+), 143 deletions(-)
diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index 8fa1dc2c3535..0941f33fd73a 100644
--- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -763,68 +763,69 @@ ApplyFeatureSettingsStringArrayType (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Version, ConfigureLang, Status));
- } else {
- if (RedfishValue.Type != 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 != RedfishValueTypeStringArray) {
+ DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", __func__, Schema, Version, ConfigureLang));
+ return EFI_DEVICE_ERROR;
+ }
+ //
+ // If there is no change in array, do nothing
+ //
+ if (!CompareRedfishStringArrayValues (ArrayHead, RedfishValue.Value.StringArray, RedfishValue.ArrayCount)) {
//
- // If there is no change in array, do nothing
+ // Apply settings from redfish
//
- if (!CompareRedfishStringArrayValues (ArrayHead, RedfishValue.Value.StringArray, RedfishValue.ArrayCount)) {
- //
- // Apply settings from redfish
- //
- DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func__, Schema, Version, ConfigureLang));
- FreeArrayTypeRedfishValue (&RedfishValue);
+ DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func__, Schema, Version, ConfigureLang));
+ FreeArrayTypeRedfishValue (&RedfishValue);
- //
- // Convert array from RedfishCS_char_Array to EDKII_REDFISH_VALUE
- //
- RedfishValue.ArrayCount = 0;
- Buffer = ArrayHead;
- while (Buffer != NULL) {
- RedfishValue.ArrayCount += 1;
- Buffer = Buffer->Next;
- }
+ //
+ // Convert array from RedfishCS_char_Array to EDKII_REDFISH_VALUE
+ //
+ RedfishValue.ArrayCount = 0;
+ Buffer = ArrayHead;
+ while (Buffer != NULL) {
+ RedfishValue.ArrayCount += 1;
+ Buffer = Buffer->Next;
+ }
- //
- // Allocate pool for new values
- //
- RedfishValue.Value.StringArray = AllocatePool (RedfishValue.ArrayCount *sizeof (CHAR8 *));
- if (RedfishValue.Value.StringArray == NULL) {
+ //
+ // Allocate pool for new values
+ //
+ RedfishValue.Value.StringArray = AllocatePool (RedfishValue.ArrayCount *sizeof (CHAR8 *));
+ if (RedfishValue.Value.StringArray == NULL) {
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Buffer = ArrayHead;
+ Index = 0;
+ while (Buffer != NULL) {
+ RedfishValue.Value.StringArray[Index] = AllocateCopyPool (AsciiStrSize (Buffer->ArrayValue), Buffer->ArrayValue);
+ if (RedfishValue.Value.StringArray[Index] == NULL) {
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
- Buffer = ArrayHead;
- Index = 0;
- while (Buffer != NULL) {
- RedfishValue.Value.StringArray[Index] = AllocateCopyPool (AsciiStrSize (Buffer->ArrayValue), Buffer->ArrayValue);
- if (RedfishValue.Value.StringArray[Index] == NULL) {
- ASSERT (FALSE);
- return EFI_OUT_OF_RESOURCES;
- }
-
- Buffer = Buffer->Next;
- Index++;
- }
+ Buffer = Buffer->Next;
+ Index++;
+ }
- ASSERT (Index <= RedfishValue.ArrayCount);
+ ASSERT (Index <= RedfishValue.ArrayCount);
- Status = RedfishPlatformConfigSetValue (Schema, Version, ConfigureLang, 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 = RedfishPlatformConfigSetValue (Schema, Version, ConfigureLang, 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", __func__, Schema, Version, ConfigureLang));
+ DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, ConfigureLang, Status));
}
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __func__, Schema, Version, ConfigureLang));
}
return Status;
@@ -866,63 +867,64 @@ ApplyFeatureSettingsNumericArrayType (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Version, ConfigureLang, Status));
- } else {
- if (RedfishValue.Type != 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 != RedfishValueTypeIntegerArray) {
+ DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", __func__, Schema, Version, ConfigureLang));
+ return EFI_DEVICE_ERROR;
+ }
+ //
+ // If there is no change in array, do nothing
+ //
+ if (!CompareRedfishNumericArrayValues (ArrayHead, RedfishValue.Value.IntegerArray, RedfishValue.ArrayCount)) {
//
- // If there is no change in array, do nothing
+ // Apply settings from redfish
//
- if (!CompareRedfishNumericArrayValues (ArrayHead, RedfishValue.Value.IntegerArray, RedfishValue.ArrayCount)) {
- //
- // Apply settings from redfish
- //
- DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func__, Schema, Version, ConfigureLang));
- FreeArrayTypeRedfishValue (&RedfishValue);
+ DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func__, Schema, Version, ConfigureLang));
+ FreeArrayTypeRedfishValue (&RedfishValue);
- //
- // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE
- //
- RedfishValue.ArrayCount = 0;
- Buffer = ArrayHead;
- while (Buffer != NULL) {
- RedfishValue.ArrayCount += 1;
- Buffer = Buffer->Next;
- }
+ //
+ // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE
+ //
+ RedfishValue.ArrayCount = 0;
+ Buffer = ArrayHead;
+ while (Buffer != NULL) {
+ RedfishValue.ArrayCount += 1;
+ Buffer = Buffer->Next;
+ }
- //
- // Allocate pool for new values
- //
- RedfishValue.Value.IntegerArray = AllocatePool (RedfishValue.ArrayCount * sizeof (INT64));
- if (RedfishValue.Value.IntegerArray == NULL) {
- ASSERT (FALSE);
- return EFI_OUT_OF_RESOURCES;
- }
+ //
+ // Allocate pool for new values
+ //
+ RedfishValue.Value.IntegerArray = AllocatePool (RedfishValue.ArrayCount * sizeof (INT64));
+ if (RedfishValue.Value.IntegerArray == NULL) {
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
- Buffer = ArrayHead;
- Index = 0;
- while (Buffer != NULL) {
- RedfishValue.Value.IntegerArray[Index] = (INT64)*Buffer->ArrayValue;
- Buffer = Buffer->Next;
- Index++;
- }
+ Buffer = ArrayHead;
+ Index = 0;
+ while (Buffer != NULL) {
+ RedfishValue.Value.IntegerArray[Index] = (INT64)*Buffer->ArrayValue;
+ Buffer = Buffer->Next;
+ Index++;
+ }
- ASSERT (Index <= RedfishValue.ArrayCount);
+ ASSERT (Index <= RedfishValue.ArrayCount);
- Status = RedfishPlatformConfigSetValue (Schema, Version, ConfigureLang, 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 = RedfishPlatformConfigSetValue (Schema, Version, ConfigureLang, 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", __func__, Schema, Version, ConfigureLang));
+ DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, ConfigureLang, Status));
}
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __func__, Schema, Version, ConfigureLang));
}
return Status;
@@ -964,63 +966,64 @@ ApplyFeatureSettingsBooleanArrayType (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLang, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s failed: %r\n", __func__, Schema, Version, ConfigureLang, Status));
- } else {
- if (RedfishValue.Type != 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 != RedfishValueTypeBooleanArray) {
+ DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", __func__, Schema, Version, ConfigureLang));
+ return EFI_DEVICE_ERROR;
+ }
+ //
+ // If there is no change in array, do nothing
+ //
+ if (!CompareRedfishBooleanArrayValues (ArrayHead, RedfishValue.Value.BooleanArray, RedfishValue.ArrayCount)) {
//
- // If there is no change in array, do nothing
+ // Apply settings from redfish
//
- if (!CompareRedfishBooleanArrayValues (ArrayHead, RedfishValue.Value.BooleanArray, RedfishValue.ArrayCount)) {
- //
- // Apply settings from redfish
- //
- DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func__, Schema, Version, ConfigureLang));
- FreeArrayTypeRedfishValue (&RedfishValue);
+ DEBUG ((DEBUG_MANAGEABILITY, "%a, %a.%a apply %s for array\n", __func__, Schema, Version, ConfigureLang));
+ FreeArrayTypeRedfishValue (&RedfishValue);
- //
- // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE
- //
- RedfishValue.ArrayCount = 0;
- Buffer = ArrayHead;
- while (Buffer != NULL) {
- RedfishValue.ArrayCount += 1;
- Buffer = Buffer->Next;
- }
+ //
+ // Convert array from RedfishCS_int64_Array to EDKII_REDFISH_VALUE
+ //
+ RedfishValue.ArrayCount = 0;
+ Buffer = ArrayHead;
+ while (Buffer != NULL) {
+ RedfishValue.ArrayCount += 1;
+ Buffer = Buffer->Next;
+ }
- //
- // Allocate pool for new values
- //
- RedfishValue.Value.BooleanArray = AllocatePool (RedfishValue.ArrayCount * sizeof (BOOLEAN));
- if (RedfishValue.Value.BooleanArray == NULL) {
- ASSERT (FALSE);
- return EFI_OUT_OF_RESOURCES;
- }
+ //
+ // Allocate pool for new values
+ //
+ RedfishValue.Value.BooleanArray = AllocatePool (RedfishValue.ArrayCount * sizeof (BOOLEAN));
+ if (RedfishValue.Value.BooleanArray == NULL) {
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
- Buffer = ArrayHead;
- Index = 0;
- while (Buffer != NULL) {
- RedfishValue.Value.BooleanArray[Index] = (BOOLEAN)*Buffer->ArrayValue;
- Buffer = Buffer->Next;
- Index++;
- }
+ Buffer = ArrayHead;
+ Index = 0;
+ while (Buffer != NULL) {
+ RedfishValue.Value.BooleanArray[Index] = (BOOLEAN)*Buffer->ArrayValue;
+ Buffer = Buffer->Next;
+ Index++;
+ }
- ASSERT (Index <= RedfishValue.ArrayCount);
+ ASSERT (Index <= RedfishValue.ArrayCount);
- Status = RedfishPlatformConfigSetValue (Schema, Version, ConfigureLang, 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 = RedfishPlatformConfigSetValue (Schema, Version, ConfigureLang, 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", __func__, Schema, Version, ConfigureLang));
+ DEBUG ((DEBUG_ERROR, "%a, apply %s array failed: %r\n", __func__, ConfigureLang, Status));
}
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a, %a.%a %s array value has no change\n", __func__, Schema, Version, ConfigureLang));
}
return Status;
--
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]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-09-29 21:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 21:59 [edk2-devel] [PATCH 0/9] RedfishClientPkg: various minor fixes Mike Maslenkin
2023-09-29 21:59 ` [edk2-devel] [PATCH 1/9] RedfishClientPkg: fix format used for output __func__ Mike Maslenkin
2023-10-02 2:16 ` Chang, Abner via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 2/9] RedfishClientPkg: fix DEBUG macro arguments Mike Maslenkin
2023-10-02 2:16 ` Chang, Abner via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 3/9] RedfishLib: remove redudant zeroing Mike Maslenkin
2023-10-02 2:18 ` Chang, Abner via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 4/9] RedfishClientPkg: RedfishFeatureUtilityLib: fix memory leaks Mike Maslenkin
2023-10-02 2:25 ` Chang, Abner via groups.io
2023-09-29 21:59 ` Mike Maslenkin [this message]
2023-10-02 3:00 ` [edk2-devel] [PATCH 5/9] RedfishClientPkg: reduce identation level by adding early return Chang, Abner via groups.io
2023-10-02 3:09 ` Chang, Abner via groups.io
2023-10-11 1:53 ` Nickle Wang via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 6/9] RedfishClientPkg: fix memory leaks while applying feature settings Mike Maslenkin
2023-10-02 2:30 ` Chang, Abner via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 7/9] RedfishClientPkg: fix memory leak Mike Maslenkin
2023-10-02 2:36 ` Chang, Abner via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 8/9] RedfishClientPkg: fix pragma pack usage Mike Maslenkin
2023-10-02 2:45 ` Chang, Abner via groups.io
2023-10-02 12:14 ` Mike Maslenkin
2023-10-11 1:49 ` Nickle Wang via groups.io
2023-10-03 2:02 ` Chang, Abner via groups.io
2023-09-29 21:59 ` [edk2-devel] [PATCH 9/9] RedfishClientPkg: fix StrnCpyS arguments Mike Maslenkin
2023-10-02 2:56 ` Chang, Abner via groups.io
2023-10-26 23:51 ` Mike Maslenkin
2023-10-27 2:33 ` Chang, Abner via groups.io
2023-10-26 8:33 ` [edk2-devel] [PATCH 0/9] RedfishClientPkg: various minor fixes Nickle Wang via groups.io
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230929215915.46616-6-mike.maslenkin@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox