提交 983e2444 编写于 作者: H Himangi Saraogi 提交者: Scott Wood

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:

// <smpl>
@disable sizeof_type_expr@
type T;
T **x;
@@

  x =
  <+...sizeof(
- T
+ *x
  )...+>
// </smpl>
Signed-off-by: NHimangi Saraogi <himangi774@gmail.com>
Acked-by: NJulia Lawall <julia.lawall@lip6.fr>
Signed-off-by: NScott Wood <scottwood@freescale.com>
上级 54afbec0
...@@ -184,7 +184,7 @@ static int mpic_msgr_probe(struct platform_device *dev) ...@@ -184,7 +184,7 @@ static int mpic_msgr_probe(struct platform_device *dev)
dev_info(&dev->dev, "Found %d message registers\n", dev_info(&dev->dev, "Found %d message registers\n",
mpic_msgr_count); mpic_msgr_count);
mpic_msgrs = kzalloc(sizeof(struct mpic_msgr) * mpic_msgr_count, mpic_msgrs = kcalloc(mpic_msgr_count, sizeof(*mpic_msgrs),
GFP_KERNEL); GFP_KERNEL);
if (!mpic_msgrs) { if (!mpic_msgrs) {
dev_err(&dev->dev, dev_err(&dev->dev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册