Skip to content

Commit

Permalink
led: gpio: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
Browse files Browse the repository at this point in the history
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 <Li.Xiubo@freescale.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
  • Loading branch information
Xiubo Li authored and Bryan Wu committed Sep 29, 2014
1 parent 4cc7234 commit a823e76
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/leds/leds-gpio-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a823e76

Please sign in to comment.