lkml.org 
[lkml]   [2016]   [Sep]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions
    From
    Date
    From: Markus Elfring <elfring@users.sourceforge.net>
    Date: Sun, 25 Sep 2016 22:22:04 +0200

    * 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 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>
    ---
    drivers/isdn/gigaset/common.c | 6 ++----
    1 file changed, 2 insertions(+), 4 deletions(-)

    diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
    index 7c78144..cecbb6a 100644
    --- a/drivers/isdn/gigaset/common.c
    +++ b/drivers/isdn/gigaset/common.c
    @@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,

    cs->mode = M_UNKNOWN;
    cs->mstate = MS_UNINITIALIZED;
    -
    - cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
    + cs->bcs = kmalloc_array(channels, sizeof(*cs->bcs), GFP_KERNEL);
    cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
    if (!cs->bcs || !cs->inbuf) {
    pr_err("out of memory\n");
    @@ -1089,8 +1088,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
    drv->ops = ops;
    drv->owner = owner;
    INIT_LIST_HEAD(&drv->list);
    -
    - drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
    + drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);
    if (!drv->cs)
    goto error;

    --
    2.10.0
    \
     
     \ /
      Last update: 2016-09-26 17:39    [W:4.017 / U:0.252 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site