* [PATCH 1/2] pinctrl: rp1: use raw spinlock for gpio regmap
2026-11-26 3:54 [PATCH 0/2] pinctrl: rp1: fix RT sleep and clean up map freeing Xiaolei Wang
@ 2026-11-26 3:54 ` Xiaolei Wang
2026-11-26 3:54 ` [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup Xiaolei Wang
1 sibling, 0 replies; 4+ messages in thread
From: Xiaolei Wang @ 2026-11-26 3:54 UTC (permalink / raw)
To: linusw, florian.fainelli, bcm-kernel-feedback-list, daniel,
wangxiaolei01, iivanov, andrea.porta, phil
Cc: linux-gpio, linux-rpi-kernel, linux-arm-kernel, linux-kernel,
stable
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: 4732f079cd19f ("pinctrl: rp1: Implement RaspberryPi RP1 gpio support")
Cc: stable@vger.kernel.org
Signed-off-by: Xiaolei Wang <wangxiaolei01@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
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup
2026-11-26 3:54 [PATCH 0/2] pinctrl: rp1: fix RT sleep and clean up map freeing Xiaolei Wang
2026-11-26 3:54 ` [PATCH 1/2] pinctrl: rp1: use raw spinlock for gpio regmap Xiaolei Wang
@ 2026-11-26 3:54 ` Xiaolei Wang
2026-11-26 4:02 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Xiaolei Wang @ 2026-11-26 3:54 UTC (permalink / raw)
To: linusw, florian.fainelli, bcm-kernel-feedback-list, daniel,
wangxiaolei01, iivanov, andrea.porta, phil
Cc: linux-gpio, linux-rpi-kernel, linux-arm-kernel, linux-kernel
The rp1 driver open-codes a dt_free_map callback that frees the config
arrays of pinctrl maps and the map array itself. This duplicates
pinctrl_utils_free_map(), which the pinctrl core already provides for
exactly this purpose.
The local copy only handles CONFIGS_PIN maps. Because the driver can
delegate map creation to the generic pinconf DT parser, CONFIGS_GROUP
maps may also be produced, and their config arrays would be leaked by
the open-coded version. The core helper handles both types, so using
it removes the duplicate code and closes that leak at the same time.
Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>
---
drivers/pinctrl/pinctrl-rp1.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-rp1.c b/drivers/pinctrl/pinctrl-rp1.c
index 99566a25ecb4..bf2c300eef29 100644
--- a/drivers/pinctrl/pinctrl-rp1.c
+++ b/drivers/pinctrl/pinctrl-rp1.c
@@ -1089,18 +1089,6 @@ static void rp1_pctl_pin_dbg_show(struct pinctrl_dev *pctldev,
irq, irq_type_names[pin->irq_type]);
}
-static void rp1_pctl_dt_free_map(struct pinctrl_dev *pctldev,
- struct pinctrl_map *maps, unsigned int num_maps)
-{
- int i;
-
- for (i = 0; i < num_maps; i++)
- if (maps[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
- kfree(maps[i].data.configs.configs);
-
- kfree(maps);
-}
-
static int rp1_pctl_legacy_map_func(struct rp1_pinctrl *pc,
struct device_node *np, u32 pin, u32 fnum,
struct pinctrl_map *maps,
@@ -1286,7 +1274,7 @@ static int rp1_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
return 0;
out:
- rp1_pctl_dt_free_map(pctldev, maps, reserved_maps);
+ pinctrl_utils_free_map(pctldev, maps, reserved_maps);
return err;
}
@@ -1296,7 +1284,7 @@ static const struct pinctrl_ops rp1_pctl_ops = {
.get_group_pins = rp1_pctl_get_group_pins,
.pin_dbg_show = rp1_pctl_pin_dbg_show,
.dt_node_to_map = rp1_pctl_dt_node_to_map,
- .dt_free_map = rp1_pctl_dt_free_map,
+ .dt_free_map = pinctrl_utils_free_map,
};
static int rp1_pmx_free(struct pinctrl_dev *pctldev, unsigned int offset)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread