[Skiboot] [PATCH v2 11/12] secvar_util.c: add dealloc_secvar helper to match alloc_secvar
Stefan Berger
stefanb at linux.ibm.com
Thu Jan 23 07:29:40 AEDT 2020
On 1/19/20 9:36 PM, Eric Richter wrote:
> Since there is a constructor function for alloc_secvar, there should be a
> matching destructor function for any of its non-toplevel allocations.
>
> This patch introduces dealloc_secvar(), which frees a whole secvar_node
> reference including its children allocations. This also updates the
> clear_bank_list() helper function to use this destructor.
>
> Signed-off-by: Eric Richter <erichte at linux.ibm.com>
> ---
> libstb/secvar/secvar.h | 1 +
> libstb/secvar/secvar_util.c | 10 ++++++++++
> 2 files changed, 11 insertions(+)
>
> diff --git a/libstb/secvar/secvar.h b/libstb/secvar/secvar.h
> index 771ff648..1bc00476 100644
> --- a/libstb/secvar/secvar.h
> +++ b/libstb/secvar/secvar.h
> @@ -45,6 +45,7 @@ extern struct secvar_backend_driver secvar_backend;
> void clear_bank_list(struct list_head *bank);
> struct secvar_node *alloc_secvar(uint64_t size);
> int realloc_secvar(struct secvar_node *node, uint64_t size);
> +void dealloc_secvar(struct secvar_node *node);
> struct secvar_node *find_secvar(const char *key, uint64_t key_len, struct list_head *bank);
> int is_key_empty(const char *key, uint64_t key_len);
> int list_length(struct list_head *bank);
> diff --git a/libstb/secvar/secvar_util.c b/libstb/secvar/secvar_util.c
> index a143d0bc..eb0def29 100644
> --- a/libstb/secvar/secvar_util.c
> +++ b/libstb/secvar/secvar_util.c
> @@ -64,6 +64,16 @@ int realloc_secvar(struct secvar_node *node, uint64_t size)
> return 0;
> }
>
> +void dealloc_secvar(struct secvar_node *node)
> +{
> + if (!node)
> + return;
> +
> + if (node->var)
> + free(node->var);
No need to check node->var, just call free() on it; it knows how to
handle NULL as well.
> + free(node);
> +}
> +
> struct secvar_node *find_secvar(const char *key, uint64_t key_len, struct list_head *bank)
> {
> struct secvar_node *node = NULL;
More information about the Skiboot
mailing list