Skip to contentSkip to conversation

gpio/aspeed: Fix incorrect number of banks

PATCH In review Rashmica Gupta 3 participants 3 messages Sep 6, 2019 – Sep 11, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 2/5 gpio/aspeed: Fix incorrect number of banks

The current calculation for the number of GPIO banks is only correct if the number of GPIOs is a multiple of 32 (if there were 31 GPIOs we would currently say there are 0 banks, which is incorrect).

Fixes 361b79119a4b7 ('gpio: Add Aspeed driver')
---
 drivers/gpio/gpio-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-aspeed.c +1 -1
index 9defe25d4721..b83e23aecd18 100644
@@ -1165,7 +1165,7 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
 	gpio->chip.base = -1;
 
 	/* Allocate a cache of the output registers */
-	banks = gpio->config->nr_gpios >> 5;
+	banks = DIV_ROUND_UP(gpio->config->nr_gpios, 32);
 	gpio->dcache = devm_kcalloc(&pdev->dev,
 				    banks, sizeof(u32), GFP_KERNEL);
 	if (!gpio->dcache)
Signature · 1 line
2.20.1
maintainer Reviewed-by on v3 2/5
#1 lore raw
Quoted 9 lines · Rashmica Gupta

The current calculation for the number of GPIO banks is only correct if the number of GPIOs is a multiple of 32 (if there were 31 GPIOs we would currently say there are 0 banks, which is incorrect).

Fixes 361b79119a4b7 ('gpio: Add Aspeed driver')
Quoted 20 lines
---
 drivers/gpio/gpio-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-aspeed.c +1 -2
index 9defe25d4721..b83e23aecd18 100644
@@ -1165,7 +1165,7 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
        gpio->chip.base = -1;
 
        /* Allocate a cache of the output registers */
-       banks = gpio->config->nr_gpios >> 5;
+       banks = DIV_ROUND_UP(gpio->config->nr_gpios, 32);
        gpio->dcache = devm_kcalloc(&pdev->dev,
                                    banks, sizeof(u32), GFP_KERNEL);
        if (!gpio->dcache)
--

2.20.1