mmc: core: Use kmalloc_array() in mmc_alloc_sg()
authorMarkus Elfring <elfring@users.sourceforge.net>
Sun, 8 Jan 2017 21:10:40 +0000 (22:10 +0100)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 13 Feb 2017 12:20:11 +0000 (13:20 +0100)
* 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>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/core/queue.c

index a6496d8027bce0b4914c2ced3cf6bada3c540b8c..b1986622c60e8f65315b3643e7314113776dc0b2 100644 (file)
@@ -152,7 +152,7 @@ static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
        struct scatterlist *sg;
 
-       sg = kmalloc(sizeof(struct scatterlist)*sg_len, GFP_KERNEL);
+       sg = kmalloc_array(sg_len, sizeof(*sg), GFP_KERNEL);
        if (!sg)
                *err = -ENOMEM;
        else {