* [PATCH 1/2] of: base: exclude memcpy-like code from of_property_write_u8_array()
2017-04-17 10:42 [PATCH 0/2] of: base: some simplifications Antony Pavlov
@ 2017-04-17 10:42 ` Antony Pavlov
2017-04-17 10:42 ` [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup() Antony Pavlov
2017-04-19 9:47 ` [PATCH 0/2] of: base: some simplifications Sascha Hauer
2 siblings, 0 replies; 6+ messages in thread
From: Antony Pavlov @ 2017-04-17 10:42 UTC (permalink / raw)
To: barebox
The of_new_property() function already has functionality
to copy data into of_property so we can make
of_property_write_u8_array() simpler.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
drivers/of/base.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6632f4d9dd..1161ce9793 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1090,19 +1090,14 @@ int of_property_write_u8_array(struct device_node *np,
size_t sz)
{
struct property *prop = of_find_property(np, propname, NULL);
- u8 *val;
if (prop)
of_delete_property(prop);
- prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+ prop = of_new_property(np, propname, values, sizeof(*values) * sz);
if (!prop)
return -ENOMEM;
- val = prop->value;
- while (sz--)
- *val++ = *values++;
-
return 0;
}
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup()
2017-04-17 10:42 [PATCH 0/2] of: base: some simplifications Antony Pavlov
2017-04-17 10:42 ` [PATCH 1/2] of: base: exclude memcpy-like code from of_property_write_u8_array() Antony Pavlov
@ 2017-04-17 10:42 ` Antony Pavlov
2017-04-19 10:20 ` Antony Pavlov
2017-04-19 9:47 ` [PATCH 0/2] of: base: some simplifications Sascha Hauer
2 siblings, 1 reply; 6+ messages in thread
From: Antony Pavlov @ 2017-04-17 10:42 UTC (permalink / raw)
To: barebox
At the moment of_new_property() uses xfunctions for memory
allocation so we can use xstrdup() instead of strdup()
for code simplification.
A side effect of this commmit is that
the of_new_property() function can't return NULL
anymore if CONFIG_OFTREE is set.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
drivers/of/base.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1161ce9793..c9bdd91810 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1802,12 +1802,7 @@ struct property *of_new_property(struct device_node *node, const char *name,
struct property *prop;
prop = xzalloc(sizeof(*prop));
- prop->name = strdup(name);
- if (!prop->name) {
- free(prop);
- return NULL;
- }
-
+ prop->name = xstrdup(name);
prop->length = len;
prop->value = xzalloc(len);
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup()
2017-04-17 10:42 ` [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup() Antony Pavlov
@ 2017-04-19 10:20 ` Antony Pavlov
2017-04-19 10:19 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Antony Pavlov @ 2017-04-19 10:20 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Mon, 17 Apr 2017 13:42:10 +0300
Antony Pavlov <antonynpavlov@gmail.com> wrote:
> At the moment of_new_property() uses xfunctions for memory
> allocation so we can use xstrdup() instead of strdup()
> for code simplification.
>
> A side effect of this commmit is that
> the of_new_property() function can't return NULL
> anymore if CONFIG_OFTREE is set.
If of_new_property() can't return NULL we can skip all numerous
checks after of_new_property() call. So the checks are actual only
if CONFIG_OFTREE isn't set.
Have you any sugestions on removing of_new_property() return value checks?
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
> drivers/of/base.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1161ce9793..c9bdd91810 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1802,12 +1802,7 @@ struct property *of_new_property(struct device_node *node, const char *name,
> struct property *prop;
>
> prop = xzalloc(sizeof(*prop));
> - prop->name = strdup(name);
> - if (!prop->name) {
> - free(prop);
> - return NULL;
> - }
> -
> + prop->name = xstrdup(name);
> prop->length = len;
> prop->value = xzalloc(len);
>
> --
> 2.11.0
>
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup()
2017-04-19 10:20 ` Antony Pavlov
@ 2017-04-19 10:19 ` Sascha Hauer
0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2017-04-19 10:19 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Wed, Apr 19, 2017 at 01:20:26PM +0300, Antony Pavlov wrote:
> On Mon, 17 Apr 2017 13:42:10 +0300
> Antony Pavlov <antonynpavlov@gmail.com> wrote:
>
> > At the moment of_new_property() uses xfunctions for memory
> > allocation so we can use xstrdup() instead of strdup()
> > for code simplification.
> >
> > A side effect of this commmit is that
> > the of_new_property() function can't return NULL
> > anymore if CONFIG_OFTREE is set.
>
> If of_new_property() can't return NULL we can skip all numerous
> checks after of_new_property() call. So the checks are actual only
> if CONFIG_OFTREE isn't set.
>
> Have you any sugestions on removing of_new_property() return value checks?
I'm not sure removing these checks is a good idea. One possible error
return for of_new_property() could be -EEXIST. Right now we do not check
is the property already exists and just create a second property with
the same name. Also if you consider FIT images: These store a whole
kernel in a device tree property, so the xmalloc() we have for
allocating the data for the property might better be malloc() so that
it can fail.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] of: base: some simplifications
2017-04-17 10:42 [PATCH 0/2] of: base: some simplifications Antony Pavlov
2017-04-17 10:42 ` [PATCH 1/2] of: base: exclude memcpy-like code from of_property_write_u8_array() Antony Pavlov
2017-04-17 10:42 ` [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup() Antony Pavlov
@ 2017-04-19 9:47 ` Sascha Hauer
2 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2017-04-19 9:47 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Mon, Apr 17, 2017 at 01:42:08PM +0300, Antony Pavlov wrote:
> Antony Pavlov (2):
> of: base: exclude memcpy-like code from of_property_write_u8_array()
> of: base: of_new_property(): use xstrdup() instead of strdup()
>
> drivers/of/base.c | 14 ++------------
> 1 file changed, 2 insertions(+), 12 deletions(-)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread