pinctrl: mediatek: Fix eint->base allocation type
Subsystems (4)
PATCH 1/1 pinctrl: mediatek: Fix eint->base allocation type
From: Kees Cook <[email protected]>
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
---
Cc: Sean Wang <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
--- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +2 -1
@@ -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 ;
Signature · 1 line
2.34.1
Linus Walleij
maintainerQuoted 15 lines · Kees Cook
From: Kees Cook <[email protected]>
In preparation for making the
devm_kmallocfamily 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.
Quoted 5 lines
Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
drivers/pinctrl/mediatek/pinctrl-mtk-common.oAssisted-by LLM coccinelleSigned-off-by Kees Cook <[email protected]>
Patch applied!
Yours,
Linus Walleij