lkml.org 
[lkml]   [2016]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 40/54] md/raid10: Use kcalloc() in two functions
    From
    Date
    From: Markus Elfring <elfring@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 <elfring@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
    \
     
     \ /
      Last update: 2016-10-06 11:41    [W:4.158 / U:0.052 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site