From: Markus Elfring <elfr...@users.sourceforge.net>
Date: Wed, 5 Oct 2016 16:45:05 +0200

* 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 <elfr...@users.sourceforge.net>
---
 drivers/md/raid10.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index be1a9fc..17352a9 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3504,8 +3504,8 @@ static struct r10conf *setup_conf(struct mddev *mddev)
                goto out;
 
        /* FIXME calc properly */
-       conf->mirrors = kzalloc(sizeof(struct raid10_info)*(mddev->raid_disks +
-                                                           
max(0,-mddev->delta_disks)),
+       conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
+                               sizeof(*conf->mirrors),
                                GFP_KERNEL);
        if (!conf->mirrors)
                goto out;
@@ -3936,11 +3936,10 @@ static int raid10_check_reshape(struct mddev *mddev)
        conf->mirrors_new = NULL;
        if (mddev->delta_disks > 0) {
                /* allocate new 'mirrors' list */
-               conf->mirrors_new = kzalloc(
-                       sizeof(struct raid10_info)
-                       *(mddev->raid_disks +
-                         mddev->delta_disks),
-                       GFP_KERNEL);
+               conf->mirrors_new = kcalloc(mddev->raid_disks
+                                           + mddev->delta_disks,
+                                           sizeof(*conf->mirrors_new),
+                                           GFP_KERNEL);
                if (!conf->mirrors_new)
                        return -ENOMEM;
        }
-- 
2.10.1

Reply via email to