Skip to contentSkip to conversation

of: base: some simplifications

PATCH Applied Antony Pavlov 2 participants 6 messages Apr 17, 2017 – Apr 19, 2017 Device tree

lore
Share & tools
lore
#0 lore raw

cover of: base: some simplifications

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(-)
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/2 of: base: exclude memcpy-like code from of_property_write_u8_array()

The of_new_property() function already has functionality to copy data into of_property so we can make of_property_write_u8_array() simpler.

---
 drivers/of/base.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/of/base.c +1 -6
index 6632f4d9dd..1161ce9793 100644
@@ -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;
 }
 
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/2 of: base: of_new_property(): use xstrdup() instead of strdup()

In reply to Antony Pavlov

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.

---
 drivers/of/base.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/of/base.c +1 -6
index 1161ce9793..c9bdd91810 100644
@@ -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);
 
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#5 lore raw
In reply to Antony Pavlov
Quoted 6 lines · Antony Pavlov

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup()

In reply to Antony Pavlov
Quoted 7 lines · On Mon, 17 Apr 2017 13:42:10 +0300 Antony Pavlov <[email protected]>…

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?

Quoted 26 lines
---
 drivers/of/base.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/of/base.c +1 -6
index 1161ce9793..c9bdd91810 100644
@@ -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);
 
Signature · 1 line
2.11.0
Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup()

Quoted 11 lines · Antony Pavlov
Quoted 7 lines · On Mon, 17 Apr 2017 13:42:10 +0300 Antony Pavlov <[email protected]>…

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.

Quoted 5 lines

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox