Merge tag 'pinctrl-v5.16-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl

Pull pin control fixes from Linus Walleij:
"Some hopefully final pin control fixes for the v5.16 kernel:

- Fix an out-of-bounds bug in the Mediatek driver

- Fix an init order bug in the Broadcom BCM2835 driver

- Fix a GPIO offset bug in the STM32 driver"

* tag 'pinctrl-v5.16-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl:
pinctrl: stm32: consider the GPIO offset to expose all the GPIO lines
pinctrl: bcm2835: Change init order for gpio hogs
pinctrl: mediatek: fix global-out-of-bounds issue

Changed files
+26 -19
drivers
+16 -13
drivers/pinctrl/bcm/pinctrl-bcm2835.c
··· 1244 1244 raw_spin_lock_init(&pc->irq_lock[i]); 1245 1245 } 1246 1246 1247 + pc->pctl_desc = *pdata->pctl_desc; 1248 + pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc); 1249 + if (IS_ERR(pc->pctl_dev)) { 1250 + gpiochip_remove(&pc->gpio_chip); 1251 + return PTR_ERR(pc->pctl_dev); 1252 + } 1253 + 1254 + pc->gpio_range = *pdata->gpio_range; 1255 + pc->gpio_range.base = pc->gpio_chip.base; 1256 + pc->gpio_range.gc = &pc->gpio_chip; 1257 + pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range); 1258 + 1247 1259 girq = &pc->gpio_chip.irq; 1248 1260 girq->chip = &bcm2835_gpio_irq_chip; 1249 1261 girq->parent_handler = bcm2835_gpio_irq_handler; ··· 1263 1251 girq->parents = devm_kcalloc(dev, BCM2835_NUM_IRQS, 1264 1252 sizeof(*girq->parents), 1265 1253 GFP_KERNEL); 1266 - if (!girq->parents) 1254 + if (!girq->parents) { 1255 + pinctrl_remove_gpio_range(pc->pctl_dev, &pc->gpio_range); 1267 1256 return -ENOMEM; 1257 + } 1268 1258 1269 1259 if (is_7211) { 1270 1260 pc->wake_irq = devm_kcalloc(dev, BCM2835_NUM_IRQS, ··· 1321 1307 err = gpiochip_add_data(&pc->gpio_chip, pc); 1322 1308 if (err) { 1323 1309 dev_err(dev, "could not add GPIO chip\n"); 1310 + pinctrl_remove_gpio_range(pc->pctl_dev, &pc->gpio_range); 1324 1311 return err; 1325 1312 } 1326 - 1327 - pc->pctl_desc = *pdata->pctl_desc; 1328 - pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc); 1329 - if (IS_ERR(pc->pctl_dev)) { 1330 - gpiochip_remove(&pc->gpio_chip); 1331 - return PTR_ERR(pc->pctl_dev); 1332 - } 1333 - 1334 - pc->gpio_range = *pdata->gpio_range; 1335 - pc->gpio_range.base = pc->gpio_chip.base; 1336 - pc->gpio_range.gc = &pc->gpio_chip; 1337 - pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range); 1338 1313 1339 1314 return 0; 1340 1315 }
+6 -2
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
··· 285 285 desc = (const struct mtk_pin_desc *)hw->soc->pins; 286 286 *gpio_chip = &hw->chip; 287 287 288 - /* Be greedy to guess first gpio_n is equal to eint_n */ 289 - if (desc[eint_n].eint.eint_n == eint_n) 288 + /* 289 + * Be greedy to guess first gpio_n is equal to eint_n. 290 + * Only eint virtual eint number is greater than gpio number. 291 + */ 292 + if (hw->soc->npins > eint_n && 293 + desc[eint_n].eint.eint_n == eint_n) 290 294 *gpio_n = eint_n; 291 295 else 292 296 *gpio_n = mtk_xt_find_eint_num(hw, eint_n);
+4 -4
drivers/pinctrl/stm32/pinctrl-stm32.c
··· 1251 1251 bank_nr = args.args[1] / STM32_GPIO_PINS_PER_BANK; 1252 1252 bank->gpio_chip.base = args.args[1]; 1253 1253 1254 - npins = args.args[2]; 1255 - while (!of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 1256 - ++i, &args)) 1257 - npins += args.args[2]; 1254 + /* get the last defined gpio line (offset + nb of pins) */ 1255 + npins = args.args[0] + args.args[2]; 1256 + while (!of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, ++i, &args)) 1257 + npins = max(npins, (int)(args.args[0] + args.args[2])); 1258 1258 } else { 1259 1259 bank_nr = pctl->nbanks; 1260 1260 bank->gpio_chip.base = bank_nr * STM32_GPIO_PINS_PER_BANK;