* [PATCH v2 3/6] pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs
2026-11-19 20:47 [PATCH v2 0/6] pinctrl: Fix out-of-bounds accesses, divide-by-zero, and error handling Lee Jones
@ 2026-11-19 20:47 ` Lee Jones
2026-11-19 23:01 ` Daniel Golle
2026-11-19 20:47 ` [PATCH v2 4/6] pinctrl: mediatek: Guard against NULL eint in mtk_eint_do_suspend() and mtk_eint_do_resume() Lee Jones
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Lee Jones @ 2026-11-19 20:47 UTC (permalink / raw)
To: lee, Sean Wang, Linus Walleij, Matthias Brugger,
AngeloGioacchino Del Regno, Sam Shih, Daniel Golle, Rob Herring,
linux-mediatek, linux-gpio, linux-kernel, linux-arm-kernel
Cc: stable
mt7981_ant_sel_pins[] defines 14 pins (pins 14..25, 34, and 35), all of
which select ANT_SEL at function mux mode 6, but mt7981_ant_sel_funcs[]
only contains 12 entries. When mtk_pinmux_set_mux() iterates over
grp->grp.npins (14), it reads two int elements past the end of
mt7981_ant_sel_funcs[].
Add the two missing mode 6 entries to mt7981_ant_sel_funcs[] so its
length matches mt7981_ant_sel_pins[].
Fixes: 6c83b2d94fcc ("pinctrl: add mt7981 pinctrl driver")
Closes: https://sashiko.dev/#/bug/linux-6233f285-1487-4d2d-afe3-d4ce3c445054
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2: No changes
drivers/pinctrl/mediatek/pinctrl-mt7981.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/mediatek/pinctrl-mt7981.c b/drivers/pinctrl/mediatek/pinctrl-mt7981.c
index 2325cc8b9345..62fec909408b 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mt7981.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mt7981.c
@@ -800,7 +800,7 @@ static int mt7981_mt7531_int_funcs[] = { 1, };
/* ANT_SEL */
static int mt7981_ant_sel_pins[] = { 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 34, 35 };
-static int mt7981_ant_sel_funcs[] = { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 };
+static int mt7981_ant_sel_funcs[] = { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 };
static const struct group_desc mt7981_groups[] = {
/* @GPIO(0,1): WA_AICE(2) */
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2 3/6] pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs
2026-11-19 20:47 ` [PATCH v2 3/6] pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs Lee Jones
@ 2026-11-19 23:01 ` Daniel Golle
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Golle @ 2026-11-19 23:01 UTC (permalink / raw)
To: Lee Jones
Cc: Sean Wang, Linus Walleij, Matthias Brugger,
AngeloGioacchino Del Regno, Sam Shih, Rob Herring, linux-mediatek,
linux-gpio, linux-kernel, linux-arm-kernel, stable
On Thu, Nov 19, 2026 at 08:47:18PM +0000, Lee Jones wrote:
> mt7981_ant_sel_pins[] defines 14 pins (pins 14..25, 34, and 35), all of
> which select ANT_SEL at function mux mode 6, but mt7981_ant_sel_funcs[]
> only contains 12 entries. When mtk_pinmux_set_mux() iterates over
> grp->grp.npins (14), it reads two int elements past the end of
> mt7981_ant_sel_funcs[].
>
> Add the two missing mode 6 entries to mt7981_ant_sel_funcs[] so its
> length matches mt7981_ant_sel_pins[].
>
> Fixes: 6c83b2d94fcc ("pinctrl: add mt7981 pinctrl driver")
> Closes: https://sashiko.dev/#/bug/linux-6233f285-1487-4d2d-afe3-d4ce3c445054
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 4/6] pinctrl: mediatek: Guard against NULL eint in mtk_eint_do_suspend() and mtk_eint_do_resume()
2026-11-19 20:47 [PATCH v2 0/6] pinctrl: Fix out-of-bounds accesses, divide-by-zero, and error handling Lee Jones
2026-11-19 20:47 ` [PATCH v2 3/6] pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs Lee Jones
@ 2026-11-19 20:47 ` Lee Jones
2026-11-19 20:47 ` [PATCH v2 5/6] pinctrl: mediatek: Clean up partially initialised hw->eint on error Lee Jones
2026-11-19 20:47 ` [PATCH v2 6/6] pinctrl: mediatek: Prevent divide-by-zero for pins with fixed drive strength Lee Jones
3 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-11-19 20:47 UTC (permalink / raw)
To: lee, Sean Wang, Linus Walleij, Matthias Brugger,
AngeloGioacchino Del Regno, Maoguang Meng, Hao Chang,
Qingliang Li, Nicolas Boichat, linux-mediatek, linux-gpio,
linux-kernel, linux-arm-kernel
Cc: stable
mtk_paris_pinctrl_probe() treats mtk_build_eint() failure as non-fatal,
logging a warning and completing probe with hw->eint left as NULL
whenever EINT initialisation is skipped or fails. However, the system
sleep callbacks pass pctl->eint unconditionally to
mtk_eint_do_suspend() and mtk_eint_do_resume(), both of which
dereference eint without checking for NULL.
Return 0 early from mtk_eint_do_suspend() and mtk_eint_do_resume() when
eint is NULL.
Fixes: 5c0904488a20 ("pinctrl: mediatek: Add pm_ops to pinctrl-paris")
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2:
- New patch, avoiding a NULL dereference on suspend/resume when EINT
setup fails (Sashiko)
drivers/pinctrl/mediatek/mtk-eint.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c
index 827231dc0d24..ca47a416c666 100644
--- a/drivers/pinctrl/mediatek/mtk-eint.c
+++ b/drivers/pinctrl/mediatek/mtk-eint.c
@@ -427,6 +427,9 @@ static void mtk_eint_irq_handler(struct irq_desc *desc)
int mtk_eint_do_suspend(struct mtk_eint *eint)
{
+ if (!eint)
+ return 0;
+
mtk_eint_chip_write_mask(eint, eint->wake_mask);
return 0;
@@ -435,6 +438,9 @@ EXPORT_SYMBOL_GPL(mtk_eint_do_suspend);
int mtk_eint_do_resume(struct mtk_eint *eint)
{
+ if (!eint)
+ return 0;
+
mtk_eint_chip_write_mask(eint, eint->cur_mask);
return 0;
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 5/6] pinctrl: mediatek: Clean up partially initialised hw->eint on error
2026-11-19 20:47 [PATCH v2 0/6] pinctrl: Fix out-of-bounds accesses, divide-by-zero, and error handling Lee Jones
2026-11-19 20:47 ` [PATCH v2 3/6] pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs Lee Jones
2026-11-19 20:47 ` [PATCH v2 4/6] pinctrl: mediatek: Guard against NULL eint in mtk_eint_do_suspend() and mtk_eint_do_resume() Lee Jones
@ 2026-11-19 20:47 ` Lee Jones
2026-11-19 20:47 ` [PATCH v2 6/6] pinctrl: mediatek: Prevent divide-by-zero for pins with fixed drive strength Lee Jones
3 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-11-19 20:47 UTC (permalink / raw)
To: lee, Sean Wang, Linus Walleij, Matthias Brugger,
AngeloGioacchino Del Regno, Bartosz Golaszewski, Hao Chang,
Qingliang Li, linux-mediatek, linux-gpio, linux-kernel,
linux-arm-kernel
Cc: stable
In mtk_build_eint(), if of_property_count_strings() fails or
hw->eint->nbase is non-positive, the function returns -EINVAL directly
after allocating hw->eint without jumping to err_free_base. Because
callers such as mtk_paris_pinctrl_probe() and mtk_moore_pinctrl_probe()
log a warning and continue probing when mtk_build_eint() fails, leaving
hw->eint non-NULL with hw->eint->domain and hw->eint->hw unset causes
mtk_gpio_to_irq() and mtk_gpio_set_config() to pass the half-initialised
structure into mtk_eint_find_irq() and mtk_eint_set_debounce(),
dereferencing NULL pointers.
Jump to err_free_base on both error paths so hw->eint is freed and
reset to NULL.
Fixes: 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for multiple addresses")
Closes: https://sashiko.dev/#/bug/linux-0689c07e-ef74-4bc2-b5de-bd2f361124bd
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2:
- Clarify the commit message regarding mtk_gpio_to_irq() and
mtk_gpio_set_config(), while handling NULL eint on suspend/resume in
the preceding patch (Sashiko)
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index bf9d20b59213..95d0455f7d53 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -382,12 +382,16 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
return -ENOMEM;
count_reg_names = of_property_count_strings(np, "reg-names");
- if (count_reg_names < 0)
- return -EINVAL;
+ if (count_reg_names < 0) {
+ ret = -EINVAL;
+ goto err_free_base;
+ }
hw->eint->nbase = count_reg_names - (int)hw->soc->nbase_names;
- if (hw->eint->nbase <= 0)
- return -EINVAL;
+ if (hw->eint->nbase <= 0) {
+ ret = -EINVAL;
+ goto err_free_base;
+ }
hw->eint->base = devm_kmalloc_array(&pdev->dev, hw->eint->nbase,
sizeof(*hw->eint->base), GFP_KERNEL | __GFP_ZERO);
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 6/6] pinctrl: mediatek: Prevent divide-by-zero for pins with fixed drive strength
2026-11-19 20:47 [PATCH v2 0/6] pinctrl: Fix out-of-bounds accesses, divide-by-zero, and error handling Lee Jones
` (2 preceding siblings ...)
2026-11-19 20:47 ` [PATCH v2 5/6] pinctrl: mediatek: Clean up partially initialised hw->eint on error Lee Jones
@ 2026-11-19 20:47 ` Lee Jones
3 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-11-19 20:47 UTC (permalink / raw)
To: lee, Sean Wang, Linus Walleij, Matthias Brugger,
AngeloGioacchino Del Regno, Ryder.Lee, linux-mediatek, linux-gpio,
linux-kernel, linux-arm-kernel
Cc: stable
mtk_drive[] only defines entries for DRV_GRP0 (1) through DRV_GRP4 (5),
leaving mtk_drive[DRV_FIXED] (0) zero-initialised with min = 0, max = 0,
step = 0, and scal = 0. If mtk_pinconf_drive_set() or
mtk_pinconf_drive_set_rev1() is called with arg = 0 on a pin with
drv_n == DRV_FIXED, the range check (0 >= 0 && 0 <= 0) succeeds and
!(arg % tb->step) divides by zero. Similarly, mtk_pinconf_drive_get()
and mtk_pinconf_drive_get_rev1() divide by tb->scal (0) if the pin has
drive register fields defined.
Return -ENOTSUPP immediately when desc->drv_n == DRV_FIXED.
Fixes: c28321979ba8 ("pinctrl: mediatek: add driving strength related support to pinctrl-mtk-common-v2.c")
Closes: https://sashiko.dev/#/bug/linux-d3852d37-6806-4c41-a493-f249dd59d0c6
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2: No changes
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 95d0455f7d53..d0c2292a1bbf 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -1040,6 +1040,9 @@ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
const struct mtk_drive_desc *tb;
int err = -ENOTSUPP;
+ if (desc->drv_n == DRV_FIXED)
+ return -ENOTSUPP;
+
tb = &mtk_drive[desc->drv_n];
/* 4mA when (e8, e4) = (0, 0)
* 8mA when (e8, e4) = (0, 1)
@@ -1069,6 +1072,9 @@ int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
const struct mtk_drive_desc *tb;
int err, val1, val2;
+ if (desc->drv_n == DRV_FIXED)
+ return -ENOTSUPP;
+
tb = &mtk_drive[desc->drv_n];
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1);
@@ -1095,6 +1101,9 @@ int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
const struct mtk_drive_desc *tb;
int err = -ENOTSUPP;
+ if (desc->drv_n == DRV_FIXED)
+ return -ENOTSUPP;
+
tb = &mtk_drive[desc->drv_n];
if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
@@ -1116,6 +1125,9 @@ int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
const struct mtk_drive_desc *tb;
int err, val1;
+ if (desc->drv_n == DRV_FIXED)
+ return -ENOTSUPP;
+
tb = &mtk_drive[desc->drv_n];
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1);
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread