[PATCH] scsi: elx: efct: Avoid open coded arithmetic in memory allocation

From: Christophe JAILLET
Date: Fri Jul 22 2022 - 01:24:12 EST


kmalloc_array()/kcalloc() should be used to avoid potential overflow when
a multiplication is needed to compute the size of the requested memory.

So turn a kzalloc()+explicit size computation into an equivalent kcalloc().

Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Discussion about it at:
https://lore.kernel.org/all/eab847fe-8d17-1a38-b55e-e68a2f6a1829@xxxxxxxxxxxxxx/
---
drivers/scsi/elx/efct/efct_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/elx/efct/efct_io.c b/drivers/scsi/elx/efct/efct_io.c
index c612f0a48839..1ae2e4e950ef 100644
--- a/drivers/scsi/elx/efct/efct_io.c
+++ b/drivers/scsi/elx/efct/efct_io.c
@@ -56,7 +56,7 @@ efct_io_pool_create(struct efct *efct, u32 num_sgl)
}

/* Allocate SGL */
- io->sgl = kzalloc(sizeof(*io->sgl) * num_sgl, GFP_KERNEL);
+ io->sgl = kcalloc(num_sgl, sizeof(*io->sgl), GFP_KERNEL);
if (!io->sgl) {
efct_io_pool_free(io_pool);
return NULL;
--
2.34.1