diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 3b90d38d1..74364ad51 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -1247,8 +1247,9 @@ static int dev_user_map_buf(struct scst_user_cmd *ucmd, unsigned long ubuff, ucmd->num_data_pages = num_pg; - ucmd->data_pages = kmalloc(sizeof(*ucmd->data_pages) * ucmd->num_data_pages, - GFP_KERNEL); + ucmd->data_pages = kmalloc_array(ucmd->num_data_pages, + sizeof(*ucmd->data_pages), + GFP_KERNEL); if (ucmd->data_pages == NULL) { TRACE(TRACE_OUT_OF_MEM, "Unable to allocate data_pages array " "(num_data_pages=%d)", ucmd->num_data_pages); @@ -1535,7 +1536,7 @@ static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, goto out_hw_err_free_buf; } - left = kmalloc(sizeof(*left) * count, GFP_KERNEL); + left = kmalloc_array(count, sizeof(*left), GFP_KERNEL); if (unlikely(left == NULL)) { PRINT_ERROR("Unable to alloc leftover remap descriptors " "(size %zd, count %d)", sizeof(*left) * count, count); @@ -1691,7 +1692,7 @@ static int dev_user_process_ws_reply(struct scst_user_cmd *ucmd, goto out_free_buf; } - where = kmalloc(sizeof(*where) * count, GFP_KERNEL); + where = kmalloc_array(count, sizeof(*where), GFP_KERNEL); if (unlikely(where == NULL)) { PRINT_ERROR("Unable to alloc WS descriptors where (size %zd)", sizeof(*where) * count); diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index b55fb9bcd..f3788afa0 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -3323,7 +3323,7 @@ static struct scatterlist *alloc_sg(size_t size, unsigned off, gfp_t gfp_mask, sg_cnt = PAGE_ALIGN(size + off) >> PAGE_SHIFT; sg = sg_cnt <= small_sg_size ? small_sg : - kmalloc(sg_cnt * sizeof(*sg), gfp_mask); + kmalloc_array(sg_cnt, sizeof(*sg), gfp_mask); if (!sg) goto out; @@ -5710,7 +5710,8 @@ static struct iovec *vdisk_alloc_iv(struct scst_cmd *cmd, p->iv_count = 0; /* It can't be called in atomic context */ p->iv = (iv_count <= ARRAY_SIZE(p->small_iv)) ? p->small_iv : - kmalloc(sizeof(*p->iv) * iv_count, cmd->cmd_gfp_mask); + kmalloc_array(iv_count, sizeof(*p->iv), + cmd->cmd_gfp_mask); if (p->iv == NULL) { PRINT_ERROR("Unable to allocate iv (%d)", iv_count); goto out; diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 7c626aa65..316aaf18a 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -6089,7 +6089,7 @@ static int scst_ws_sg_init(struct scatterlist **ws_sg, int ws_sg_cnt, struct scatterlist *sg; int i; - *ws_sg = kmalloc(ws_sg_cnt * sizeof(**ws_sg), GFP_KERNEL); + *ws_sg = kmalloc_array(ws_sg_cnt, sizeof(**ws_sg), GFP_KERNEL); if (*ws_sg == NULL) { PRINT_ERROR("Unable to alloc sg for %d entries", ws_sg_cnt); return -ENOMEM; diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index 488132c07..9800d1a65 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -1332,7 +1332,7 @@ struct scatterlist *scst_alloc_sg(int size, gfp_t gfp_mask, int *count) } } - res = kmalloc(pages*sizeof(*res), gfp_mask); + res = kmalloc_array(pages, sizeof(*res), gfp_mask); if (res == NULL) { TRACE(TRACE_OUT_OF_MEM, "Unable to allocate sg for %d pages", pages);