Skip to content

Commit 55ec409

Browse files
elfringNicholas Bellinger
authored andcommitted
target: Use kcalloc() in two functions
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. * Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 3829f38 commit 55ec409

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎drivers/target/target_core_rd.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ static int rd_build_device_space(struct rd_dev *rd_dev)
210210
total_sg_needed = rd_dev->rd_page_count;
211211

212212
sg_tables = (total_sg_needed / max_sg_per_table) + 1;
213-
214-
sg_table = kzalloc(sg_tables * sizeof(struct rd_dev_sg_table), GFP_KERNEL);
213+
sg_table = kcalloc(sg_tables, sizeof(*sg_table), GFP_KERNEL);
215214
if (!sg_table) {
216215
pr_err("Unable to allocate memory for Ramdisk"
217216
" scatterlist tables\n");
@@ -271,8 +270,7 @@ static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block
271270
total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1;
272271

273272
sg_tables = (total_sg_needed / max_sg_per_table) + 1;
274-
275-
sg_table = kzalloc(sg_tables * sizeof(struct rd_dev_sg_table), GFP_KERNEL);
273+
sg_table = kcalloc(sg_tables, sizeof(*sg_table), GFP_KERNEL);
276274
if (!sg_table) {
277275
pr_err("Unable to allocate memory for Ramdisk protection"
278276
" scatterlist tables\n");

0 commit comments

Comments
 (0)