Skip to contentSkip to conversation

staging: fsl-mc: bus: Use devm_kcalloc instead of devm_kzalloc

PATCH New Amitoj Kaur Chawla 1 participant 1 message Feb 25, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fsl-mc: bus: Use devm_kcalloc instead of devm_kzalloc

Replace devm_kzalloc with devm_kcalloc to ensure there are no integer overflows from the multiplication of a number * sizeof.

The following Coccinelle semantic patch was used to make this change:
//<smpl>
@@
expression dev,E1,E2,E3;
@@
- devm_kzalloc(dev,E1*sizeof(E2),E3)
+ devm_kcalloc(dev,E1,sizeof(E2),E3)
//</smpl>

---
 drivers/staging/fsl-mc/bus/mc-allocator.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/fsl-mc/bus/mc-allocator.c +3 -4
index 86f8543..f3d34be 100644
@@ -491,9 +491,8 @@ int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
 	if (error < 0)
 		return error;
 
-	irq_resources = devm_kzalloc(&mc_bus_dev->dev,
-				     sizeof(*irq_resources) * irq_count,
-				     GFP_KERNEL);
+	irq_resources = devm_kcalloc(&mc_bus_dev->dev, irq_count,
+				     sizeof(*irq_resources), GFP_KERNEL);
 	if (!irq_resources) {
 		error = -ENOMEM;
 		goto cleanup_msi_irqs;
@@ -596,7 +595,7 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
 		return -ENOSPC;
 	}
 
-	irqs = devm_kzalloc(&mc_dev->dev, irq_count * sizeof(irqs[0]),
+	irqs = devm_kcalloc(&mc_dev->dev, irq_count, sizeof(irqs[0]),
 			    GFP_KERNEL);
 	if (!irqs)
 		return -ENOMEM;
Signature · 1 line
1.9.1