Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pinctrl: mediatek: eint: Fix invalid pointer dereference for v1 platforms

Commit 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for multiple
addresses") introduced an access to the 'soc' field of struct
mtk_pinctrl in mtk_eint_do_init() and for that an include of
pinctrl-mtk-common-v2.h.

However, pinctrl drivers relying on the v1 common driver include
pinctrl-mtk-common.h instead, which provides another definition of
struct mtk_pinctrl that does not contain an 'soc' field.

Since mtk_eint_do_init() can be called both by v1 and v2 drivers, it
will now try to dereference an invalid pointer when called on v1
platforms. This has been observed on Genio 350 EVK (MT8365), which
crashes very early in boot (the kernel trace can only be seen with
earlycon).

In order to fix this, since 'struct mtk_pinctrl' was only needed to get
a 'struct mtk_eint_pin', make 'struct mtk_eint_pin' a parameter
of mtk_eint_do_init() so that callers need to supply it, removing
mtk_eint_do_init()'s dependency on any particular 'struct mtk_pinctrl'.

Fixes: 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for multiple addresses")
Suggested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Link: https://lore.kernel.org/20250520-genio-350-eint-null-ptr-deref-fix-v2-1-6a3ca966a7ba@collabora.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Nícolas F. R. A. Prado and committed by
Linus Walleij
1c9977b2 a660d9e8

+16 -19
+11 -15
drivers/pinctrl/mediatek/mtk-eint.c
··· 22 22 #include <linux/platform_device.h> 23 23 24 24 #include "mtk-eint.h" 25 - #include "pinctrl-mtk-common-v2.h" 26 25 27 26 #define MTK_EINT_EDGE_SENSITIVE 0 28 27 #define MTK_EINT_LEVEL_SENSITIVE 1 ··· 504 505 } 505 506 EXPORT_SYMBOL_GPL(mtk_eint_find_irq); 506 507 507 - int mtk_eint_do_init(struct mtk_eint *eint) 508 + int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin) 508 509 { 509 510 unsigned int size, i, port, virq, inst = 0; 510 - struct mtk_pinctrl *hw = (struct mtk_pinctrl *)eint->pctl; 511 511 512 512 /* If clients don't assign a specific regs, let's use generic one */ 513 513 if (!eint->regs) ··· 517 519 if (!eint->base_pin_num) 518 520 return -ENOMEM; 519 521 520 - if (eint->nbase == 1) { 522 + if (eint_pin) { 523 + eint->pins = eint_pin; 524 + for (i = 0; i < eint->hw->ap_num; i++) { 525 + inst = eint->pins[i].instance; 526 + if (inst >= eint->nbase) 527 + continue; 528 + eint->base_pin_num[inst]++; 529 + } 530 + } else { 521 531 size = eint->hw->ap_num * sizeof(struct mtk_eint_pin); 522 532 eint->pins = devm_kmalloc(eint->dev, size, GFP_KERNEL); 523 533 if (!eint->pins) ··· 536 530 eint->pins[i].instance = inst; 537 531 eint->pins[i].index = i; 538 532 eint->pins[i].debounce = (i < eint->hw->db_cnt) ? 1 : 0; 539 - } 540 - } 541 - 542 - if (hw && hw->soc && hw->soc->eint_pin) { 543 - eint->pins = hw->soc->eint_pin; 544 - for (i = 0; i < eint->hw->ap_num; i++) { 545 - inst = eint->pins[i].instance; 546 - if (inst >= eint->nbase) 547 - continue; 548 - eint->base_pin_num[inst]++; 549 533 } 550 534 } 551 535 ··· 606 610 err_wake_mask: 607 611 devm_kfree(eint->dev, eint->pin_list); 608 612 err_pin_list: 609 - if (eint->nbase == 1) 613 + if (!eint_pin) 610 614 devm_kfree(eint->dev, eint->pins); 611 615 err_pins: 612 616 devm_kfree(eint->dev, eint->base_pin_num);
+3 -2
drivers/pinctrl/mediatek/mtk-eint.h
··· 88 88 }; 89 89 90 90 #if IS_ENABLED(CONFIG_EINT_MTK) 91 - int mtk_eint_do_init(struct mtk_eint *eint); 91 + int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin); 92 92 int mtk_eint_do_suspend(struct mtk_eint *eint); 93 93 int mtk_eint_do_resume(struct mtk_eint *eint); 94 94 int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n, ··· 96 96 int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n); 97 97 98 98 #else 99 - static inline int mtk_eint_do_init(struct mtk_eint *eint) 99 + static inline int mtk_eint_do_init(struct mtk_eint *eint, 100 + struct mtk_eint_pin *eint_pin) 100 101 { 101 102 return -EOPNOTSUPP; 102 103 }
+1 -1
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
··· 419 419 hw->eint->pctl = hw; 420 420 hw->eint->gpio_xlate = &mtk_eint_xt; 421 421 422 - ret = mtk_eint_do_init(hw->eint); 422 + ret = mtk_eint_do_init(hw->eint, hw->soc->eint_pin); 423 423 if (ret) 424 424 goto err_free_eint; 425 425
+1 -1
drivers/pinctrl/mediatek/pinctrl-mtk-common.c
··· 1038 1038 pctl->eint->pctl = pctl; 1039 1039 pctl->eint->gpio_xlate = &mtk_eint_xt; 1040 1040 1041 - return mtk_eint_do_init(pctl->eint); 1041 + return mtk_eint_do_init(pctl->eint, NULL); 1042 1042 } 1043 1043 1044 1044 /* This is used as a common probe function */