Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1557321

[PATCH 1/3] mtd/ftl: Use kmalloc_array() in build_maps()

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 1/3] mtd/ftl: Use kmalloc_array() in build_maps()
Date 2017-01-12 11:40 +0100
Message-ID <sYKXw-2QD-39@gated-at.bofh.it> (permalink)
References <sYKXw-2QD-37@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 12 Jan 2017 10:42:25 +0100

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of data types 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>
---
 drivers/mtd/ftl.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 9fb3b0dcdac2..ef2f38b6a837 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -207,15 +207,14 @@ static int build_maps(partition_t *part)
     /* Set up erase unit maps */
     part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) -
 	part->header.NumTransferUnits;
-    part->EUNInfo = kmalloc(part->DataUnits * sizeof(struct eun_info_t),
-			    GFP_KERNEL);
+	part->EUNInfo = kmalloc_array(part->DataUnits, sizeof(*part->EUNInfo),
+				      GFP_KERNEL);
     if (!part->EUNInfo)
 	    goto out;
     for (i = 0; i < part->DataUnits; i++)
 	part->EUNInfo[i].Offset = 0xffffffff;
-    part->XferInfo =
-	kmalloc(part->header.NumTransferUnits * sizeof(struct xfer_info_t),
-		GFP_KERNEL);
+	part->XferInfo = kmalloc_array(part->header.NumTransferUnits,
+				       sizeof(*part->XferInfo), GFP_KERNEL);
     if (!part->XferInfo)
 	    goto out_EUNInfo;
 
@@ -275,8 +274,8 @@ static int build_maps(partition_t *part)
     memset(part->VirtualBlockMap, 0xff, blocks * sizeof(uint32_t));
     part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize;
 
-    part->bam_cache = kmalloc(part->BlocksPerUnit * sizeof(uint32_t),
-			      GFP_KERNEL);
+	part->bam_cache = kmalloc_array(part->BlocksPerUnit,
+					sizeof(*part->bam_cache), GFP_KERNEL);
     if (!part->bam_cache)
 	    goto out_VirtualBlockMap;
 
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] MTD-FTL: Fine-tuning for two function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-12 11:40 +0100
  [PATCH 1/3] mtd/ftl: Use kmalloc_array() in build_maps() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-12 11:40 +0100
    Re: [PATCH 1/3] mtd/ftl: Use kmalloc_array() in build_maps() Cyrille Pitchen <cyrille.pitchen@atmel.com> - 2017-01-12 14:10 +0100
      Re: mtd/ftl: Use kmalloc_array() in build_maps() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-12 18:00 +0100
        Re: mtd/ftl: Use kmalloc_array() in build_maps() Marek Vasut <marek.vasut@gmail.com> - 2017-01-12 18:00 +0100
  [PATCH 2/3] mtd/ftl: Delete an error message for a failed memory  allocation in ftl_add_mtd() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-12 11:40 +0100
  [PATCH 3/3] mtd/ftl: Improve another size determination in  ftl_add_mtd() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-12 11:50 +0100

csiph-web