Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko
@ 2026-12-03 20:54 Lee Jones
  2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:54 UTC (permalink / raw)
  To: lee, Heiko Stuebner, linux-arm-kernel, linux-rockchip
  Cc: linux-kernel, Alex Marginean, Andrew Lunn, Andy Shevchenko,
	Arnd Bergmann, Asmaa Mnebhi, Bartosz Golaszewski,
	Grygorii Strashko, Guangshuo Li, Jan Kotas, Janusz Krzysztofik,
	Jason Cooper, Jianqun Xu, Keerthy, Laurentiu Tudor, Linus Walleij,
	linux-acpi, linux-gpio, Mary Strodl, Mathias Nyman,
	Mathieu Dubois-Briand, Michael Walle, Mika Westerberg,
	Peter Korsgaard, Rosen Penev, Sebastian Hesselbarth, Song Hui,
	Thomas Petazzoni, William Breathitt Gray

These issues were reported by Sashiko.

Cc: Alex Marginean <alexandru.marginean@nxp.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Asmaa Mnebhi <asmaa@nvidia.com>
Cc: Bartosz Golaszewski <brgl@kernel.org>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Jan Kotas <jank@cadence.com>
Cc: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Jianqun Xu <jay.xu@rock-chips.com>
Cc: Keerthy <j-keerthy@ti.com>
Cc: Laurentiu Tudor <Laurentiu.Tudor@nxp.com>
Cc: Linus Walleij <linusw@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-gpio@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: Mary Strodl <mstrodl@csh.rit.edu>
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Cc: Michael Walle <mwalle@kernel.org>
Cc: Mika Westerberg <westeri@kernel.org>
Cc: Peter Korsgaard <jacmet@sunsite.dk>
Cc: Rosen Penev <rosenp@gmail.com>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Song Hui <hui.song_1@nxp.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: William Breathitt Gray <wbg@kernel.org>

Lee Jones (10):
  gpio: davinci: Validate ngpio against MAX_REGS_BANKS in
    davinci_gpio_probe()
  gpiolib: acpi: Hold gpio_device reference in
    acpi_dev_gpio_irq_wake_get_by()
  gpio: mvebu: Clear chained IRQ handlers on unbind
  gpio: rockchip: Unregister gpiochip on pin-range lookup errors
  gpiolib: Avoid undersized array bitmap in set fastpath
  gpio: mlxbf2: Embed context save registers to prevent suspend NULL
    dereference
  gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg
  gpio: mpc8xxx: Drop stale remove callback clearing chained handler
  gpio: mpsse: Allocate DMA-safe buffer in mpsse_write()
  gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition

 drivers/gpio/gpio-davinci.c      |  6 +++++-
 drivers/gpio/gpio-mlxbf2.c       | 14 +++++---------
 drivers/gpio/gpio-mpc8xxx.c      |  9 ---------
 drivers/gpio/gpio-mpsse.c        | 12 +++++++-----
 drivers/gpio/gpio-mvebu.c        | 15 ++++++++++++++-
 drivers/gpio/gpio-pcie-idio-24.c |  2 +-
 drivers/gpio/gpio-regmap.c       |  2 +-
 drivers/gpio/gpio-rockchip.c     | 12 ++++++++----
 drivers/gpio/gpiolib-acpi-core.c |  9 +++++++--
 drivers/gpio/gpiolib.c           |  5 +++--
 drivers/gpio/gpiolib.h           |  2 ++
 11 files changed, 53 insertions(+), 35 deletions(-)

-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe()
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
@ 2026-12-03 20:54 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Lee Jones
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:54 UTC (permalink / raw)
  To: lee, Keerthy, Linus Walleij, Bartosz Golaszewski, Software, Inc,
	Jan Kotas, Grygorii Strashko, linux-gpio
  Cc: linux-kernel, stable

davinci_gpio_probe() validates nirq against MAX_INT_PER_BANK (32) but
never bounds ngpio against MAX_REGS_BANKS (5, supporting at most 160
GPIOs).  A larger ti,ngpio value causes out-of-bounds reads past
offset_array[] and out-of-bounds writes past chips->regs[] and
chips->context[].

