aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-davinci.c
diff options
context:
space:
mode:
authorAndrew F. Davis <afd@ti.com>2018-08-31 15:13:24 -0400
committerLinus Walleij <linus.walleij@linaro.org>2018-09-20 11:36:10 -0400
commitc809e37a3b5a889063ae737ff8b54705219d1ddc (patch)
tree14c6df1a83156a4e15e20355872aea2c85c87a82 /drivers/gpio/gpio-davinci.c
parent587f7a694f016b65f8de8ea8b5fb0402712b5475 (diff)
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: Andrew F. Davis <afd@ti.com> Tested-by: Keerthy <j-keerthy@ti.com> Acked-by: Keerthy <j-keerthy@ti.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-davinci.c')
-rw-r--r--drivers/gpio/gpio-davinci.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 14d1729927d3..121a7948f785 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -165,7 +165,7 @@ of_err:
165 165
166static int davinci_gpio_probe(struct platform_device *pdev) 166static int davinci_gpio_probe(struct platform_device *pdev)
167{ 167{
168 int gpio, bank, i, ret = 0; 168 int bank, i, ret = 0;
169 unsigned int ngpio, nbank, nirq; 169 unsigned int ngpio, nbank, nirq;
170 struct davinci_gpio_controller *chips; 170 struct davinci_gpio_controller *chips;
171 struct davinci_gpio_platform_data *pdata; 171 struct davinci_gpio_platform_data *pdata;
@@ -204,10 +204,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
204 else 204 else
205 nirq = DIV_ROUND_UP(ngpio, 16); 205 nirq = DIV_ROUND_UP(ngpio, 16);
206 206
207 nbank = DIV_ROUND_UP(ngpio, 32); 207 chips = devm_kzalloc(dev, sizeof(*chips), GFP_KERNEL);
208 chips = devm_kcalloc(dev,
209 nbank, sizeof(struct davinci_gpio_controller),
210 GFP_KERNEL);
211 if (!chips) 208 if (!chips)
212 return -ENOMEM; 209 return -ENOMEM;
213 210
@@ -247,7 +244,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
247#endif 244#endif
248 spin_lock_init(&chips->lock); 245 spin_lock_init(&chips->lock);
249 246
250 for (gpio = 0, bank = 0; gpio < ngpio; gpio += 32, bank++) 247 nbank = DIV_ROUND_UP(ngpio, 32);
248 for (bank = 0; bank < nbank; bank++)
251 chips->regs[bank] = gpio_base + offset_array[bank]; 249 chips->regs[bank] = gpio_base + offset_array[bank];
252 250
253 ret = devm_gpiochip_add_data(dev, &chips->chip, chips); 251 ret = devm_gpiochip_add_data(dev, &chips->chip, chips);