From: Xiubo Li
Date: Sun, 28 Sep 2014 08:57:15 +0000 (-0700)
Subject: led: gpio: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
X-Git-Tag: firefly_0821_release~176^2~2985^2~1
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a823e76138466225d0a9f45520c5654132939a01;p=firefly-linux-kernel-4.4.55.git
led: gpio: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
Since we cannot make sure the 'pdata->num_leds' will always be none
zero here, and then if it equals to zero, the kmemdup() will return
ZERO_SIZE_PTR, which equals to ((void *)16).
So this patch fix this with just doing the zero check before calling
kmemdup().
Signed-off-by: Xiubo Li
Signed-off-by: Bryan Wu
---
diff --git a/drivers/leds/leds-gpio-register.c b/drivers/leds/leds-gpio-register.c
index fbd89344bec4..75717ba68ae0 100644
--- a/drivers/leds/leds-gpio-register.c
+++ b/drivers/leds/leds-gpio-register.c
@@ -28,6 +28,9 @@ struct platform_device *__init gpio_led_register_device(
struct platform_device *ret;
struct gpio_led_platform_data _pdata = *pdata;
+ if (!pdata->num_leds)
+ return ERR_PTR(-EINVAL);
+
_pdata.leds = kmemdup(pdata->leds,
pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL);
if (!_pdata.leds)