Skip to contentSkip to conversation

crypto: qat - use kcalloc() instead of kzalloc()

PATCH In review Lenko Donchev 3 participants 3 messages Jan 29, 2024 – Feb 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: qat - use kcalloc() instead of kzalloc()

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows[1]. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 drivers/crypto/intel/qat/qat_common/adf_isr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_isr.c +1 -1
index 3557a0d6dea2..a13d9885d60f 100644
@@ -272,7 +272,7 @@ static int adf_isr_alloc_msix_vectors_data(struct adf_accel_dev *accel_dev)
 	if (!accel_dev->pf.vf_info)
 		msix_num_entries += hw_data->num_banks;
 
-	irqs = kzalloc_node(msix_num_entries * sizeof(*irqs),
+	irqs = kcalloc_node(msix_num_entries, sizeof(*irqs),
 			    GFP_KERNEL, dev_to_node(&GET_DEV(accel_dev)));
 	if (!irqs)
 		return -ENOMEM;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Lenko Donchev

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows[1]. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

Thanks!

Signature · 1 line
Gustavo
Quoted 17 lines
---
  drivers/crypto/intel/qat/qat_common/adf_isr.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_isr.c +1 -1
index 3557a0d6dea2..a13d9885d60f 100644
@@ -272,7 +272,7 @@ static int adf_isr_alloc_msix_vectors_data(struct adf_accel_dev *accel_dev)
  	if (!accel_dev->pf.vf_info)
  		msix_num_entries += hw_data->num_banks;
 
-	irqs = kzalloc_node(msix_num_entries * sizeof(*irqs),
+	irqs = kcalloc_node(msix_num_entries, sizeof(*irqs),
  			    GFP_KERNEL, dev_to_node(&GET_DEV(accel_dev)));
  	if (!irqs)
  		return -ENOMEM;
#2 lore raw
In reply to Lenko Donchev
Quoted 9 lines · Lenko Donchev

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows[1]. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

Thanks for your patch.
The same change was already applied to the cryptodev tree about two weeks ago. See 4da3bc65d218 ("crypto: qat - use kcalloc_node() instead of kzalloc_node()") [1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git/commit/?id=4da3bc65d218605557696109e42cfeee666d601f

Regards,

Signature · 1 line
Giovanni