From: Masahiro Yamada <yamada.m@jp.panasonic.com>
To: barebox@lists.infradead.org
Subject: [PATCH v3] param: add error check to __dev_add_param()
Date: Thu, 29 Jan 2015 19:43:06 +0900 [thread overview]
Message-ID: <1422528186-3666-1-git-send-email-yamada.m@jp.panasonic.com> (raw)
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(¶m->list, &dev->parameters);
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2015-01-29 10:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-29 10:43 Masahiro Yamada [this message]
2015-01-30 7:42 ` Sascha Hauer
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=1422528186-3666-1-git-send-email-yamada.m@jp.panasonic.com \
--to=yamada.m@jp.panasonic.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