* [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc()
@ 2025-08-19 14:39 Qianfeng Rong
2025-08-19 14:39 ` [PATCH 1/4] pinctrl: microchip-sgpio: " Qianfeng Rong
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Qianfeng Rong @ 2025-08-19 14:39 UTC (permalink / raw)
To: Steen Hegelund, Daniel Machon,
maintainer:ARM/Microchip Sparx5 SoC support, Linus Walleij,
Michal Simek, Bjorn Andersson, Chen-Yu Tsai, Jernej Skrabec,
Samuel Holland, moderated list:ARM/Microchip Sparx5 SoC support,
open list:PIN CONTROL SUBSYSTEM, open list,
open list:ARM/QUALCOMM MAILING LIST,
open list:ARM/Allwinner sunXi SoC support
Cc: Qianfeng Rong
Replace devm_kzalloc() with devm_kcalloc() in drivers/pinctrl. As noted
in the kernel documentation [1], open-coded multiplication in allocator
arguments is discouraged because it can lead to integer overflow.
Use devm_kcalloc() to gain built-in overflow protection, making memory
allocation safer when calculating allocation size compared to explicit
multiplication.
[1]: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Qianfeng Rong (4):
pinctrl: microchip-sgpio: use kcalloc() instead of kzalloc()
pinctrl: pinctrl-zynqmp: use kcalloc() instead of kzalloc()
pinctrl: qcom: sc8180x: use kcalloc() instead of kzalloc()
pinctrl: sunxi: use kcalloc() instead of kzalloc()
drivers/pinctrl/pinctrl-microchip-sgpio.c | 2 +-
drivers/pinctrl/pinctrl-zynqmp.c | 2 +-
drivers/pinctrl/qcom/pinctrl-sc8180x.c | 2 +-
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/4] pinctrl: microchip-sgpio: use kcalloc() instead of kzalloc()
2025-08-19 14:39 [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc() Qianfeng Rong
@ 2025-08-19 14:39 ` Qianfeng Rong
2025-08-19 14:39 ` [PATCH 2/4] pinctrl: pinctrl-zynqmp: " Qianfeng Rong
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Qianfeng Rong @ 2025-08-19 14:39 UTC (permalink / raw)
To: Steen Hegelund, Daniel Machon,
maintainer:ARM/Microchip Sparx5 SoC support, Linus Walleij,
moderated list:ARM/Microchip Sparx5 SoC support,
open list:PIN CONTROL SUBSYSTEM, open list
Cc: Qianfeng Rong
Use devm_kcalloc() in microchip_sgpio_register_bank() to gain built-in
overflow protection, making memory allocation safer when calculating
allocation size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/pinctrl/pinctrl-microchip-sgpio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
index 6191e5c13815..069cc665a402 100644
--- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
+++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
@@ -824,7 +824,7 @@ static int microchip_sgpio_register_bank(struct device *dev,
pctl_desc->confops = &sgpio_confops;
pctl_desc->owner = THIS_MODULE;
- pins = devm_kzalloc(dev, sizeof(*pins)*ngpios, GFP_KERNEL);
+ pins = devm_kcalloc(dev, ngpios, sizeof(*pins), GFP_KERNEL);
if (!pins)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/4] pinctrl: pinctrl-zynqmp: use kcalloc() instead of kzalloc()
2025-08-19 14:39 [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-19 14:39 ` [PATCH 1/4] pinctrl: microchip-sgpio: " Qianfeng Rong
@ 2025-08-19 14:39 ` Qianfeng Rong
2025-08-20 8:02 ` Michal Simek
2025-08-19 14:39 ` [PATCH 3/4] pinctrl: qcom: sc8180x: " Qianfeng Rong
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Qianfeng Rong @ 2025-08-19 14:39 UTC (permalink / raw)
To: Linus Walleij, Michal Simek, open list:PIN CONTROL SUBSYSTEM,
moderated list:ARM/ZYNQ ARCHITECTURE, open list
Cc: Qianfeng Rong
Use devm_kcalloc() in versal_pinctrl_prepare_pin_desc() to gain built-in
overflow protection, making memory allocation safer when calculating
allocation size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/pinctrl/pinctrl-zynqmp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
index 71eaac81deb1..aba129ead04c 100644
--- a/drivers/pinctrl/pinctrl-zynqmp.c
+++ b/drivers/pinctrl/pinctrl-zynqmp.c
@@ -918,7 +918,7 @@ static int versal_pinctrl_prepare_pin_desc(struct device *dev,
if (ret)
return ret;
- pins = devm_kzalloc(dev, sizeof(*pins) * *npins, GFP_KERNEL);
+ pins = devm_kcalloc(dev, *npins, sizeof(*pins), GFP_KERNEL);
if (!pins)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] pinctrl: qcom: sc8180x: use kcalloc() instead of kzalloc()
2025-08-19 14:39 [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-19 14:39 ` [PATCH 1/4] pinctrl: microchip-sgpio: " Qianfeng Rong
2025-08-19 14:39 ` [PATCH 2/4] pinctrl: pinctrl-zynqmp: " Qianfeng Rong
@ 2025-08-19 14:39 ` Qianfeng Rong
2025-08-19 18:37 ` Dmitry Baryshkov
2025-08-19 14:39 ` [PATCH 4/4] pinctrl: sunxi: " Qianfeng Rong
2025-08-21 11:29 ` [PATCH 0/4] pinctrl: " Linus Walleij
4 siblings, 1 reply; 9+ messages in thread
From: Qianfeng Rong @ 2025-08-19 14:39 UTC (permalink / raw)
To: Bjorn Andersson, Linus Walleij,
open list:ARM/QUALCOMM MAILING LIST,
open list:PIN CONTROL SUBSYSTEM, open list
Cc: Qianfeng Rong
Use devm_kcalloc() in sc8180x_pinctrl_add_tile_resources() to gain built-in
overflow protection, making memory allocation safer when calculating
allocation size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/pinctrl/qcom/pinctrl-sc8180x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/qcom/pinctrl-sc8180x.c b/drivers/pinctrl/qcom/pinctrl-sc8180x.c
index 26dd165d1543..ae5134fdebd9 100644
--- a/drivers/pinctrl/qcom/pinctrl-sc8180x.c
+++ b/drivers/pinctrl/qcom/pinctrl-sc8180x.c
@@ -1634,7 +1634,7 @@ static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev)
return 0;
/* Allocate for new resources */
- nres = devm_kzalloc(&pdev->dev, sizeof(*nres) * nres_num, GFP_KERNEL);
+ nres = devm_kcalloc(&pdev->dev, nres_num, sizeof(*nres), GFP_KERNEL);
if (!nres)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] pinctrl: sunxi: use kcalloc() instead of kzalloc()
2025-08-19 14:39 [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc() Qianfeng Rong
` (2 preceding siblings ...)
2025-08-19 14:39 ` [PATCH 3/4] pinctrl: qcom: sc8180x: " Qianfeng Rong
@ 2025-08-19 14:39 ` Qianfeng Rong
2025-08-20 13:17 ` Chen-Yu Tsai
2025-08-21 11:29 ` [PATCH 0/4] pinctrl: " Linus Walleij
4 siblings, 1 reply; 9+ messages in thread
From: Qianfeng Rong @ 2025-08-19 14:39 UTC (permalink / raw)
To: Linus Walleij, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
open list:PIN CONTROL SUBSYSTEM,
moderated list:ARM/Allwinner sunXi SoC support,
open list:ARM/Allwinner sunXi SoC support, open list
Cc: Qianfeng Rong
Use devm_kcalloc() in init_pins_table() and prepare_function_table() to
gain built-in overflow protection, making memory allocation safer when
calculating allocation size compared to explicit multiplication.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
index 4e34b0cd3b73..5f13315ebff3 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
@@ -103,7 +103,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
return ERR_PTR(-EINVAL);
}
- pins = devm_kzalloc(dev, desc->npins * sizeof(*pins), GFP_KERNEL);
+ pins = devm_kcalloc(dev, desc->npins, sizeof(*pins), GFP_KERNEL);
if (!pins)
return ERR_PTR(-ENOMEM);
@@ -199,7 +199,7 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,
* Allocate the memory needed for the functions in one table.
* We later use pointers into this table to mark each pin.
*/
- func = devm_kzalloc(dev, num_funcs * sizeof(*func), GFP_KERNEL);
+ func = devm_kcalloc(dev, num_funcs, sizeof(*func), GFP_KERNEL);
if (!func)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] pinctrl: qcom: sc8180x: use kcalloc() instead of kzalloc()
2025-08-19 14:39 ` [PATCH 3/4] pinctrl: qcom: sc8180x: " Qianfeng Rong
@ 2025-08-19 18:37 ` Dmitry Baryshkov
0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Baryshkov @ 2025-08-19 18:37 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Bjorn Andersson, Linus Walleij,
open list:ARM/QUALCOMM MAILING LIST,
open list:PIN CONTROL SUBSYSTEM, open list
On Tue, Aug 19, 2025 at 10:39:34PM +0800, Qianfeng Rong wrote:
> Use devm_kcalloc() in sc8180x_pinctrl_add_tile_resources() to gain built-in
> overflow protection, making memory allocation safer when calculating
> allocation size compared to explicit multiplication.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> drivers/pinctrl/qcom/pinctrl-sc8180x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/4] pinctrl: pinctrl-zynqmp: use kcalloc() instead of kzalloc()
2025-08-19 14:39 ` [PATCH 2/4] pinctrl: pinctrl-zynqmp: " Qianfeng Rong
@ 2025-08-20 8:02 ` Michal Simek
0 siblings, 0 replies; 9+ messages in thread
From: Michal Simek @ 2025-08-20 8:02 UTC (permalink / raw)
To: Qianfeng Rong, Linus Walleij, open list:PIN CONTROL SUBSYSTEM,
moderated list:ARM/ZYNQ ARCHITECTURE, open list
On 8/19/25 16:39, Qianfeng Rong wrote:
> Use devm_kcalloc() in versal_pinctrl_prepare_pin_desc() to gain built-in
> overflow protection, making memory allocation safer when calculating
> allocation size compared to explicit multiplication.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> drivers/pinctrl/pinctrl-zynqmp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
> index 71eaac81deb1..aba129ead04c 100644
> --- a/drivers/pinctrl/pinctrl-zynqmp.c
> +++ b/drivers/pinctrl/pinctrl-zynqmp.c
> @@ -918,7 +918,7 @@ static int versal_pinctrl_prepare_pin_desc(struct device *dev,
> if (ret)
> return ret;
>
> - pins = devm_kzalloc(dev, sizeof(*pins) * *npins, GFP_KERNEL);
> + pins = devm_kcalloc(dev, *npins, sizeof(*pins), GFP_KERNEL);
> if (!pins)
> return -ENOMEM;
>
Acked-by: Michal Simek <michal.simek@amd.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] pinctrl: sunxi: use kcalloc() instead of kzalloc()
2025-08-19 14:39 ` [PATCH 4/4] pinctrl: sunxi: " Qianfeng Rong
@ 2025-08-20 13:17 ` Chen-Yu Tsai
0 siblings, 0 replies; 9+ messages in thread
From: Chen-Yu Tsai @ 2025-08-20 13:17 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Linus Walleij, Jernej Skrabec, Samuel Holland,
open list:PIN CONTROL SUBSYSTEM,
moderated list:ARM/Allwinner sunXi SoC support,
open list:ARM/Allwinner sunXi SoC support, open list
On Tue, Aug 19, 2025 at 10:40 PM Qianfeng Rong <rongqianfeng@vivo.com> wrote:
>
> Use devm_kcalloc() in init_pins_table() and prepare_function_table() to
> gain built-in overflow protection, making memory allocation safer when
> calculating allocation size compared to explicit multiplication.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Acked-by: Chen-Yu Tsai <wens@csie.org>
> ---
> drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
> index 4e34b0cd3b73..5f13315ebff3 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
> @@ -103,7 +103,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
> return ERR_PTR(-EINVAL);
> }
>
> - pins = devm_kzalloc(dev, desc->npins * sizeof(*pins), GFP_KERNEL);
> + pins = devm_kcalloc(dev, desc->npins, sizeof(*pins), GFP_KERNEL);
> if (!pins)
> return ERR_PTR(-ENOMEM);
>
> @@ -199,7 +199,7 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,
> * Allocate the memory needed for the functions in one table.
> * We later use pointers into this table to mark each pin.
> */
> - func = devm_kzalloc(dev, num_funcs * sizeof(*func), GFP_KERNEL);
> + func = devm_kcalloc(dev, num_funcs, sizeof(*func), GFP_KERNEL);
> if (!func)
> return -ENOMEM;
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc()
2025-08-19 14:39 [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc() Qianfeng Rong
` (3 preceding siblings ...)
2025-08-19 14:39 ` [PATCH 4/4] pinctrl: sunxi: " Qianfeng Rong
@ 2025-08-21 11:29 ` Linus Walleij
4 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2025-08-21 11:29 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Steen Hegelund, Daniel Machon,
maintainer:ARM/Microchip Sparx5 SoC support, Michal Simek,
Bjorn Andersson, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
moderated list:ARM/Microchip Sparx5 SoC support,
open list:PIN CONTROL SUBSYSTEM, open list,
open list:ARM/QUALCOMM MAILING LIST,
open list:ARM/Allwinner sunXi SoC support
On Tue, Aug 19, 2025 at 4:39 PM Qianfeng Rong <rongqianfeng@vivo.com> wrote:
> Replace devm_kzalloc() with devm_kcalloc() in drivers/pinctrl. As noted
> in the kernel documentation [1], open-coded multiplication in allocator
> arguments is discouraged because it can lead to integer overflow.
>
> Use devm_kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication.
All patches applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-08-21 11:29 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 14:39 [PATCH 0/4] pinctrl: use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-19 14:39 ` [PATCH 1/4] pinctrl: microchip-sgpio: " Qianfeng Rong
2025-08-19 14:39 ` [PATCH 2/4] pinctrl: pinctrl-zynqmp: " Qianfeng Rong
2025-08-20 8:02 ` Michal Simek
2025-08-19 14:39 ` [PATCH 3/4] pinctrl: qcom: sc8180x: " Qianfeng Rong
2025-08-19 18:37 ` Dmitry Baryshkov
2025-08-19 14:39 ` [PATCH 4/4] pinctrl: sunxi: " Qianfeng Rong
2025-08-20 13:17 ` Chen-Yu Tsai
2025-08-21 11:29 ` [PATCH 0/4] pinctrl: " Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).