[PATCH 3/4] staging: greybus: light: Check return value of a kstrndup() call in gb_lights_light_config()

From: SF Markus Elfring
Date: Fri Dec 09 2016 - 09:38:16 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 9 Dec 2016 14:36:16 +0100

A return value was not checked after a call of the function "kstrndup".
This issue was detected by using the Coccinelle software.

Add a bit of exception handling.

Fixes: 2870b52bae4c81823ffcb3ed2b0626fb39d64f48 ("greybus: lights: add lights implementation")

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/staging/greybus/light.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 27bfc20eb9a5..c9c377f40f56 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -1030,6 +1030,9 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id)

light->channels_count = conf.channel_count;
light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL);
+ if (!light->name)
+ return -ENOMEM;
+
light->channels = kcalloc(light->channels_count,
sizeof(*light->channels),
GFP_KERNEL);
--
2.11.0