[PATCH v2 1/2] pinctrl: rp1: use raw spinlock for gpio regmap

Xiaolei Wang wangxiaolei01 at kaihong.com
Tue Dec 1 01:07:16 PST 2026


The rp1 gpio irq_chip callbacks run in atomic context: irq_set_type()
is called with the irq descriptor's raw spinlock held, and the driver
itself also disables preemption/interrupts while accessing the GPIO
registers.  On PREEMPT_RT, however, the gpio regmap is created with the
default spinlock_t, which becomes a sleepable rt_spin_lock.  Writing a
register field from that atomic context therefore attempts to sleep and
triggers a "sleeping function called from invalid context" BUG.

This is reachable from ordinary userspace: requesting a GPIO line with
an edge trigger through the GPIO cdev ioctl ends up in irq_set_type(),
so any application using edge-detected GPIO lines hits it on an RT
kernel.

  Call trace:
   __might_resched
   rt_spin_lock
   regmap_lock_spinlock
   regmap_field_update_bits_base
   rp1_gpio_irq_set_type
   __irq_set_trigger
   __setup_irq
   request_threaded_irq
   edge_detector_setup
   linereq_create
   gpio_ioctl

Make the gpio regmap use a raw spinlock so its lock matches the atomic
contexts the registers are accessed from.

Fixes: 4732f079cd19 ("pinctrl: rp1: Implement RaspberryPi RP1 gpio support")
Cc: stable at vger.kernel.org
Signed-off-by: Xiaolei Wang <wangxiaolei01 at kaihong.com>
---
 drivers/pinctrl/pinctrl-rp1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pinctrl/pinctrl-rp1.c b/drivers/pinctrl/pinctrl-rp1.c
index dd0e85c2ca33..99566a25ecb4 100644
--- a/drivers/pinctrl/pinctrl-rp1.c
+++ b/drivers/pinctrl/pinctrl-rp1.c
@@ -1693,6 +1693,7 @@ static const struct regmap_config rp1_pinctrl_gpio_regmap_cfg = {
 	.rd_table = &rp1_gpio_reg_table,
 	.name = "rp1-gpio",
 	.max_register = 0xb11c,
+	.use_raw_spinlock = true,
 };
 
 static const struct regmap_config rp1_pinctrl_rio_regmap_cfg = {
-- 
2.34.1




More information about the linux-arm-kernel mailing list