* [PATCH 0/2] pinctrl: rp1: fix RT sleep and clean up map freeing @ 2026-11-26 3:54 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 ` [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup Xiaolei Wang 0 siblings, 2 replies; 5+ 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 This series contains two independent changes to the RP1 pinctrl driver: a fix for a real PREEMPT_RT bug, and a cleanup that removes duplicated code and a small leak. They do not depend on each other. Patch 1 makes the gpio regmap use a raw spinlock. The 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 disables preemption and interrupts while touching the registers. On PREEMPT_RT the gpio regmap uses the default spinlock_t, which becomes a sleepable rt_spin_lock, so writing a register field from that context sleeps and triggers "sleeping function called from invalid context". 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. Other pinctrl drivers have already adopted the same fix, e.g. armada-37xx. Patch 2 replaces the open-coded dt_free_map callback with the core pinctrl_utils_free_map() helper. The local copy only frees config arrays of CONFIGS_PIN maps, but the driver may also produce CONFIGS_GROUP maps through the generic pinconf DT parser; their config arrays would be leaked. The core helper handles both types and removes the duplicate code. The RT bug was reproduced on a Raspberry Pi 5 with a PREEMPT_RT kernel by requesting an edge-triggered GPIO line from userspace. A full read of the pinctrl debugfs "pins" file (all 54 pins) produces no warnings. This patch was initially drafted with AI assistance and has been reviewed and modified by me. Xiaolei Wang (2): pinctrl: rp1: use raw spinlock for gpio regmap pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup drivers/pinctrl/pinctrl-rp1.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) -- 2.34.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [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; 5+ 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] 5+ 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; 5+ 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] 5+ messages in thread
* Re: [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup 2026-11-26 3:54 ` [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup Xiaolei Wang @ 2026-11-26 4:02 ` sashiko-bot 2026-11-30 1:28 ` 王孝雷 0 siblings, 1 reply; 5+ messages in thread From: sashiko-bot @ 2026-11-26 4:02 UTC (permalink / raw) To: Xiaolei Wang; +Cc: linux-gpio Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] pinctrl: rp1: missing Fixes trailer for CONFIGS_GROUP map config leak -- commit 1a3cbb21b3f3fd0731c811def787e2db607e8aeb Author: Xiaolei Wang <wangxiaolei01@kaihong.com> > pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup > > 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> [Severity: Low] Since this fixes a memory leak of PIN_MAP_TYPE_CONFIGS_GROUP config arrays, should it include a Fixes tag? Fixes: e3ce7b897388 ("pinctrl: rp1: Implement RaspberryPi RP1 pinmux/pinconf support") -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126035420.1836760-1-wangxiaolei01@kaihong.com?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup 2026-11-26 4:02 ` sashiko-bot @ 2026-11-30 1:28 ` 王孝雷 0 siblings, 0 replies; 5+ messages in thread From: 王孝雷 @ 2026-11-30 1:28 UTC (permalink / raw) To: sashiko-reviews; +Cc: linux-gpio > From: sashiko-bot@kernel.org > Date: Thu, Nov 26, 2026, 12:02 > Subject: Re: [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup > To: "Xiaolei Wang"<wangxiaolei01@kaihong.com> > Cc: <linux-gpio@vger.kernel.org> > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [Low] pinctrl: rp1: missing Fixes trailer for CONFIGS_GROUP map config > leak > -- > > commit 1a3cbb21b3f3fd0731c811def787e2db607e8aeb > Author: Xiaolei Wang <wangxiaolei01@kaihong.com> > > > pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup > > > > 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> > > [Severity: Low] > Since this fixes a memory leak of PIN_MAP_TYPE_CONFIGS_GROUP config > arrays, should it include a Fixes tag? > > Fixes: e3ce7b897388 ("pinctrl: rp1: Implement RaspberryPi RP1 pinmux/pinconf support") Agreed, it will be fixed in v2. Thanks Xiaolei > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261126035420.1836760-1-wangxiaolei01@kaihong.com?part=2 > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 1:29 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup Xiaolei Wang 2026-11-26 4:02 ` sashiko-bot 2026-11-30 1:28 ` 王孝雷
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.