Skip to content

Commit 8ec91c0

Browse files
committed
Merge tag 'gpio-v5.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Some GPIO fixes for v5.7, slightly overdue. Been learning MMUs and KASan that is why it's late. Bartosz helped me out, luckily! - Fix pin configuration in the PCA953x driver - Ruggedize the watch/unwatch ioctl() - Possible call to a sleeping function when holding a spinlock, avoid this - Fix UML builds with DT overlays - Mask Tegra GPIO IRQs during shutdown()" * tag 'gpio-v5.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: tegra: mask GPIO IRQs during IRQ shutdown gpio: of: Build fails if CONFIG_OF_DYNAMIC enabled without CONFIG_OF_GPIO gpiolib: don't call sleeping functions with a spinlock taken gpiolib: improve the robustness of watch/unwatch ioctl() gpio: pca953x: Fix pca953x_gpio_set_config
2 parents e719340 + 0cf253e commit 8ec91c0

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

drivers/gpio/gpio-pca953x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
531531
{
532532
struct pca953x_chip *chip = gpiochip_get_data(gc);
533533

534-
switch (config) {
534+
switch (pinconf_to_config_param(config)) {
535535
case PIN_CONFIG_BIAS_PULL_UP:
536536
case PIN_CONFIG_BIAS_PULL_DOWN:
537537
return pca953x_gpio_set_pull_up_down(chip, offset, config);

drivers/gpio/gpio-tegra.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ static void tegra_gpio_irq_shutdown(struct irq_data *d)
368368
struct tegra_gpio_info *tgi = bank->tgi;
369369
unsigned int gpio = d->hwirq;
370370

371+
tegra_gpio_irq_mask(d);
371372
gpiochip_unlock_as_irq(&tgi->gc, gpio);
372373
}
373374

drivers/gpio/gpiolib.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,19 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
11581158
struct gpioline_info *info)
11591159
{
11601160
struct gpio_chip *gc = desc->gdev->chip;
1161+
bool ok_for_pinctrl;
11611162
unsigned long flags;
11621163

1164+
/*
1165+
* This function takes a mutex so we must check this before taking
1166+
* the spinlock.
1167+
*
1168+
* FIXME: find a non-racy way to retrieve this information. Maybe a
1169+
* lock common to both frameworks?
1170+
*/
1171+
ok_for_pinctrl =
1172+
pinctrl_gpio_can_use_line(gc->base + info->line_offset);
1173+
11631174
spin_lock_irqsave(&gpio_lock, flags);
11641175

11651176
if (desc->name) {
@@ -1186,7 +1197,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
11861197
test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
11871198
test_bit(FLAG_EXPORT, &desc->flags) ||
11881199
test_bit(FLAG_SYSFS, &desc->flags) ||
1189-
!pinctrl_gpio_can_use_line(gc->base + info->line_offset))
1200+
!ok_for_pinctrl)
11901201
info->flags |= GPIOLINE_FLAG_KERNEL;
11911202
if (test_bit(FLAG_IS_OUT, &desc->flags))
11921203
info->flags |= GPIOLINE_FLAG_IS_OUT;
@@ -1227,6 +1238,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
12271238
void __user *ip = (void __user *)arg;
12281239
struct gpio_desc *desc;
12291240
__u32 offset;
1241+
int hwgpio;
12301242

12311243
/* We fail any subsequent ioctl():s when the chip is gone */
12321244
if (!gc)
@@ -1259,13 +1271,19 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
12591271
if (IS_ERR(desc))
12601272
return PTR_ERR(desc);
12611273

1274+
hwgpio = gpio_chip_hwgpio(desc);
1275+
1276+
if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL &&
1277+
test_bit(hwgpio, priv->watched_lines))
1278+
return -EBUSY;
1279+
12621280
gpio_desc_to_lineinfo(desc, &lineinfo);
12631281

12641282
if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))
12651283
return -EFAULT;
12661284

12671285
if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL)
1268-
set_bit(gpio_chip_hwgpio(desc), priv->watched_lines);
1286+
set_bit(hwgpio, priv->watched_lines);
12691287

12701288
return 0;
12711289
} else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) {
@@ -1280,7 +1298,12 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
12801298
if (IS_ERR(desc))
12811299
return PTR_ERR(desc);
12821300

1283-
clear_bit(gpio_chip_hwgpio(desc), priv->watched_lines);
1301+
hwgpio = gpio_chip_hwgpio(desc);
1302+
1303+
if (!test_bit(hwgpio, priv->watched_lines))
1304+
return -EBUSY;
1305+
1306+
clear_bit(hwgpio, priv->watched_lines);
12841307
return 0;
12851308
}
12861309
return -EINVAL;
@@ -5289,8 +5312,9 @@ static int __init gpiolib_dev_init(void)
52895312
gpiolib_initialized = true;
52905313
gpiochip_setup_devs();
52915314

5292-
if (IS_ENABLED(CONFIG_OF_DYNAMIC))
5293-
WARN_ON(of_reconfig_notifier_register(&gpio_of_notifier));
5315+
#if IS_ENABLED(CONFIG_OF_DYNAMIC) && IS_ENABLED(CONFIG_OF_GPIO)
5316+
WARN_ON(of_reconfig_notifier_register(&gpio_of_notifier));
5317+
#endif /* CONFIG_OF_DYNAMIC && CONFIG_OF_GPIO */
52945318

52955319
return ret;
52965320
}

0 commit comments

Comments
 (0)