Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target: Use kmalloc_array() in compare_and_write_callback()

* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
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>

authored by

Markus Elfring and committed by
Nicholas Bellinger
f318aef5 5d68fb72

+2 -2
+2 -2
drivers/target/target_core_sbc.c
··· 519 519 goto out; 520 520 } 521 521 522 - write_sg = kmalloc(sizeof(struct scatterlist) * cmd->t_data_nents, 523 - GFP_KERNEL); 522 + write_sg = kmalloc_array(cmd->t_data_nents, sizeof(*write_sg), 523 + GFP_KERNEL); 524 524 if (!write_sg) { 525 525 pr_err("Unable to allocate compare_and_write sg\n"); 526 526 ret = TCM_OUT_OF_RESOURCES;