From: "Nickle Wang via groups.io" <nicklew=nvidia.com@groups.io>
To: "abner.chang@amd.com" <abner.chang@amd.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Igor Kulchytskyy <igork@ami.com>
Subject: Re: [edk2-devel] [edk2-redfish-client][PATCH 2/3] RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions
Date: Tue, 16 Jan 2024 03:14:43 +0000 [thread overview]
Message-ID: <MW4PR12MB7031D7D4CFE7223A6637E135D9732@MW4PR12MB7031.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20240112032622.274-2-abner.chang@amd.com>
Please see my comments below.
Regards,
Nickle
> -----Original Message-----
> From: abner.chang@amd.com <abner.chang@amd.com>
> Sent: Friday, January 12, 2024 11:26 AM
> To: devel@edk2.groups.io
> Cc: Nickle Wang <nicklew@nvidia.com>; Igor Kulchytskyy <igork@ami.com>
> Subject: [edk2-redfish-client][PATCH 2/3]
> RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions
>
> External email: Use caution opening links or attachments
>
>
> From: Abner Chang <abner.chang@amd.com>
>
> - Add RedfishRemoveUnchangeableProperties () to remove
> unchangeable Redfish properties such as @OData.id.
> - Add DestoryRedfishCharArray () to free Redfish string
> array.
>
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
> .../RedfishFeatureUtilityLib.inf | 1 +
> .../Library/RedfishFeatureUtilityLib.h | 35 ++++++++
> .../RedfishFeatureUtilityLib.c | 79 +++++++++++++++++++
> 3 files changed, 115 insertions(+)
>
> diff --git
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf
> index 63330c8e9d..d8f3da3732 100644
> ---
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.inf
> +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUt
> +++ ilityLib.inf
> @@ -37,6 +37,7 @@
> [LibraryClasses]
> BaseLib
> BaseMemoryLib
> + ConverterCommonLib
> DebugLib
> MemoryAllocationLib
> RedfishLib
> diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> index 0f8aede5c4..1b6d3f4cf8 100644
> --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> @@ -821,6 +821,23 @@ AddRedfishCharArray (
> IN UINTN ArraySize
> );
>
> +/**
> +
> + Destroy Redfish string array
> +
> + @param[in] Head The head of string array.
> + @param[in] ArraySize The size of StringArray.
> +
> + @retval EFI_SUCCESS String array is destroyed successfully.
> + @retval Others Error happens
> +
> +**/
> +EFI_STATUS
> +DestoryRedfishCharArray (
> + IN RedfishCS_char_Array *Head,
> + IN UINTN ArraySize
> + );
> +
> /**
>
> Create numeric array and append to array node in Redfish JSON convert format.
> @@ -1024,4 +1041,22 @@ ValidateRedfishStringArrayValues (
> OUT BOOLEAN *ValueChanged
> );
>
> +/**
> + This function removes the unchangeable Redfish properties from input
> JsonString.
> + New JSON string is returned in JsonString and the memory of original
> +pointer to input
> + JsonString was freed. Caller is responsible to free the memory
> +pointed by output
> + JsonString.
> +
> + @param[in,out] JsonString On input, this is the pointer to original JSON string.
> + On output, this is the new pointer to the updated JSON string.
> +
> + @retval EFI_SUCCESS The unchangeable Redfish properties were removed
> from original JSON string.
> + @retval Others There are problems to remove unchangeable Redfish
> properties.
> +
> +**/
> +EFI_STATUS
> +RedfishRemoveUnchangeableProperties (
> + IN OUT CHAR8 **JsonString
> + );
1) I am thinking that can we use "ReadOnly" instead of "Unchangeable"?
2) Can we have two parameters for input and output string? Caller can decide when to release input string and this function does not do this for caller.
For example:
RedfishRemoveReadOnlyProperties (
IN CHAR8 *JsonString,
OUT CHAR8 **ModifedString
);
> +
> #endif
> diff --git
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
> index aa723264e8..b16a811bb1 100644
> ---
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
> +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUt
> +++ ilityLib.c
> @@ -3412,6 +3412,40 @@ AddRedfishCharArray (
> return EFI_SUCCESS;
> }
>
> +/**
> +
> + Destroy Redfish string array
> +
> + @param[in] Head The head of string array.
> + @param[in] ArraySize The size of StringArray.
> +
> + @retval EFI_SUCCESS String array is destroyed successfully.
> + @retval Others Error happens
> +
> +**/
> +EFI_STATUS
> +DestoryRedfishCharArray (
> + IN RedfishCS_char_Array *Head,
> + IN UINTN ArraySize
> + )
> +{
> + UINTN Index;
> + RedfishCS_char_Array *NextPointer;
> +
> + if ((Head == NULL) || (ArraySize == 0)) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + for (Index = 0; Index < ArraySize; Index++) {
> + NextPointer = Head->Next;
> + if (Head != NULL) {
> + FreePool (Head);
I suggest setting Head to NULL after FreePool call. So, no one can use this memory by accident.
> + }
> + Head = NextPointer;
> + }
> + return EFI_SUCCESS;
> +}
> +
> /**
>
> Create numeric array and append to array node in Redfish JSON convert format.
> @@ -3935,6 +3969,51 @@ ValidateRedfishStringArrayValues (
> return EFI_SUCCESS;
> }
>
> +/**
> + This function removes the unchangeable Redfish properties from input
> JsonString.
> + New JSON string is returned in JsonString and the memory of original
> +pointer to input
> + JsonString was freed. Caller is responsible to free the memory
> +pointed by output
> + JsonString.
> +
> + @param[in,out] JsonString On input, this is the pointer to original JSON string.
> + On output, this is the new pointer to the updated JSON string.
> +
> + @retval EFI_SUCCESS The unchangeable Redfish properties were removed
> from original JSON string.
> + @retval Others There are problems to remove unchangeable Redfish
> properties.
> +
> +**/
> +EFI_STATUS
> +RedfishRemoveUnchangeableProperties (
> + IN OUT CHAR8 **JsonString
> + )
> +{
> + RedfishCS_status Status;
> + CHAR8 *UpdatedJsonString;
> +
> + if ((JsonString == NULL) || (*JsonString == NULL)) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + UpdatedJsonString = AllocateZeroPool (AsciiStrSize (*JsonString));
> + if (UpdatedJsonString == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: Insufficient memory for
> UpdatedJsonString.\n", __func__));
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + Status = RemoveUnchangeableProperties (
> + (RedfishCS_char *)*JsonString,
> + (RedfishCS_char *)UpdatedJsonString,
> + (RedfishCS_uint32)AsciiStrSize (*JsonString)
> + );
> + if (Status != RedfishCS_status_success) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> + FreePool (*JsonString);
> + *JsonString = UpdatedJsonString;
> + return EFI_SUCCESS;
> +}
> +
> /**
>
> Install Boot Maintenance Manager Menu driver.
> --
> 2.37.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113862): https://edk2.groups.io/g/devel/message/113862
Mute This Topic: https://groups.io/mt/103676919/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:[~2024-01-16 5:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 3:26 [edk2-devel] [edk2-redfish-client][PATCH 1/3] RedfishClientPkg/jansson: Define json_object_del Chang, Abner via groups.io
2024-01-12 3:26 ` [edk2-devel] [edk2-redfish-client][PATCH 2/3] RedfishClientPkg/RedfishFeatureUtilityLib: Add two helper functions Chang, Abner via groups.io
2024-01-16 3:14 ` Nickle Wang via groups.io [this message]
2024-01-12 3:26 ` [edk2-devel] [edk2-redfish-client][PATCH 3/3] RedfishClientPkg/ConverterLib: Function to remove Redfish unchangeable properties Chang, Abner via groups.io
2024-01-16 3:17 ` Nickle Wang via groups.io
2024-01-16 4:08 ` Chang, Abner via groups.io
2024-01-16 6:20 ` Nickle Wang via groups.io
2024-01-16 8:31 ` Chang, Abner via groups.io
2024-01-16 3:07 ` [edk2-devel] [edk2-redfish-client][PATCH 1/3] RedfishClientPkg/jansson: Define json_object_del 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=MW4PR12MB7031D7D4CFE7223A6637E135D9732@MW4PR12MB7031.namprd12.prod.outlook.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