Skip to content

Commit 8312d50

Browse files
committed
Merge tag 'gpio-fixes-for-v5.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into fixes
gpio fixes for v5.7-rc3 - fix set_config in pca953x - improve robustness of the new line watch/unwatch ioctl() - fix a bug with caling a sleeping function with spinlock taken
2 parents ae83d0b + 6409d04 commit 8312d50

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
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/gpiolib.c

Lines changed: 26 additions & 3 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;

0 commit comments

Comments
 (0)