Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c809e37a authored by Andrew F. Davis's avatar Andrew F. Davis Committed by Linus Walleij
Browse files

gpio: davinci: Allocate the correct amount of memory for controller



Previously we created a controller structure per bank of GPIO pins. This
has since been changed to one per controller, but the allocation size
was not changed. Fix this here.

This also leaves the variable 'nbank' unused, instead of removing it,
move it down and use it to clean up a loop. For loops with multiple
initializers and/or iteration expressions, especially ones that don't
use those loop counters are quite hard to follow, fix this.

Signed-off-by: default avatarAndrew F. Davis <afd@ti.com>
Tested-by: default avatarKeerthy <j-keerthy@ti.com>
Acked-by: default avatarKeerthy <j-keerthy@ti.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 587f7a69
Loading
Loading
Loading
Loading
+4 −6
Original line number Original line Diff line number Diff line
@@ -165,7 +165,7 @@ davinci_gpio_get_pdata(struct platform_device *pdev)


static int davinci_gpio_probe(struct platform_device *pdev)
static int davinci_gpio_probe(struct platform_device *pdev)
{
{
	int gpio, bank, i, ret = 0;
	int bank, i, ret = 0;
	unsigned int ngpio, nbank, nirq;
	unsigned int ngpio, nbank, nirq;
	struct davinci_gpio_controller *chips;
	struct davinci_gpio_controller *chips;
	struct davinci_gpio_platform_data *pdata;
	struct davinci_gpio_platform_data *pdata;
@@ -204,10 +204,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
	else
	else
		nirq = DIV_ROUND_UP(ngpio, 16);
		nirq = DIV_ROUND_UP(ngpio, 16);


	nbank = DIV_ROUND_UP(ngpio, 32);
	chips = devm_kzalloc(dev, sizeof(*chips), GFP_KERNEL);
	chips = devm_kcalloc(dev,
			     nbank, sizeof(struct davinci_gpio_controller),
			     GFP_KERNEL);
	if (!chips)
	if (!chips)
		return -ENOMEM;
		return -ENOMEM;


@@ -247,7 +244,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
#endif
#endif
	spin_lock_init(&chips->lock);
	spin_lock_init(&chips->lock);


	for (gpio = 0, bank = 0; gpio < ngpio; gpio += 32, bank++)
	nbank = DIV_ROUND_UP(ngpio, 32);
	for (bank = 0; bank < nbank; bank++)
		chips->regs[bank] = gpio_base + offset_array[bank];
		chips->regs[bank] = gpio_base + offset_array[bank];


	ret = devm_gpiochip_add_data(dev, &chips->chip, chips);
	ret = devm_gpiochip_add_data(dev, &chips->chip, chips);