Skip to contentSkip to conversation

pinctrl: mediatek: common-v2: Fix of_iomap() error check

PATCH In review Saad Anjum 2 participants 2 messages Oct 5 – Nov 4

Subsystems (4)
lore
Share & tools
lore

Saad Anjum

author
#0 lore raw

PATCH 1/1 pinctrl: mediatek: common-v2: Fix of_iomap() error check

of_iomap() returns NULL on failure, never an error pointer, so the IS_ERR() check in mtk_build_eint() can never be true. The check was carried over from the previous devm_platform_ioremap_resource_byname() call, which does return an error pointer, when the EINT registers were switched to being mapped with of_iomap() to support multiple bases.

If mapping one of the EINT register ranges fails, for example because the device tree node lists more "reg-names" than "reg" entries so that of_address_to_resource() fails, or because ioremap() itself fails, the NULL pointer is stored in hw->eint->base[] and probing continues. mtk_eint_do_init() then calls mtk_eint_hw_init(), which writes to eint->base[i] + regs->dom_en, causing a NULL pointer dereference instead of a clean probe failure.

Check for NULL and return -ENOMEM instead. The existing error path already skips NULL entries when unmapping, so any ranges mapped before the failure are still released.

Fixes 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for multiple addresses")
---
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +2 -2
index faa6dbf0f..bf9d20b59 100644
@@ -398,8 +398,8 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
 
 	for (i = hw->soc->nbase_names, j = 0; i < count_reg_names; i++, j++) {
 		hw->eint->base[j] = of_iomap(np, i);
-		if (IS_ERR(hw->eint->base[j])) {
-			ret = PTR_ERR(hw->eint->base[j]);
+		if (!hw->eint->base[j]) {
+			ret = -ENOMEM;
 			goto err_free_eint;
 		}
 	}

base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a

Signature · 1 line
2.50.1 (Apple Git-155)
maintainer
#1 lore raw
Quoted 14 lines · Saad Anjum

of_iomap() returns NULL on failure, never an error pointer, so the IS_ERR() check in mtk_build_eint() can never be true. The check was carried over from the previous devm_platform_ioremap_resource_byname() call, which does return an error pointer, when the EINT registers were switched to being mapped with of_iomap() to support multiple bases.

If mapping one of the EINT register ranges fails, for example because the device tree node lists more "reg-names" than "reg" entries so that of_address_to_resource() fails, or because ioremap() itself fails, the NULL pointer is stored in hw->eint->base[] and probing continues. mtk_eint_do_init() then calls mtk_eint_hw_init(), which writes to eint->base[i] + regs->dom_en, causing a NULL pointer dereference instead of a clean probe failure.

Quoted 6 lines

Check for NULL and return -ENOMEM instead. The existing error path already skips NULL entries when unmapping, so any ranges mapped before the failure are still released.

Fixes 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for multiple addresses")

Patch applied.

Yours,
Linus Walleij