Skip to content

Commit 37174f3

Browse files
digetxbrgl
authored andcommitted
gpio: tegra: Use raw_spinlock
Use raw_spinlock in order to fix spurious messages about invalid context when spinlock debugging is enabled. This happens because there is a legit nested raw_spinlock->spinlock locking usage within IRQ-related code. IRQ core uses raw spinlock and then Tegra GPIO driver uses a nested spinlock. The debug code can't recognize and handle this case, hence we need to use raw spinlock in the GPIO driver. [ BUG: Invalid wait context ] ... (dump_stack) from (__lock_acquire) (__lock_acquire) from (lock_acquire) (lock_acquire) from (_raw_spin_lock_irqsave) (_raw_spin_lock_irqsave) from (tegra_gpio_irq_set_type) (tegra_gpio_irq_set_type) from (__irq_set_trigger) (__irq_set_trigger) from (__setup_irq) (__setup_irq) from (request_threaded_irq) (request_threaded_irq) from (devm_request_threaded_irq) (devm_request_threaded_irq) from (elants_i2c_probe) (elants_i2c_probe) from (i2c_device_probe) ... Tested-by: Peter Geis <pgwipeout@gmail.com> Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
1 parent 6ea68fc commit 37174f3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/gpio/gpio-tegra.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,16 @@ struct tegra_gpio_info;
6161
struct tegra_gpio_bank {
6262
unsigned int bank;
6363
unsigned int irq;
64-
spinlock_t lvl_lock[4];
65-
spinlock_t dbc_lock[4]; /* Lock for updating debounce count register */
64+
65+
/*
66+
* IRQ-core code uses raw locking, and thus, nested locking also
67+
* should be raw in order not to trip spinlock debug warnings.
68+
*/
69+
raw_spinlock_t lvl_lock[4];
70+
71+
/* Lock for updating debounce count register */
72+
spinlock_t dbc_lock[4];
73+
6674
#ifdef CONFIG_PM_SLEEP
6775
u32 cnf[4];
6876
u32 out[4];
@@ -334,14 +342,14 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
334342
return -EINVAL;
335343
}
336344

337-
spin_lock_irqsave(&bank->lvl_lock[port], flags);
345+
raw_spin_lock_irqsave(&bank->lvl_lock[port], flags);
338346

339347
val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio));
340348
val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio));
341349
val |= lvl_type << GPIO_BIT(gpio);
342350
tegra_gpio_writel(tgi, val, GPIO_INT_LVL(tgi, gpio));
343351

344-
spin_unlock_irqrestore(&bank->lvl_lock[port], flags);
352+
raw_spin_unlock_irqrestore(&bank->lvl_lock[port], flags);
345353

346354
tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0);
347355
tegra_gpio_enable(tgi, gpio);
@@ -675,7 +683,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
675683
tegra_gpio_irq_handler, bank);
676684

677685
for (j = 0; j < 4; j++) {
678-
spin_lock_init(&bank->lvl_lock[j]);
686+
raw_spin_lock_init(&bank->lvl_lock[j]);
679687
spin_lock_init(&bank->dbc_lock[j]);
680688
}
681689
}

0 commit comments

Comments
 (0)