Reject ngpio values greater than MAX_REGS_BANKS * 32 with -EINVAL and
size offset_array with MAX_REGS_BANKS.

Fixes: 8f7cf8c65746 ("gpio: davinci: Remove gpio2regs function")
Closes: https://sashiko.dev/#/bug/linux-59cf1b6f-2241-467c-a82a-93a3d1bf5d16
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-davinci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 5f24367ad9af..f1f2b8f75761 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -43,7 +43,9 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);
 
 #define BINTEN	0x8 /* GPIO Interrupt Per-Bank Enable Register */
 
-static unsigned int offset_array[5] = {0x10, 0x38, 0x60, 0x88, 0xb0};
+static unsigned int offset_array[MAX_REGS_BANKS] = {
+	0x10, 0x38, 0x60, 0x88, 0xb0,
+};
 
 struct davinci_gpio_irq_data {
 	void __iomem			*regs;
@@ -179,6 +181,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, ret, "Failed to get the number of GPIOs\n");
 	if (ngpio == 0)
 		return dev_err_probe(dev, -EINVAL, "How many GPIOs?\n");
+	if (ngpio > MAX_REGS_BANKS * 32)
+		return dev_err_probe(dev, -EINVAL, "Too many GPIOs\n");
 
 	/*
 	 * If there are unbanked interrupts then the number of
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by()
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
  2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Mika Westerberg, Andy Shevchenko, Linus Walleij,
	Bartosz Golaszewski, Mathias Nyman, linux-gpio, linux-acpi
  Cc: linux-kernel, stable

acpi_dev_gpio_irq_wake_get_by() obtains a descriptor from
__acpi_find_gpio() without holding gpio_devices_srcu or acquiring a
reference to desc->gdev.  Because acpi_get_gpiod() releases its
gpio_device reference before returning, a concurrent GPIO controller
unbind can free gdev and gdev->descs before gpiod_to_irq() and the
subsequent descriptor configuration helpers run.

Expose gpio_devices_srcu internally within gpiolib, guard the
__acpi_find_gpio() lookup with gpio_devices_srcu, and acquire a scoped
gpio_device reference via gpio_device_get() before leaving the SRCU
read-side critical section.

Fixes: e348544f7994 ("gpio: protect the list of GPIO devices with SRCU")
Closes: https://sashiko.dev/#/bug/linux-97d822c4-1532-47ad-ab8d-717448607bc1
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpiolib-acpi-core.c | 9 +++++++--
 drivers/gpio/gpiolib.c           | 2 +-
 drivers/gpio/gpiolib.h           | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index f94f456dbe5f..fccb4fe71e80 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -1027,10 +1027,15 @@ int acpi_dev_gpio_irq_wake_get_by(struct acpi_device *adev, const char *con_id,
 
 	for (i = 0, idx = 0; idx <= index; i++) {
 		struct acpi_gpio_info info = {};
+		struct gpio_device *gdev __free(gpio_device_put) = NULL;
 		struct gpio_desc *desc;
 
-		/* Ignore -EPROBE_DEFER, it only matters if idx matches */
-		desc = __acpi_find_gpio(fwnode, con_id, i, true, &info);
+		scoped_guard(srcu, &gpio_devices_srcu) {
+			/* Ignore -EPROBE_DEFER, it only matters if idx matches */
+			desc = __acpi_find_gpio(fwnode, con_id, i, true, &info);
+			if (!IS_ERR(desc))
+				gdev = gpio_device_get(desc->gdev);
+		}
 		if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
 			return PTR_ERR(desc);
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 22c9288fea10..8843b2175caf 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -102,7 +102,7 @@ static LIST_HEAD(gpio_devices);
 /* Protects the GPIO device list against concurrent modifications. */
 static DEFINE_MUTEX(gpio_devices_lock);
 /* Ensures coherence during read-only accesses to the list of GPIO devices. */
-DEFINE_STATIC_SRCU(gpio_devices_srcu);
+DEFINE_SRCU(gpio_devices_srcu);
 
 const char *const gpio_suffixes[] = { "gpios", "gpio", NULL };
 
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 8dd8ea747f8a..c4a390231086 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -283,6 +283,8 @@ int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev);
 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum);
 const char *gpiod_get_label(struct gpio_desc *desc);
 
