Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1266552

[PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc

From Geliang Tang <geliangtang@163.com>
Newsgroups linux.kernel
Subject [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc
Date 2015-11-10 15:50 +0100
Message-ID <qtipc-6iz-21@gated-at.bofh.it> (permalink)
References <qsUZz-73K-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Use kmalloc_array instead of kmalloc to allocate memory for an array.

Signed-off-by: Geliang Tang <geliangtang@163.com>

---
Changes in v2:
 - preserve the existing whitespace style.
---
 drivers/staging/comedi/drivers/amplc_pci224.c | 11 +++++++----
 drivers/staging/comedi/drivers/ni_670x.c      |  5 +++--
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index b2f7679..cac011f 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -1022,14 +1022,17 @@ pci224_auto_attach(struct comedi_device *dev, unsigned long context_model)
 	irq = pci_dev->irq;
 
 	/* Allocate buffer to hold values for AO channel scan. */
-	devpriv->ao_scan_vals = kmalloc(sizeof(devpriv->ao_scan_vals[0]) *
-					board->ao_chans, GFP_KERNEL);
+	devpriv->ao_scan_vals = kmalloc_array(board->ao_chans,
+					      sizeof(devpriv->ao_scan_vals[0]),
+					      GFP_KERNEL);
 	if (!devpriv->ao_scan_vals)
 		return -ENOMEM;
 
 	/* Allocate buffer to hold AO channel scan order. */
-	devpriv->ao_scan_order = kmalloc(sizeof(devpriv->ao_scan_order[0]) *
-					 board->ao_chans, GFP_KERNEL);
+	devpriv->ao_scan_order =
+				kmalloc_array(board->ao_chans,
+					      sizeof(devpriv->ao_scan_order[0]),
+					      GFP_KERNEL);
 	if (!devpriv->ao_scan_order)
 		return -ENOMEM;
 
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index f4c580f..3e7271880 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -214,8 +214,9 @@ static int ni_670x_auto_attach(struct comedi_device *dev,
 	if (s->n_chan == 32) {
 		const struct comedi_lrange **range_table_list;
 
-		range_table_list = kmalloc(sizeof(struct comedi_lrange *) * 32,
-					   GFP_KERNEL);
+		range_table_list = kmalloc_array(32,
+						 sizeof(struct comedi_lrange *),
+						 GFP_KERNEL);
 		if (!range_table_list)
 			return -ENOMEM;
 		s->range_table_list = range_table_list;
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-08 15:30 +0100
  [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-08 15:30 +0100
  [PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-08 15:30 +0100
  Re: [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Ian Abbott <abbotti@mev.co.uk> - 2015-11-09 14:50 +0100
    [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang <geliangtang@163.com> - 2015-11-10 15:50 +0100
      Re: [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc Ian Abbott <abbotti@mev.co.uk> - 2015-11-11 15:10 +0100

csiph-web