From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: barebox@lists.infradead.org
Subject: [PATCH v2 2/2] OF: base: use of_delete_property where applicable
Date: Mon, 24 Jun 2013 12:49:21 +0200 [thread overview]
Message-ID: <1372070961-10132-2-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
This patch makes OF API use of_delete_property where applicable instead
of freeing allocated data in different places.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Changelog:
v1->v2:
- remove offending whitespace lines
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 81 ++++++++++++++++------------------------------------
1 files changed, 25 insertions(+), 56 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e65cf85..63ff647 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -899,16 +899,11 @@ int of_property_write_u8_array(struct device_node *np,
struct property *prop = of_find_property(np, propname, NULL);
u8 *val;
- if (!prop)
- prop = of_new_property(np, propname, NULL, 0);
- if (!prop)
- return -ENOMEM;
-
- free(prop->value);
+ if (prop)
+ of_delete_property(prop);
- prop->length = sizeof(*val) * sz;
- prop->value = malloc(prop->length);
- if (!prop->value)
+ prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+ if (!prop)
return -ENOMEM;
val = prop->value;
@@ -940,16 +935,11 @@ int of_property_write_u16_array(struct device_node *np,
struct property *prop = of_find_property(np, propname, NULL);
__be16 *val;
- if (!prop)
- prop = of_new_property(np, propname, NULL, 0);
- if (!prop)
- return -ENOMEM;
-
- free(prop->value);
+ if (prop)
+ of_delete_property(prop);
- prop->length = sizeof(*val) * sz;
- prop->value = malloc(prop->length);
- if (!prop->value)
+ prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+ if (!prop)
return -ENOMEM;
val = prop->value;
@@ -981,16 +971,11 @@ int of_property_write_u32_array(struct device_node *np,
struct property *prop = of_find_property(np, propname, NULL);
__be32 *val;
- if (!prop)
- prop = of_new_property(np, propname, NULL, 0);
- if (!prop)
- return -ENOMEM;
+ if (prop)
+ of_delete_property(prop);
- free(prop->value);
-
- prop->length = sizeof(*val) * sz;
- prop->value = malloc(prop->length);
- if (!prop->value)
+ prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+ if (!prop)
return -ENOMEM;
val = prop->value;
@@ -1022,16 +1007,11 @@ int of_property_write_u64_array(struct device_node *np,
struct property *prop = of_find_property(np, propname, NULL);
__be32 *val;
- if (!prop)
- prop = of_new_property(np, propname, NULL, 0);
- if (!prop)
- return -ENOMEM;
+ if (prop)
+ of_delete_property(prop);
- free(prop->value);
-
- prop->length = 2 * sizeof(*val) * sz;
- prop->value = malloc(prop->length);
- if (!prop->value)
+ prop = of_new_property(np, propname, NULL, 2 * sizeof(*val) * sz);
+ if (!prop)
return -ENOMEM;
val = prop->value;
@@ -1567,26 +1547,19 @@ void of_delete_property(struct property *pp)
int of_set_property(struct device_node *np, const char *name, const void *val, int len,
int create)
{
- struct property *pp;
+ struct property *pp = of_find_property(np, name, NULL);
if (!np)
return -ENOENT;
- pp = of_find_property(np, name, NULL);
- if (pp) {
- void *data;
+ if (!pp && !create)
+ return -ENOENT;
- free(pp->value);
- data = xzalloc(len);
- memcpy(data, val, len);
- pp->value = data;
- pp->length = len;
- } else {
- if (!create)
- return -ENOENT;
+ of_delete_property(pp);
- pp = of_new_property(np, name, val, len);
- }
+ pp = of_new_property(np, name, val, len);
+ if (!pp)
+ return -ENOMEM;
return 0;
}
@@ -1810,12 +1783,8 @@ void of_free(struct device_node *node)
if (!node)
return;
- list_for_each_entry_safe(p, pt, &node->properties, list) {
- list_del(&p->list);
- free(p->name);
- free(p->value);
- free(p);
- }
+ list_for_each_entry_safe(p, pt, &node->properties, list)
+ of_delete_property(p);
list_for_each_entry_safe(n, nt, &node->children, parent_list) {
of_free(n);
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2013-06-24 10:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-21 15:15 [PATCH 0/3] OF: base: cleanup and allow empty properties Sebastian Hesselbarth
2013-06-21 15:15 ` [PATCH 1/3] OF: base: add sanity checks to of_new/delete_property Sebastian Hesselbarth
2013-06-23 18:24 ` Sascha Hauer
2013-06-21 15:15 ` [PATCH 2/3] OF: base: use of_delete_property where applicable Sebastian Hesselbarth
2013-06-21 15:15 ` [PATCH 3/3] OF: base: add empty property value pointer Sebastian Hesselbarth
2013-06-23 18:33 ` Sascha Hauer
2013-06-23 20:11 ` Sebastian Hesselbarth
2013-06-23 20:26 ` Sascha Hauer
2013-06-23 20:29 ` Sebastian Hesselbarth
2013-06-24 10:49 ` [PATCH v2 1/2] OF: base: add sanity checks to of_new/delete_property Sebastian Hesselbarth
2013-06-24 19:40 ` Sascha Hauer
2013-06-24 10:49 ` Sebastian Hesselbarth [this message]
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-all 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=1372070961-10132-2-git-send-email-sebastian.hesselbarth@gmail.com \
--to=sebastian.hesselbarth@gmail.com \
--cc=barebox@lists.infradead.org \
/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