+extern struct srcu_struct gpio_devices_srcu;
+
 /* With descriptor prefix */
 
 #define __gpiod_pr(level, desc, fmt, ...) \
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
  2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
  2026-12-03 20:55 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 21:13   ` sashiko-bot
  2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Linus Walleij, Bartosz Golaszewski, Rosen Penev,
	Thomas Petazzoni, Andrew Lunn, Sebastian Hesselbarth,
	Arnd Bergmann, Jason Cooper, linux-gpio
  Cc: linux-kernel, stable

mvebu_gpio_probe() installs chained IRQ handlers pointing to the
devm-allocated mvchip structure, but neither sets suppress_bind_attrs
nor removes the chained handlers on unbind.  Unbinding the device tears
down mvchip->domain and frees mvchip while mvebu_gpio_irq_handler()
remains registered.

Register a devm cleanup action after installing the chained handlers to
clear each bank IRQ handler before the IRQ domain, GPIO chip, and
mvchip are torn down.

Fixes: fefe7b092345 ("gpio: introduce gpio-mvebu driver for Marvell SoCs")
Closes: https://sashiko.dev/#/bug/linux-de993bd0-1753-40e6-bd77-aa0fb133120b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-mvebu.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 6c2bcc5d749c..2f0a6cecd52a 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1181,6 +1181,17 @@ static void mvebu_gpio_remove_irq_domain(void *data)
 	irq_domain_remove(domain);
 }
 
+static void mvebu_gpio_remove_chained_handlers(void *data)
+{
+	struct mvebu_gpio_chip *mvchip = data;
+
+	for (unsigned int i = 0; i < ARRAY_SIZE(mvchip->bank_irq); i++) {
+		if (mvchip->bank_irq[i] > 0)
+			irq_set_chained_handler_and_data(mvchip->bank_irq[i],
+							 NULL, NULL);
+	}
+}
+
 static int mvebu_gpio_probe(struct platform_device *pdev)
 {
 	struct mvebu_gpio_chip *mvchip;
@@ -1370,7 +1381,9 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 		mvchip->bank_irq[i] = irq;
 	}
 
-	return 0;
+	return devm_add_action_or_reset(&pdev->dev,
+					mvebu_gpio_remove_chained_handlers,
+					mvchip);
 }
 
 static struct platform_driver mvebu_gpio_driver = {
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (2 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath Lee Jones
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Linus Walleij, Bartosz Golaszewski, Heiko Stuebner,
	Jianqun Xu, linux-gpio, linux-arm-kernel, linux-rockchip
  Cc: linux-kernel, stable

After gpiochip_add_data() succeeds in rockchip_gpiolib_register(), the
fallback path when gpio-ranges is absent returns -ENODATA or -ENODEV
directly when the parent pinctrl node or device cannot be found,
skipping the fail label that calls gpiochip_remove().

Jump to the fail label on both error paths so the GPIO chip is properly
unregistered on probe failure.

Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio")
Closes: https://sashiko.dev/#/bug/linux-d336bb33-7381-45ac-868f-1124190c27a1
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-rockchip.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 714604c11d78..a620c98718de 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -613,13 +613,17 @@ static int rockchip_gpiolib_register(struct rockchip_pin_bank *bank)
 		struct device_node *pctlnp = of_get_parent(bank->of_node);
 		struct pinctrl_dev *pctldev = NULL;
 
-		if (!pctlnp)
-			return -ENODATA;
+		if (!pctlnp) {
+			ret = -ENODATA;
+			goto fail;
+		}
 
 		pctldev = of_pinctrl_get(pctlnp);
 		of_node_put(pctlnp);
-		if (!pctldev)
-			return -ENODEV;
+		if (!pctldev) {
+			ret = -ENODEV;
+			goto fail;
+		}
 
 		ret = gpiochip_add_pin_range(gc, dev_name(pctldev->dev), 0,
 					     bank->pin_base, bank->nr_pins);
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (3 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Linus Walleij, Bartosz Golaszewski, Janusz Krzysztofik,
	linux-gpio
  Cc: linux-kernel, stable

gpiod_set_array_value_complex() passes the caller's value_bitmap
directly to gpiochip_set_multiple() whenever array_size <=
array_info->size.  When the GPIO chip spans more unsigned long words
than value_bitmap (BITS_TO_LONGS(gdev->ngpio) >
BITS_TO_LONGS(array_size)), drivers operating across gc->ngpio bits
read past the end of value_bitmap.

Require BITS_TO_LONGS(array_info->gdev->ngpio) <=
BITS_TO_LONGS(array_size) before taking the fastpath, mirroring the
corresponding check in the get fastpath.

Fixes: b17566a6b08b ("gpiolib: Implement fast processing path in get/set array")
Closes: https://sashiko.dev/#/bug/linux-9966f9bb-49bb-49d3-b955-762062db0725
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpiolib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8843b2175caf..7785be3e2de9 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3922,7 +3922,8 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
 	 */
 	if (array_info && array_info->desc == desc_array &&
 	    array_size <= array_info->size &&
-	    (void *)array_info == desc_array + array_info->size) {
+	    (void *)array_info == desc_array + array_info->size &&
+	    BITS_TO_LONGS(array_info->gdev->ngpio) <= BITS_TO_LONGS(array_size)) {
 		if (!can_sleep)
 			WARN_ON(array_info->gdev->can_sleep);
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (4 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Linus Walleij, Bartosz Golaszewski, Asmaa Mnebhi, linux-gpio
  Cc: linux-kernel, stable

struct mlxbf2_gpio_context declares csave_regs as a pointer that is
never allocated during probe.  Both mlxbf2_gpio_suspend() and
mlxbf2_gpio_resume() unconditionally dereference gs->csave_regs,
causing a NULL pointer dereference on system suspend.

Embed struct mlxbf2_gpio_context_save_regs directly inside struct
mlxbf2_gpio_context.

Fixes: bc0ae0e737f5 ("gpio: add driver for Mellanox BlueField 2 GPIO controller")
Closes: https://sashiko.dev/#/bug/linux-a27fa304-ac63-43b1-94b8-0b30e7a2e1bc
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-mlxbf2.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c
index ed724d544c03..534ad29be19e 100644
--- a/drivers/gpio/gpio-mlxbf2.c
+++ b/drivers/gpio/gpio-mlxbf2.c
@@ -72,7 +72,7 @@ struct mlxbf2_gpio_context {
 	void __iomem *gpio_io;
 	struct device *dev;
 
-	struct mlxbf2_gpio_context_save_regs *csave_regs;
+	struct mlxbf2_gpio_context_save_regs csave_regs;
 };
 
 /* BlueField-2 gpio shared structure. */
@@ -440,10 +440,8 @@ static int mlxbf2_gpio_suspend(struct device *dev)
 {
 	struct mlxbf2_gpio_context *gs = dev_get_drvdata(dev);
 
-	gs->csave_regs->gpio_mode0 = readl(gs->gpio_io +
-		YU_GPIO_MODE0);
-	gs->csave_regs->gpio_mode1 = readl(gs->gpio_io +
-		YU_GPIO_MODE1);
+	gs->csave_regs.gpio_mode0 = readl(gs->gpio_io + YU_GPIO_MODE0);
+	gs->csave_regs.gpio_mode1 = readl(gs->gpio_io + YU_GPIO_MODE1);
 
 	return 0;
 }
@@ -452,10 +450,8 @@ static int mlxbf2_gpio_resume(struct device *dev)
 {
 	struct mlxbf2_gpio_context *gs = dev_get_drvdata(dev);
 
-	writel(gs->csave_regs->gpio_mode0, gs->gpio_io +
-		YU_GPIO_MODE0);
-	writel(gs->csave_regs->gpio_mode1, gs->gpio_io +
-		YU_GPIO_MODE1);
+	writel(gs->csave_regs.gpio_mode0, gs->gpio_io + YU_GPIO_MODE0);
+	writel(gs->csave_regs.gpio_mode1, gs->gpio_io + YU_GPIO_MODE1);
 
 	return 0;
 }
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (5 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Michael Walle, Linus Walleij, Bartosz Golaszewski,
	Andy Shevchenko, Mathieu Dubois-Briand, linux-gpio
  Cc: linux-kernel, stable

When a caller leaves config->ngpio as 0 so gpiochip_get_ngpios() reads
chip->ngpio from firmware and also leaves config->ngpio_per_reg as 0,
gpio_regmap_register() falls back to setting gpio->ngpio_per_reg from
config->ngpio (0) instead of chip->ngpio.  Subsequent calls to
gpio_regmap_simple_xlate() divide by zero.

Use chip->ngpio as the default value for gpio->ngpio_per_reg.

Fixes: db305161880a ("gpio: regmap: Allow ngpio to be read from the property")
Closes: https://sashiko.dev/#/bug/linux-85577bd9-c441-47ec-b415-cd40acf50e01
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index ac6ad56f4479..65e87177baf0 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -523,7 +523,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	/* if not set, assume there is only one register */
 	gpio->ngpio_per_reg = config->ngpio_per_reg;
 	if (!gpio->ngpio_per_reg)
-		gpio->ngpio_per_reg = config->ngpio;
+		gpio->ngpio_per_reg = chip->ngpio;
 
 	/* if not set, assume they are consecutive */
 	gpio->reg_stride = config->reg_stride;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (6 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 21:17   ` sashiko-bot
  2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
  2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones
  9 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Linus Walleij, Bartosz Golaszewski, Guangshuo Li,
	Peter Korsgaard, Alex Marginean, Laurentiu Tudor, Song Hui,
	linux-gpio
  Cc: linux-kernel, stable

