[PATCH] pinctrl: imx: Remove const from group_names allocation type

Kees Cook kees at kernel.org
Thu Sep 17 14:14:47 PDT 2026


From: Kees Cook <kees+treewide at 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.)

The assigned type is "const char **", but the converted allocation type
would be "const char * const *", as the size was taken from
"*func->groups", whose type "const char * const" is const qualified. As
there is no general way to remove const qualifiers, take the size from
the assignment target instead. No change in allocation size results.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
drivers/pinctrl/freescale/pinctrl-imx.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <kees+treewide at kernel.org>
---
Cc: Dong Aisheng <aisheng.dong at nxp.com>
Cc: Fabio Estevam <festevam at gmail.com>
Cc: Frank Li <Frank.Li at nxp.com>
Cc: Jacky Bai <ping.bai at nxp.com>
Cc: Pengutronix Kernel Team <kernel at pengutronix.de>
Cc: NXP S32 Linux Team <s32 at nxp.com>
Cc: Linus Walleij <linusw at kernel.org>
Cc: Sascha Hauer <s.hauer at pengutronix.de>
Cc: <linux-gpio at vger.kernel.org>
Cc: <imx at lists.linux.dev>
Cc: <linux-arm-kernel at lists.infradead.org>
---
 drivers/pinctrl/freescale/pinctrl-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index 9a45b376d36f..c11d220d982a 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -600,7 +600,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
 	}
 
 	group_names = devm_kcalloc(ipctl->dev, func->ngroups,
-				   sizeof(*func->groups), GFP_KERNEL);
+				   sizeof(*group_names), GFP_KERNEL);
 	if (!group_names)
 		return -ENOMEM;
 	i = 0;
-- 
2.34.1




More information about the linux-arm-kernel mailing list