Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: at91_adc: Use devm_kcalloc to allocate arrays

Use dev_kcalloc instead of devm_kzalloc to allocate arrays since it is
semantically more appropriate.

While we are at it the patch also fixes the following coccinelle warning:
drivers/iio/adc/at91_adc.c:277:25-31: ERROR: application of sizeof to pointer

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-By: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
45259859 7737fa6d

+6 -10
+6 -10
drivers/iio/adc/at91_adc.c
··· 123 123 idev->num_channels = bitmap_weight(&st->channels_mask, 124 124 st->num_channels) + 1; 125 125 126 - chan_array = devm_kzalloc(&idev->dev, 127 - ((idev->num_channels + 1) * 128 - sizeof(struct iio_chan_spec)), 129 - GFP_KERNEL); 126 + chan_array = devm_kcalloc(&idev->dev, idev->num_channels + 1, 127 + sizeof(*chan_array), GFP_KERNEL); 130 128 131 129 if (!chan_array) 132 130 return -ENOMEM; ··· 268 270 struct at91_adc_state *st = iio_priv(idev); 269 271 int i, ret; 270 272 271 - st->trig = devm_kzalloc(&idev->dev, 272 - st->trigger_number * sizeof(st->trig), 273 - GFP_KERNEL); 273 + st->trig = devm_kcalloc(&idev->dev, st->trigger_number, 274 + sizeof(*st->trig), GFP_KERNEL); 274 275 275 276 if (st->trig == NULL) { 276 277 ret = -ENOMEM; ··· 451 454 st->registers->trigger_register = prop; 452 455 453 456 st->trigger_number = of_get_child_count(node); 454 - st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number * 455 - sizeof(struct at91_adc_trigger), 456 - GFP_KERNEL); 457 + st->trigger_list = devm_kcalloc(&idev->dev, st->trigger_number, 458 + sizeof(*st->trigger_list), GFP_KERNEL); 457 459 if (!st->trigger_list) { 458 460 dev_err(&idev->dev, "Could not allocate trigger list memory.\n"); 459 461 ret = -ENOMEM;