Commit 698b8eeaed72 ("gpio/mpc8xxx: change irq handler from chained to
normal") switched mpc8xxx_probe() to devm_request_irq() with
IRQF_SHARED, but left mpc8xxx_remove() calling
irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL).  On
unbind, this tears down the shared interrupt descriptor, disrupts other
sharers, and causes devres __free_irq() to warn and skip IRQ
synchronisation.

Remove mpc8xxx_remove(), letting devres LIFO teardown free and
synchronise the shared IRQ before removing the GPIO chip and IRQ
domain.

Fixes: 698b8eeaed72 ("gpio/mpc8xxx: change irq handler from chained to normal")
Closes: https://sashiko.dev/#/bug/linux-0a7973a1-38dd-4b19-9120-a3aa08d02cda
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-mpc8xxx.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 312250deb763..bcc7e2e739e3 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -460,14 +460,6 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void mpc8xxx_remove(struct platform_device *pdev)
-{
-	struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev);
-
-	if (mpc8xxx_gc->irq)
-		irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL);
-}
-
 static int mpc8xxx_suspend(struct device *dev)
 {
 	struct mpc8xxx_gpio_chip *mpc8xxx_gc = dev_get_drvdata(dev);
@@ -501,7 +493,6 @@ MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids);
 
 static struct platform_driver mpc8xxx_plat_driver = {
 	.probe		= mpc8xxx_probe,
-	.remove		= mpc8xxx_remove,
 	.driver		= {
 		.name = "gpio-mpc8xxx",
 		.of_match_table	= mpc8xxx_gpio_ids,
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write()
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (7 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, Linus Walleij, Bartosz Golaszewski, Mary Strodl, linux-gpio
  Cc: linux-kernel, stable

gpio_mpsse_set_bank() and gpio_mpsse_get_bank() pass stack-allocated
buffers to mpsse_write(), which hands them directly to usb_bulk_msg().
Performing USB DMA from the kernel stack triggers warnings and transfer
failures under CONFIG_VMAP_STACK.

Duplicate the caller buffer with kmemdup() in mpsse_write() so
usb_bulk_msg() always receives a DMA-safe heap buffer.

Fixes: c46a74ff05c0 ("gpio: add support for FTDI's MPSSE as GPIO")
Closes: https://sashiko.dev/#/bug/linux-0aa65a1f-4c07-4943-92c9-c25c317b1625
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-mpsse.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c
index 393c537c1d27..be2a8a189010 100644
--- a/drivers/gpio/gpio-mpsse.c
+++ b/drivers/gpio/gpio-mpsse.c
@@ -11,6 +11,7 @@
 #include <linux/gpio/driver.h>
 #include <linux/mutex.h>
 #include <linux/rcupdate.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/usb.h>
 
@@ -126,18 +127,19 @@ static int mpsse_bulk_xfer(struct usb_interface *intf, struct bulk_desc *desc)
 static int mpsse_write(struct usb_interface *intf,
 		       u8 *buf, size_t len)
 {
-	int ret;
+	u8 *tx_buf __free(kfree) = kmemdup(buf, len, GFP_KERNEL);
 	struct bulk_desc desc;
 
+	if (!tx_buf)
+		return -ENOMEM;
+
 	desc.len_actual = 0;
 	desc.tx = true;
-	desc.data = buf;
+	desc.data = tx_buf;
 	desc.len = len;
 	desc.timeout = MPSSE_WRITE_TIMEOUT;
 
-	ret = mpsse_bulk_xfer(intf, &desc);
-
-	return ret;
+	return mpsse_bulk_xfer(intf, &desc);
 }
 
 static int mpsse_read(struct usb_interface *intf, u8 *buf, size_t len)
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition
  2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (8 preceding siblings ...)
  2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
@ 2026-12-03 20:55 ` Lee Jones
  9 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2026-12-03 20:55 UTC (permalink / raw)
  To: lee, William Breathitt Gray, Linus Walleij, Bartosz Golaszewski,
	Breathitt Gray, Michael Walle, linux-gpio
  Cc: linux-kernel, stable

IDIO_24_COS_ENABLE uses bits 0 through 3 for rising-edge IRQ enable
and bits 4 through 7 for falling-edge IRQ enable.  COS_ENABLE_RISING
was mistakenly defined as BIT(1) instead of BIT(0), shifting rising
masks onto bits 1 through 4 and colliding with bank 0's falling-edge
enable bit.

Define COS_ENABLE_RISING as BIT(0).

Fixes: 1a200a396617 ("gpio: pcie-idio-24: Migrate to the regmap API")
Closes: https://sashiko.dev/#/bug/linux-edc9fc3f-4844-4c16-94ba-28edaaa120c9
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-pcie-idio-24.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c
index 55a7f7653982..c9cc0b243fe7 100644
--- a/drivers/gpio/gpio-pcie-idio-24.c
+++ b/drivers/gpio/gpio-pcie-idio-24.c
@@ -71,7 +71,7 @@
 
 #define CONTROL_REG_OUT_MODE BIT(1)
 
-#define COS_ENABLE_RISING BIT(1)
+#define COS_ENABLE_RISING BIT(0)
 #define COS_ENABLE_FALLING BIT(4)
 #define COS_ENABLE_BOTH (COS_ENABLE_RISING | COS_ENABLE_FALLING)
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind
  2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
@ 2026-12-03 21:13   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-03 21:13 UTC (permalink / raw)
  To: Lee Jones, linux-gpio

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gpio: mvebu: unsynchronized chained IRQ teardown on unbind
--

commit 654c33aa50f3c81332c15236e0d1862887658524
Author: Lee Jones <lee@kernel.org>

gpio: mvebu: Clear chained IRQ handlers on unbind

This commit registers a devm cleanup action in mvebu_gpio_probe() to clear
each bank's chained IRQ handler when the device is unbound.

> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 8cb240a46a175..b9e1c4d02f579 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -1182,6 +1182,17 @@ static void mvebu_gpio_remove_irq_domain(void *data)
>  	irq_domain_remove(domain);
>  }
>  
> +static void mvebu_gpio_remove_chained_handlers(void *data)
> +{
> +	struct mvebu_gpio_chip *mvchip = data;
> +
> +	for (unsigned int i = 0; i < ARRAY_SIZE(mvchip->bank_irq); i++) {
> +		if (mvchip->bank_irq[i] > 0)
> +			irq_set_chained_handler_and_data(mvchip->bank_irq[i],
> +							 NULL, NULL);
> +	}
> +}
> +
>  static int mvebu_gpio_probe(struct platform_device *pdev)
>  {
>  	struct mvebu_gpio_chip *mvchip;

[Severity: Medium]
Can unbinding the device still use-after-free mvchip, its regmaps, and
mvchip->domain if a GPIO bank interrupt is already running on another CPU?

irq_set_chained_handler_and_data() clears handler_data, masks the IRQ, and
installs handle_bad_irq under desc->lock, then returns without waiting for
an in-flight chained handler.  Chained flow handlers run in hardirq context
without holding desc->lock or setting IRQD_IRQ_INPROGRESS:

CPU0                                 CPU1
                                     mvebu_gpio_irq_handler()
                                       mvchip = irq_desc_get_handler_data()
mvebu_gpio_remove_chained_handlers()
  irq_set_chained_handler_and_data()
mvebu_gpio_remove_irq_domain()
... (devres frees regmaps, mvchip)
                                       regmap_read(mvchip->regs, ...)
                                         <-- use-after-free

This also leaves the GPIO interrupt mask registers enabled.  On parent
controllers without irq_eoi, such as Armada XP's mpic_irq_chip, an
in-flight handler's chained_irq_exit() calls chip->irq_unmask() after
teardown masked the bank IRQ, leaving it unmasked with handle_bad_irq.

Because chained handlers do not set IRQD_IRQ_INPROGRESS and mpic_irq_chip
lacks irq_get_irqchip_state, synchronize_irq() alone is not enough.  Mask
the GPIO interrupts, detach the handlers, wait for in-flight hardirqs
(e.g. synchronize_rcu()), and ensure parent IRQs stay masked before freeing.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203205606.3905705-1-lee@kernel.org?part=3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler
  2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
@ 2026-12-03 21:17   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-03 21:17 UTC (permalink / raw)
  To: Lee Jones, linux-gpio

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] gpio: mpc8xxx: shared parent IRQ freed before GPIO_IMR is
  masked on unbind
--

commit d9a4fe4701d225631d57b747b098abd12372ac63
Author: Lee Jones <lee@kernel.org>

gpio: mpc8xxx: Drop stale remove callback clearing chained handler

This commit removes mpc8xxx_remove() so that unbinding the driver relies on
devres LIFO teardown instead of clearing the parent interrupt's chained
handler.

> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 54ac69f96628e..cd1c03679cc51 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -461,14 +461,6 @@ static int mpc8xxx_probe(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -static void mpc8xxx_remove(struct platform_device *pdev)
> -{
> -	struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev);
> -
> -	if (mpc8xxx_gc->irq)
> -		irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL);
> -}
> -
>  static int mpc8xxx_suspend(struct device *dev)
>  {
>  	struct mpc8xxx_gpio_chip *mpc8xxx_gc = dev_get_drvdata(dev);

[Severity: High]
Can devres LIFO teardown now free the shared parent IRQ while GPIO_IMR still
has active interrupts enabled?

In mpc8xxx_probe(), devm_gpiochip_add_data() is registered before
devm_request_irq() with IRQF_SHARED.  On unbind, devres runs free_irq()
before gpiochip_remove() clears GPIO_IMR via gpiochip_free_remaining_irqs(),
violating the free_irq() requirement to mask shared interrupts first.

When a sibling controller shares the level-high parent IRQ (such as gpio1
and gpio2 on LS1028A), __free_irq() leaves the line enabled across two
synchronize_srcu() grace periods in gpiochip_remove().  If a GPIO line fires
in that window, it stays asserted with no handler left to ack GPIO_IER.

Because the sibling's mpc8xxx_gpio_irq_cascade() unconditionally returns
IRQ_HANDLED, note_interrupt() never throttles the storm, trapping the CPU in
a hardirq loop that can stall synchronize_srcu() and livelock unbind.

Registering devm_request_irq() (or a devm action that masks GPIO_IMR) before
devm_gpiochip_add_data() would ensure hardware interrupts are masked before
free_irq() detaches from the shared parent IRQ.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203205606.3905705-1-lee@kernel.org?part=8

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-03 21:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
2026-12-03 20:55 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Lee Jones
2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
2026-12-03 21:13   ` sashiko-bot
2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
2026-12-03 20:55 ` [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath Lee Jones
2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
2026-12-03 21:17   ` sashiko-bot
2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox