mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pinctrl: mediatek: Fix eint->base allocation type
@ 2026-09-17 21:13 Kees Cook
  0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2026-09-17 21:13 UTC (permalink / raw)
  To: Sean Wang
  Cc: Kees Cook, Kees Cook, Linus Walleij, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-mediatek, linux-gpio,
	linux-arm-kernel, linux-kernel, linux-hardening

From: Kees Cook <kees+treewide@kernel.org>

In preparation for making the devm_kmalloc family of allocators type
aware, we need to make sure that the returned type from the allocation
matches the type of the variable being assigned. (Before, the allocator
would always return "void *", which can be implicitly cast to any
pointer type.)

This allocates the single-entry array that mtk-eint expects (nbase is
set to 1). The assigned type is "void __iomem **", but the converted
allocation type would be "void __iomem ***", as the size was taken from
"pctl->eint->base" itself rather than from what it points at. Luckily
"void __iomem **" and "void __iomem *" are the same size. Take the size
from the pointed-at type to match the assignment.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
drivers/pinctrl/mediatek/pinctrl-mtk-common.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
---
Cc: Sean Wang <sean.wang@kernel.org>
Cc: Linus Walleij <linusw@kernel.org>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: <linux-mediatek@lists.infradead.org>
Cc: <linux-gpio@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
---
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index 1a977acd6883..857d39f3438d 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -1032,7 +1032,8 @@ static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev)
 
 	pctl->eint->nbase = 1;
 	/* mtk-eint expects an array */
-	pctl->eint->base = devm_kzalloc(pctl->dev, sizeof(pctl->eint->base), GFP_KERNEL);
+	pctl->eint->base = devm_kzalloc(pctl->dev, sizeof(*pctl->eint->base),
+					GFP_KERNEL);
 	if (!pctl->eint->base)
 		return -ENOMEM;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-17 21:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 21:13 [PATCH] pinctrl: mediatek: Fix eint->base allocation type Kees Cook

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

all inboxes | Powered by JetHome®