mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-22 21:21:28 +00:00
scst: Use kmalloc_array() instead of kmalloc() with multiply
git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6637 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user