diff options
author | Wei Yang <weiyang@linux.vnet.ibm.com> | 2014-12-02 14:24:15 +0800 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2014-12-02 17:41:48 +1100 |
commit | 0f8acff8d61accde3b3cd69327a10a94bac92088 (patch) | |
tree | 0b9c0e0ce5e925d50f5597d55fa6bccbff2a4b0e | |
parent | db089242bda7a5e3805b1e02da06f81e6075ba8a (diff) | |
download | skiboot-0f8acff8d61accde3b3cd69327a10a94bac92088.zip skiboot-0f8acff8d61accde3b3cd69327a10a94bac92088.tar.gz skiboot-0f8acff8d61accde3b3cd69327a10a94bac92088.tar.bz2 |
core/device: wrap a function to destroy a dt_node
When destroying a dt_node, it needs to release both the name and itself. And
there are several places to do the release.
This patch wrap a function dt_destroy() to make sure both of the elements of a
dt_node are released when it is not used any more.
Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | core/device.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/core/device.c b/core/device.c index ffc38f8..51ddbdb 100644 --- a/core/device.c +++ b/core/device.c @@ -84,6 +84,15 @@ bool dt_attach_root(struct dt_node *parent, struct dt_node *root) return true; } + +static inline void dt_destroy(struct dt_node *dn) +{ + if (!dn) + return; + + free_name(dn->name); + free(dn); +} struct dt_node *dt_new(struct dt_node *parent, const char *name) { @@ -92,8 +101,7 @@ struct dt_node *dt_new(struct dt_node *parent, const char *name) new = new_node(name); if (!dt_attach_root(parent, new)) { - free_name(new->name); - free(new); + dt_destroy(new); return NULL; } return new; @@ -115,8 +123,7 @@ struct dt_node *dt_new_addr(struct dt_node *parent, const char *name, new = new_node(lname); free(lname); if (!dt_attach_root(parent, new)) { - free_name(new->name); - free(new); + dt_destroy(new); return NULL; } return new; @@ -139,8 +146,7 @@ struct dt_node *dt_new_2addr(struct dt_node *parent, const char *name, new = new_node(lname); free(lname); if (!dt_attach_root(parent, new)) { - free_name(new->name); - free(new); + dt_destroy(new); return NULL; } return new; @@ -634,8 +640,7 @@ void dt_free(struct dt_node *node) if (node->parent) list_del_from(&node->parent->children, &node->list); - free_name(node->name); - free(node); + dt_destroy(node); } int dt_expand_node(struct dt_node *node, const void *fdt, int fdt_node) |