Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/44x: Drop legacy-of-mm-gpiochip.h header

Remove legacy-of-mm-gpiochip.h header file. The above mentioned
file provides an OF API that's deprecated. There is no agnostic
alternatives to it and we have to open code the logic which was
hidden behind of_mm_gpiochip_add_data(). Note, most of the GPIO
drivers are using their own labeling schemas and resource retrieval
that only a few may gain of the code deduplication, so whenever
alternative is appear we can move drivers again to use that one.

As a side effect this change fixes a potential memory leak on
an error path, if of_mm_gpiochip_add_data() fails.

[Text copied from commit 34064c8267a6 ("powerpc/8xx: Drop
legacy-of-mm-gpiochip.h header")]

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/2f8f16eac72b9ec202b6e593939b44308891a661.1755519343.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Madhavan Srinivasan
d2ad26e7 1044dbaf

+19 -15
-1
arch/powerpc/platforms/44x/Kconfig
··· 231 231 bool "PPC4xx GPIO support" 232 232 depends on 44x 233 233 select GPIOLIB 234 - select OF_GPIO_MM_GPIOCHIP 235 234 help 236 235 Enable gpiolib support for ppc440 based boards 237 236
+19 -14
arch/powerpc/platforms/44x/gpio.c
··· 14 14 #include <linux/spinlock.h> 15 15 #include <linux/io.h> 16 16 #include <linux/of.h> 17 - #include <linux/gpio/legacy-of-mm-gpiochip.h> 18 17 #include <linux/gpio/driver.h> 19 18 #include <linux/types.h> 20 19 #include <linux/slab.h> ··· 45 46 }; 46 47 47 48 struct ppc4xx_gpio_chip { 48 - struct of_mm_gpio_chip mm_gc; 49 + struct gpio_chip gc; 50 + void __iomem *regs; 49 51 spinlock_t lock; 50 52 }; 51 53 ··· 58 58 59 59 static int ppc4xx_gpio_get(struct gpio_chip *gc, unsigned int gpio) 60 60 { 61 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 62 - struct ppc4xx_gpio __iomem *regs = mm_gc->regs; 61 + struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); 62 + struct ppc4xx_gpio __iomem *regs = chip->regs; 63 63 64 64 return !!(in_be32(&regs->ir) & GPIO_MASK(gpio)); 65 65 } ··· 67 67 static inline void 68 68 __ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 69 69 { 70 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 71 - struct ppc4xx_gpio __iomem *regs = mm_gc->regs; 70 + struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); 71 + struct ppc4xx_gpio __iomem *regs = chip->regs; 72 72 73 73 if (val) 74 74 setbits32(&regs->or, GPIO_MASK(gpio)); ··· 94 94 95 95 static int ppc4xx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 96 96 { 97 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 98 97 struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); 99 - struct ppc4xx_gpio __iomem *regs = mm_gc->regs; 98 + struct ppc4xx_gpio __iomem *regs = chip->regs; 100 99 unsigned long flags; 101 100 102 101 spin_lock_irqsave(&chip->lock, flags); ··· 123 124 static int 124 125 ppc4xx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 125 126 { 126 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 127 127 struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc); 128 - struct ppc4xx_gpio __iomem *regs = mm_gc->regs; 128 + struct ppc4xx_gpio __iomem *regs = chip->regs; 129 129 unsigned long flags; 130 130 131 131 spin_lock_irqsave(&chip->lock, flags); ··· 159 161 struct device *dev = &ofdev->dev; 160 162 struct device_node *np = dev->of_node; 161 163 struct ppc4xx_gpio_chip *chip; 162 - struct of_mm_gpio_chip *mm_gc; 163 164 struct gpio_chip *gc; 164 165 165 166 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); ··· 167 170 168 171 spin_lock_init(&chip->lock); 169 172 170 - mm_gc = &chip->mm_gc; 171 - gc = &mm_gc->gc; 173 + gc = &chip->gc; 172 174 175 + gc->base = -1; 173 176 gc->ngpio = 32; 174 177 gc->direction_input = ppc4xx_gpio_dir_in; 175 178 gc->direction_output = ppc4xx_gpio_dir_out; 176 179 gc->get = ppc4xx_gpio_get; 177 180 gc->set = ppc4xx_gpio_set; 178 181 179 - return of_mm_gpiochip_add_data(np, mm_gc, chip); 182 + gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np); 183 + if (!gc->label) 184 + return -ENOMEM; 185 + 186 + chip->regs = devm_of_iomap(dev, np, 0, NULL); 187 + if (IS_ERR(chip->regs)) 188 + return PTR_ERR(chip->regs); 189 + 190 + return devm_gpiochip_add_data(dev, gc, chip); 180 191 } 181 192 182 193 static const struct of_device_id ppc4xx_gpio_match[] = {