mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3] param: add error check to __dev_add_param()
@ 2015-01-29 10:43 Masahiro Yamada
  2015-01-30  7:42 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2015-01-29 10:43 UTC (permalink / raw)
  To: barebox

If strdup() fails with out-of-memory, __dev_add_param() should fail
with -ENOMEM.

(Note strdup() is always given with a non-NULL pointer.  If the
argument name is given with NULL, the system would already have
crashed in the get_param_by_name() function.)

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

Changes in v3:
  - Drop -ENOMEM check

 lib/parameter.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/parameter.c b/lib/parameter.c
index 71262c4..865ad9f 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -130,6 +130,10 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
 	if (get_param_by_name(dev, name))
 		return -EEXIST;
 
+	param->name = strdup(name);
+	if (!param->name)
+		return -ENOMEM;
+
 	if (set)
 		param->set = set;
 	else
@@ -139,7 +143,6 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
 	else
 		param->get = param_get_generic;
 
-	param->name = strdup(name);
 	param->flags = flags;
 	param->dev = dev;
 	list_add_tail(&param->list, &dev->parameters);
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] param: add error check to __dev_add_param()
  2015-01-29 10:43 [PATCH v3] param: add error check to __dev_add_param() Masahiro Yamada
@ 2015-01-30  7:42 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-01-30  7:42 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: barebox

On Thu, Jan 29, 2015 at 07:43:06PM +0900, Masahiro Yamada wrote:
> If strdup() fails with out-of-memory, __dev_add_param() should fail
> with -ENOMEM.
> 
> (Note strdup() is always given with a non-NULL pointer.  If the
> argument name is given with NULL, the system would already have
> crashed in the get_param_by_name() function.)
> 
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

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] 2+ messages in thread

end of thread, other threads:[~2015-01-30  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-29 10:43 [PATCH v3] param: add error check to __dev_add_param() Masahiro Yamada
2015-01-30  7:42 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox