mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] PCI: keystone: Use kcalloc() instead of kzalloc()
@ 2025-08-19  8:59 Qianfeng Rong
  2025-08-19  9:49 ` Siddharth Vadapalli
  0 siblings, 1 reply; 3+ messages in thread
From: Qianfeng Rong @ 2025-08-19  8:59 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński,
	Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Niklas Cassel,
	Kishon Vijay Abraham I, Siddharth Vadapalli, Sergio Paracuellos,
	Hans Zhang, Jiri Slaby (SUSE),
	linux-pci, linux-kernel
  Cc: Qianfeng Rong

Replace calls of devm_kzalloc() with devm_kcalloc() in ks_pcie_probe() for
safer memory allocation with built-in overflow protection.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/pci/controller/dwc/pci-keystone.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
index 7d7aede54ed3..3d10e1112131 100644
--- a/drivers/pci/controller/dwc/pci-keystone.c
+++ b/drivers/pci/controller/dwc/pci-keystone.c
@@ -1212,11 +1212,11 @@ static int ks_pcie_probe(struct platform_device *pdev)
 	if (ret)
 		num_lanes = 1;
 
-	phy = devm_kzalloc(dev, sizeof(*phy) * num_lanes, GFP_KERNEL);
+	phy = devm_kcalloc(dev, num_lanes, sizeof(*phy), GFP_KERNEL);
 	if (!phy)
 		return -ENOMEM;
 
-	link = devm_kzalloc(dev, sizeof(*link) * num_lanes, GFP_KERNEL);
+	link = devm_kcalloc(dev, num_lanes, sizeof(*link), GFP_KERNEL);
 	if (!link)
 		return -ENOMEM;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: keystone: Use kcalloc() instead of kzalloc()
  2025-08-19  8:59 [PATCH] PCI: keystone: Use kcalloc() instead of kzalloc() Qianfeng Rong
@ 2025-08-19  9:49 ` Siddharth Vadapalli
  2025-08-19  9:53   ` Qianfeng Rong
  0 siblings, 1 reply; 3+ messages in thread
From: Siddharth Vadapalli @ 2025-08-19  9:49 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński,
	Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Niklas Cassel,
	Kishon Vijay Abraham I, Siddharth Vadapalli, Sergio Paracuellos,
	Hans Zhang, Jiri Slaby (SUSE),
	linux-pci, linux-kernel

On Tue, Aug 19, 2025 at 04:59:15PM +0800, Qianfeng Rong wrote:

Hello,

> Replace calls of devm_kzalloc() with devm_kcalloc() in ks_pcie_probe() for
> safer memory allocation with built-in overflow protection.

Please add more details by referring to:
https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
and stating that multiplication could lead to an overflow and isn't safe
when it is used to calculate the size of allocation.

> 
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>  drivers/pci/controller/dwc/pci-keystone.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
> index 7d7aede54ed3..3d10e1112131 100644
> --- a/drivers/pci/controller/dwc/pci-keystone.c
> +++ b/drivers/pci/controller/dwc/pci-keystone.c
> @@ -1212,11 +1212,11 @@ static int ks_pcie_probe(struct platform_device *pdev)
>  	if (ret)
>  		num_lanes = 1;
>  
> -	phy = devm_kzalloc(dev, sizeof(*phy) * num_lanes, GFP_KERNEL);
> +	phy = devm_kcalloc(dev, num_lanes, sizeof(*phy), GFP_KERNEL);
>  	if (!phy)
>  		return -ENOMEM;
>  
> -	link = devm_kzalloc(dev, sizeof(*link) * num_lanes, GFP_KERNEL);
> +	link = devm_kcalloc(dev, num_lanes, sizeof(*link), GFP_KERNEL);
>  	if (!link)
>  		return -ENOMEM;

Regards,
Siddharth.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: keystone: Use kcalloc() instead of kzalloc()
  2025-08-19  9:49 ` Siddharth Vadapalli
@ 2025-08-19  9:53   ` Qianfeng Rong
  0 siblings, 0 replies; 3+ messages in thread
From: Qianfeng Rong @ 2025-08-19  9:53 UTC (permalink / raw)
  To: Siddharth Vadapalli
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński,
	Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Niklas Cassel,
	Kishon Vijay Abraham I, Sergio Paracuellos, Hans Zhang,
	Jiri Slaby (SUSE),
	linux-pci, linux-kernel


在 2025/8/19 17:49, Siddharth Vadapalli 写道:
> On Tue, Aug 19, 2025 at 04:59:15PM +0800, Qianfeng Rong wrote:
>
> Hello,
>
>> Replace calls of devm_kzalloc() with devm_kcalloc() in ks_pcie_probe() for
>> safer memory allocation with built-in overflow protection.
> Please add more details by referring to:
> https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> and stating that multiplication could lead to an overflow and isn't safe
> when it is used to calculate the size of allocation.
OK, I will try to do this in the next version.
>
>> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
>> ---
>>   drivers/pci/controller/dwc/pci-keystone.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
>> index 7d7aede54ed3..3d10e1112131 100644
>> --- a/drivers/pci/controller/dwc/pci-keystone.c
>> +++ b/drivers/pci/controller/dwc/pci-keystone.c
>> @@ -1212,11 +1212,11 @@ static int ks_pcie_probe(struct platform_device *pdev)
>>   	if (ret)
>>   		num_lanes = 1;
>>   
>> -	phy = devm_kzalloc(dev, sizeof(*phy) * num_lanes, GFP_KERNEL);
>> +	phy = devm_kcalloc(dev, num_lanes, sizeof(*phy), GFP_KERNEL);
>>   	if (!phy)
>>   		return -ENOMEM;
>>   
>> -	link = devm_kzalloc(dev, sizeof(*link) * num_lanes, GFP_KERNEL);
>> +	link = devm_kcalloc(dev, num_lanes, sizeof(*link), GFP_KERNEL);
>>   	if (!link)
>>   		return -ENOMEM;
> Regards,
> Siddharth.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-19  9:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-19  8:59 [PATCH] PCI: keystone: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-19  9:49 ` Siddharth Vadapalli
2025-08-19  9:53   ` Qianfeng Rong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®