aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorThomas Meyer <thomas@m3y3r.de>2011-11-29 16:08:00 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-11-30 05:37:33 -0500
commitd83fb184945cd2daaafd33a702bba9cb7ed502bf (patch)
treeeb13dc818416eecbc1a31b564b76fe292021b40d /drivers/staging
parent201320435d017e8ebd449034547ef0518ec4d056 (diff)
staging: iio: Use kcalloc instead of kzalloc to allocate array
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 <thomas@m3y3r.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c3
-rw-r--r--drivers/staging/iio/adc/ad7280a.c6
-rw-r--r--drivers/staging/iio/iio_simple_dummy.c3
-rw-r--r--drivers/staging/iio/industrialio-buffer.c14
-rw-r--r--drivers/staging/iio/industrialio-core.c14
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c4
6 files changed, 20 insertions, 24 deletions
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 89527af8f4c..a9005027120 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -93,8 +93,7 @@ static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array)
93 struct spi_message msg; 93 struct spi_message msg;
94 int ret, i, j = 0; 94 int ret, i, j = 0;
95 95
96 xfers = kzalloc((buffer->scan_count) * 2 96 xfers = kcalloc((buffer->scan_count) * 2, sizeof(*xfers), GFP_KERNEL);
97 * sizeof(*xfers), GFP_KERNEL);
98 if (!xfers) 97 if (!xfers)
99 return -ENOMEM; 98 return -ENOMEM;
100 99
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index 1af4194bbd8..f70bff24785 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -488,8 +488,8 @@ static int ad7280_channel_init(struct ad7280_state *st)
488{ 488{
489 int dev, ch, cnt; 489 int dev, ch, cnt;
490 490
491 st->channels = kzalloc(sizeof(*st->channels) * 491 st->channels = kcalloc((st->slave_num + 1) * 12 + 2,
492 ((st->slave_num + 1) * 12 + 2), GFP_KERNEL); 492 sizeof(*st->channels), GFP_KERNEL);
493 if (st->channels == NULL) 493 if (st->channels == NULL)
494 return -ENOMEM; 494 return -ENOMEM;
495 495
@@ -683,7 +683,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
683 unsigned *channels; 683 unsigned *channels;
684 int i, ret; 684 int i, ret;
685 685
686 channels = kzalloc(sizeof(*channels) * st->scan_cnt, GFP_KERNEL); 686 channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL);
687 if (channels == NULL) 687 if (channels == NULL)
688 return IRQ_HANDLED; 688 return IRQ_HANDLED;
689 689
diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index 228f991d40e..e3a94572bb4 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -518,7 +518,8 @@ static __init int iio_dummy_init(void)
518 return -EINVAL; 518 return -EINVAL;
519 } 519 }
520 /* Fake a bus */ 520 /* Fake a bus */
521 iio_dummy_devs = kzalloc(sizeof(*iio_dummy_devs)*instances, GFP_KERNEL); 521 iio_dummy_devs = kcalloc(instances, sizeof(*iio_dummy_devs),
522 GFP_KERNEL);
522 /* Here we have no actual device so call probe */ 523 /* Here we have no actual device so call probe */
523 for (i = 0; i < instances; i++) { 524 for (i = 0; i < instances; i++) {
524 ret = iio_dummy_probe(i); 525 ret = iio_dummy_probe(i);
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index f757bb78d88..8c5598081b6 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -315,10 +315,9 @@ int iio_buffer_register(struct iio_dev *indio_dev,
315 attrcount += ret; 315 attrcount += ret;
316 } 316 }
317 if (indio_dev->masklength && buffer->scan_mask == NULL) { 317 if (indio_dev->masklength && buffer->scan_mask == NULL) {
318 buffer->scan_mask 318 buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
319 = kzalloc(sizeof(*buffer->scan_mask)* 319 sizeof(*buffer->scan_mask),
320 BITS_TO_LONGS(indio_dev->masklength), 320 GFP_KERNEL);
321 GFP_KERNEL);
322 if (buffer->scan_mask == NULL) { 321 if (buffer->scan_mask == NULL) {
323 ret = -ENOMEM; 322 ret = -ENOMEM;
324 goto error_cleanup_dynamic; 323 goto error_cleanup_dynamic;
@@ -328,10 +327,9 @@ int iio_buffer_register(struct iio_dev *indio_dev,
328 327
329 buffer->scan_el_group.name = iio_scan_elements_group_name; 328 buffer->scan_el_group.name = iio_scan_elements_group_name;
330 329
331 buffer->scan_el_group.attrs 330 buffer->scan_el_group.attrs = kcalloc(attrcount + 1,
332 = kzalloc(sizeof(buffer->scan_el_group.attrs[0])* 331 sizeof(buffer->scan_el_group.attrs[0]),
333 (attrcount + 1), 332 GFP_KERNEL);
334 GFP_KERNEL);
335 if (buffer->scan_el_group.attrs == NULL) { 333 if (buffer->scan_el_group.attrs == NULL) {
336 ret = -ENOMEM; 334 ret = -ENOMEM;
337 goto error_free_scan_mask; 335 goto error_free_scan_mask;
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 55c0b4880f8..d8cd9e3c07a 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -669,10 +669,9 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
669 if (indio_dev->name) 669 if (indio_dev->name)
670 attrcount++; 670 attrcount++;
671 671
672 indio_dev->chan_attr_group.attrs 672 indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,
673 = kzalloc(sizeof(indio_dev->chan_attr_group.attrs[0])* 673 sizeof(indio_dev->chan_attr_group.attrs[0]),
674 (attrcount + 1), 674 GFP_KERNEL);
675 GFP_KERNEL);
676 if (indio_dev->chan_attr_group.attrs == NULL) { 675 if (indio_dev->chan_attr_group.attrs == NULL) {
677 ret = -ENOMEM; 676 ret = -ENOMEM;
678 goto error_clear_attrs; 677 goto error_clear_attrs;
@@ -965,10 +964,9 @@ static int iio_device_register_eventset(struct iio_dev *indio_dev)
965 } 964 }
966 965
967 indio_dev->event_interface->group.name = iio_event_group_name; 966 indio_dev->event_interface->group.name = iio_event_group_name;
968 indio_dev->event_interface->group.attrs = 967 indio_dev->event_interface->group.attrs = kcalloc(attrcount + 1,
969 kzalloc(sizeof(indio_dev->event_interface->group.attrs[0]) 968 sizeof(indio_dev->event_interface->group.attrs[0]),
970 *(attrcount + 1), 969 GFP_KERNEL);
971 GFP_KERNEL);
972 if (indio_dev->event_interface->group.attrs == NULL) { 970 if (indio_dev->event_interface->group.attrs == NULL) {
973 ret = -ENOMEM; 971 ret = -ENOMEM;
974 goto error_free_setup_event_lines; 972 goto error_free_setup_event_lines;
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index 348df974dfe..9dc881f59bd 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -746,12 +746,12 @@ static int __devinit ade7758_probe(struct spi_device *spi)
746 spi_set_drvdata(spi, indio_dev); 746 spi_set_drvdata(spi, indio_dev);
747 747
748 /* Allocate the comms buffers */ 748 /* Allocate the comms buffers */
749 st->rx = kzalloc(sizeof(*st->rx)*ADE7758_MAX_RX, GFP_KERNEL); 749 st->rx = kcalloc(ADE7758_MAX_RX, sizeof(*st->rx), GFP_KERNEL);
750 if (st->rx == NULL) { 750 if (st->rx == NULL) {
751 ret = -ENOMEM; 751 ret = -ENOMEM;
752 goto error_free_dev; 752 goto error_free_dev;
753 } 753 }
754 st->tx = kzalloc(sizeof(*st->tx)*ADE7758_MAX_TX, GFP_KERNEL); 754 st->tx = kcalloc(ADE7758_MAX_TX, sizeof(*st->tx), GFP_KERNEL);
755 if (st->tx == NULL) { 755 if (st->tx == NULL) {
756 ret = -ENOMEM; 756 ret = -ENOMEM;
757 goto error_free_rx; 757 goto error_free_rx;