Skip to content

Commit

Permalink
leds: Use kcalloc instead of kzalloc to allocate array
Browse files Browse the repository at this point in the history
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 semantic patch that makes this change is available
in https://lkml.org/lkml/2011/11/25/107

Signed-off-by: Thomas Meyer <[email protected]>
Cc: Bryan Wu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
thomasmey authored and torvalds committed May 29, 2012
1 parent 872b86b commit 1daef6d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/leds/leds-mc13783.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
return -EINVAL;
}

led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
if (led == NULL) {
dev_err(&pdev->dev, "failed to alloc memory\n");
return -ENOMEM;
Expand Down

0 comments on commit 1daef6d

Please sign in to comment.