From: Himangi Saraogi Date: Sat, 19 Jul 2014 21:53:35 +0000 (+0530) Subject: powerpc/mpic_msgr: Use kcalloc and correct the argument to sizeof X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=983e2444100667b4b35c9d56c9a1fec1e817143c;p=linux-beck.git powerpc/mpic_msgr: Use kcalloc and correct the argument to sizeof mpic_msgrs has type struct mpic_msgr **, not struct mpic_msgr *, so the elements of the array should have pointer type, not structure type. The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read. The Coccinelle semantic patch that makes the first change is as follows: // @disable sizeof_type_expr@ type T; T **x; @@ x = <+...sizeof( - T + *x )...+> // Signed-off-by: Himangi Saraogi Acked-by: Julia Lawall Signed-off-by: Scott Wood --- diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c index 2c9b52aa266c..7bdf3cc741e4 100644 --- a/arch/powerpc/sysdev/mpic_msgr.c +++ b/arch/powerpc/sysdev/mpic_msgr.c @@ -184,7 +184,7 @@ static int mpic_msgr_probe(struct platform_device *dev) dev_info(&dev->dev, "Found %d message registers\n", mpic_msgr_count); - mpic_msgrs = kzalloc(sizeof(struct mpic_msgr) * mpic_msgr_count, + mpic_msgrs = kcalloc(mpic_msgr_count, sizeof(*mpic_msgrs), GFP_KERNEL); if (!mpic_msgrs) { dev_err(&dev->dev,