Skip to contentSkip to conversation

pinctrl: s32cc: Remove const from groups allocation type

PATCH In review Kees Cook 3 participants 3 messages Sep 17 – Oct 1

Subsystems (4)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 pinctrl: s32cc: Remove const from groups 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.)

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=arm64 allmodconfig with GCC aarch64-linux-gnu 16.1.0:
drivers/pinctrl/nxp/pinctrl-s32cc.o

Assisted-by LLM coccinelle

---
Cc: Chester Lin <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: Ghennadi Procopciuc <[email protected]>
Cc: NXP S32 Linux Team <[email protected]>
Cc: Dong Aisheng <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Frank Li <[email protected]>
Cc: Jacky Bai <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>

---
 drivers/pinctrl/nxp/pinctrl-s32cc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/nxp/pinctrl-s32cc.c +1 -1
index 4b40770a38b7..9c4ebae22674 100644
@@ -825,7 +825,7 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
 				     "No groups defined in %pOF\n", np);
 
 	groups = devm_kcalloc(info->dev, func->ngroups,
-				    sizeof(*func->groups), GFP_KERNEL);
+				    sizeof(*groups), GFP_KERNEL);
 	if (!groups)
 		return -ENOMEM;
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 50 lines · Kees Cook

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.)

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=arm64 allmodconfig with GCC aarch64-linux-gnu 16.1.0:
drivers/pinctrl/nxp/pinctrl-s32cc.o

Assisted-by LLM coccinelle

---
Cc: Chester Lin <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: Ghennadi Procopciuc <[email protected]>
Cc: NXP S32 Linux Team <[email protected]>
Cc: Dong Aisheng <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Frank Li <[email protected]>
Cc: Jacky Bai <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>

---
 drivers/pinctrl/nxp/pinctrl-s32cc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/nxp/pinctrl-s32cc.c +1 -2
index 4b40770a38b7..9c4ebae22674 100644
@@ -825,7 +825,7 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
                                     "No groups defined in %pOF\n", np);
 
        groups = devm_kcalloc(info->dev, func->ngroups,
-                                   sizeof(*func->groups), GFP_KERNEL);
+                                   sizeof(*groups), GFP_KERNEL);
        if (!groups)
                return -ENOMEM;
 
--
Quoted 2 lines

2.34.1

Signature · 2 lines
Regards,
Ghennadi
maintainer
#2 lore raw
In reply to Kees Cook
Quoted 14 lines · Kees Cook

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.)

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.

Quoted 5 lines

Build tested ARCH=arm64 allmodconfig with GCC aarch64-linux-gnu 16.1.0:
drivers/pinctrl/nxp/pinctrl-s32cc.o

Assisted-by LLM coccinelle

Patch applied!

Yours,
Linus Walleij