Skip to contentSkip to conversation

gpio: tangier: calculate number of ctx using temporary variable

PATCH Applied Raag Jadav 2 participants 2 messages May 22, 2023 – May 23, 2023

Subsystems (3)
lore
Share & tools
lore

Raag Jadav

author
#0 lore raw

PATCH 1/1 gpio: tangier: calculate number of ctx using temporary variable

Utilize a temporary variable to calculate number of ctx from ngpio inside ->probe() implementation.
While at it, include math.h for using DIV_ROUND_UP().

---
 drivers/gpio/gpio-tangier.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-tangier.c +3 -1
index e990781935ba..7ce3eddaed25 100644
@@ -16,6 +16,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/irq.h>
+#include <linux/math.h>
 #include <linux/module.h>
 #include <linux/pinctrl/pinconf-generic.h>
 #include <linux/spinlock.h>
@@ -428,10 +429,11 @@ static int tng_gpio_add_pin_ranges(struct gpio_chip *chip)
 int devm_tng_gpio_probe(struct device *dev, struct tng_gpio *gpio)
 {
 	const struct tng_gpio_info *info = &gpio->info;
+	size_t nctx = DIV_ROUND_UP(info->ngpio, 32);
 	struct gpio_irq_chip *girq;
 	int ret;
 
-	gpio->ctx = devm_kcalloc(dev, DIV_ROUND_UP(info->ngpio, 32), sizeof(*gpio->ctx), GFP_KERNEL);
+	gpio->ctx = devm_kcalloc(dev, nctx, sizeof(*gpio->ctx), GFP_KERNEL);
 	if (!gpio->ctx)
 		return -ENOMEM;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 36 lines · Raag Jadav

Utilize a temporary variable to calculate number of ctx from ngpio inside ->probe() implementation.
While at it, include math.h for using DIV_ROUND_UP().

---
 drivers/gpio/gpio-tangier.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-tangier.c +3 -2
index e990781935ba..7ce3eddaed25 100644
@@ -16,6 +16,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/irq.h>
+#include <linux/math.h>
 #include <linux/module.h>
 #include <linux/pinctrl/pinconf-generic.h>
 #include <linux/spinlock.h>
@@ -428,10 +429,11 @@ static int tng_gpio_add_pin_ranges(struct gpio_chip *chip)
 int devm_tng_gpio_probe(struct device *dev, struct tng_gpio *gpio)
 {
        const struct tng_gpio_info *info = &gpio->info;
+       size_t nctx = DIV_ROUND_UP(info->ngpio, 32);
        struct gpio_irq_chip *girq;
        int ret;
 
-       gpio->ctx = devm_kcalloc(dev, DIV_ROUND_UP(info->ngpio, 32), sizeof(*gpio->ctx), GFP_KERNEL);
+       gpio->ctx = devm_kcalloc(dev, nctx, sizeof(*gpio->ctx), GFP_KERNEL);
        if (!gpio->ctx)
                return -ENOMEM;
 
--
Quoted 2 lines

2.17.1

Applied, thanks!

Bartosz