sh-pfc: Don't overallocate memory for the GPIO chip pins array
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Mon, 15 Jul 2013 11:36:39 +0000 (13:36 +0200)
committerLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Mon, 29 Jul 2013 13:17:41 +0000 (15:17 +0200)
The GPIO driver uses an array of sh_pfc_gpio_pin structures to store
per-GPIO pin data. The array size is miscomputed at allocation time by
using the number of the last pin instead of the number of pins. When the
pin space contains holes this leads to memory overallocation. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
drivers/pinctrl/sh-pfc/gpio.c

index d37efa7dcf90c78282a12503ad4a3d1cfb991e32..3620bd84ae938a5712ee7ad1ab66ac0474061115 100644 (file)
@@ -224,8 +224,8 @@ static int gpio_pin_setup(struct sh_pfc_chip *chip)
        struct gpio_chip *gc = &chip->gpio_chip;
        int ret;
 
-       chip->pins = devm_kzalloc(pfc->dev, pfc->nr_pins * sizeof(*chip->pins),
-                                 GFP_KERNEL);
+       chip->pins = devm_kzalloc(pfc->dev, pfc->info->nr_pins *
+                                 sizeof(*chip->pins), GFP_KERNEL);
        if (chip->pins == NULL)
                return -ENOMEM;