diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-09-10 14:57:46 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-09-10 14:57:56 +0200 |
commit | 755a69659c4283c5d572bcdacfa59cd4b55eddb6 (patch) | |
tree | 6926c6e4f82b12abd0a51f112b5fec968d5267b2 | |
parent | b1a52928e7bf4126bbe014ee434bd91c4f804bba (diff) | |
download | dt-utils-755a69659c4283c5d572bcdacfa59cd4b55eddb6.tar.gz dt-utils-755a69659c4283c5d572bcdacfa59cd4b55eddb6.tar.xz |
barebox-state: Check of_property_count_strings return value
When a enum32 state variable node does not have a "names" property bail
out gracefully instead of crashing.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | src/barebox-state.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/barebox-state.c b/src/barebox-state.c index 02e085b..f64347c 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -336,9 +336,13 @@ static struct state_variable *state_enum32_create(struct state *state, struct state_enum32 *enum32; int ret, i, num_names; - enum32 = xzalloc(sizeof(*enum32)); - num_names = of_property_count_strings(node, "names"); + if (num_names < 0) { + fprintf(stderr, "enum32 node without \"names\" property\n"); + return ERR_PTR(-EINVAL); + } + + enum32 = xzalloc(sizeof(*enum32)); enum32->names = xzalloc(sizeof(char *) * num_names); enum32->num_names = num_names; |