[PATCH 3/4] pinctrl: qcom: sc8180x: use kcalloc() instead of kzalloc()

Qianfeng Rong posted 4 patches 1 month, 2 weeks ago
[PATCH 3/4] pinctrl: qcom: sc8180x: use kcalloc() instead of kzalloc()
Posted by Qianfeng Rong 1 month, 2 weeks ago
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
Re: [PATCH 3/4] pinctrl: qcom: sc8180x: use kcalloc() instead of kzalloc()
Posted by Dmitry Baryshkov 1 month, 2 weeks ago
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