All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc
@ 2015-11-08 14:17 Geliang Tang
  2015-11-08 14:17   ` Geliang Tang
  2015-11-09 13:49 ` [PATCH 1/4] staging: comedi: " Ian Abbott
  0 siblings, 2 replies; 11+ messages in thread
From: Geliang Tang @ 2015-11-08 14:17 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman
  Cc: Geliang Tang, devel, linux-kernel

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

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/comedi/drivers/amplc_pci224.c | 8 ++++----
 drivers/staging/comedi/drivers/ni_670x.c      | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index b2f7679..d39f02d 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -1022,14 +1022,14 @@ 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



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc
  2015-11-08 14:17 [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang
@ 2015-11-08 14:17   ` Geliang Tang
  2015-11-09 13:49 ` [PATCH 1/4] staging: comedi: " Ian Abbott
  1 sibling, 0 replies; 11+ messages in thread
From: Geliang Tang @ 2015-11-08 14:17 UTC (permalink / raw)
  To: Doug Ledford, Sean Hefty, Hal Rosenstock, Greg Kroah-Hartman,
	Mike Marciniszyn
  Cc: linux-rdma, Geliang Tang, devel, linux-kernel

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

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/rdma/amso1100/c2.c          | 6 ++++--
 drivers/staging/rdma/ipath/ipath_file_ops.c | 8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rdma/amso1100/c2.c b/drivers/staging/rdma/amso1100/c2.c
index 35ac536..4e6d24a 100644
--- a/drivers/staging/rdma/amso1100/c2.c
+++ b/drivers/staging/rdma/amso1100/c2.c
@@ -116,7 +116,8 @@ static int c2_tx_ring_alloc(struct c2_ring *tx_ring, void *vaddr,
 	struct c2_element *elem;
 	int i;
 
-	tx_ring->start = kmalloc(sizeof(*elem) * tx_ring->count, GFP_KERNEL);
+	tx_ring->start = kmalloc_array(tx_ring->count, sizeof(*elem),
+				       GFP_KERNEL);
 	if (!tx_ring->start)
 		return -ENOMEM;
 
@@ -165,7 +166,8 @@ static int c2_rx_ring_alloc(struct c2_ring *rx_ring, void *vaddr,
 	struct c2_element *elem;
 	int i;
 
-	rx_ring->start = kmalloc(sizeof(*elem) * rx_ring->count, GFP_KERNEL);
+	rx_ring->start = kmalloc_array(rx_ring->count, sizeof(*elem),
+				       GFP_KERNEL);
 	if (!rx_ring->start)
 		return -ENOMEM;
 
diff --git a/drivers/staging/rdma/ipath/ipath_file_ops.c b/drivers/staging/rdma/ipath/ipath_file_ops.c
index 13c3cd1..6187b84 100644
--- a/drivers/staging/rdma/ipath/ipath_file_ops.c
+++ b/drivers/staging/rdma/ipath/ipath_file_ops.c
@@ -917,15 +917,15 @@ static int ipath_create_user_egr(struct ipath_portdata *pd)
 	chunk = pd->port_rcvegrbuf_chunks;
 	egrperchunk = pd->port_rcvegrbufs_perchunk;
 	size = pd->port_rcvegrbuf_size;
-	pd->port_rcvegrbuf = kmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]),
-				     GFP_KERNEL);
+	pd->port_rcvegrbuf = kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf[0]),
+					   GFP_KERNEL);
 	if (!pd->port_rcvegrbuf) {
 		ret = -ENOMEM;
 		goto bail;
 	}
 	pd->port_rcvegrbuf_phys =
-		kmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0]),
-			GFP_KERNEL);
+		kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf_phys[0]),
+			      GFP_KERNEL);
 	if (!pd->port_rcvegrbuf_phys) {
 		ret = -ENOMEM;
 		goto bail_rcvegrbuf;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc
@ 2015-11-08 14:17   ` Geliang Tang
  0 siblings, 0 replies; 11+ messages in thread
From: Geliang Tang @ 2015-11-08 14:17 UTC (permalink / raw)
  To: Doug Ledford, Sean Hefty, Hal Rosenstock, Greg Kroah-Hartman,
	Mike Marciniszyn
  Cc: Geliang Tang, linux-rdma, devel, linux-kernel

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

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/rdma/amso1100/c2.c          | 6 ++++--
 drivers/staging/rdma/ipath/ipath_file_ops.c | 8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rdma/amso1100/c2.c b/drivers/staging/rdma/amso1100/c2.c
index 35ac536..4e6d24a 100644
--- a/drivers/staging/rdma/amso1100/c2.c
+++ b/drivers/staging/rdma/amso1100/c2.c
@@ -116,7 +116,8 @@ static int c2_tx_ring_alloc(struct c2_ring *tx_ring, void *vaddr,
 	struct c2_element *elem;
 	int i;
 
-	tx_ring->start = kmalloc(sizeof(*elem) * tx_ring->count, GFP_KERNEL);
+	tx_ring->start = kmalloc_array(tx_ring->count, sizeof(*elem),
+				       GFP_KERNEL);
 	if (!tx_ring->start)
 		return -ENOMEM;
 
@@ -165,7 +166,8 @@ static int c2_rx_ring_alloc(struct c2_ring *rx_ring, void *vaddr,
 	struct c2_element *elem;
 	int i;
 
-	rx_ring->start = kmalloc(sizeof(*elem) * rx_ring->count, GFP_KERNEL);
+	rx_ring->start = kmalloc_array(rx_ring->count, sizeof(*elem),
+				       GFP_KERNEL);
 	if (!rx_ring->start)
 		return -ENOMEM;
 
diff --git a/drivers/staging/rdma/ipath/ipath_file_ops.c b/drivers/staging/rdma/ipath/ipath_file_ops.c
index 13c3cd1..6187b84 100644
--- a/drivers/staging/rdma/ipath/ipath_file_ops.c
+++ b/drivers/staging/rdma/ipath/ipath_file_ops.c
@@ -917,15 +917,15 @@ static int ipath_create_user_egr(struct ipath_portdata *pd)
 	chunk = pd->port_rcvegrbuf_chunks;
 	egrperchunk = pd->port_rcvegrbufs_perchunk;
 	size = pd->port_rcvegrbuf_size;
-	pd->port_rcvegrbuf = kmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]),
-				     GFP_KERNEL);
+	pd->port_rcvegrbuf = kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf[0]),
+					   GFP_KERNEL);
 	if (!pd->port_rcvegrbuf) {
 		ret = -ENOMEM;
 		goto bail;
 	}
 	pd->port_rcvegrbuf_phys =
-		kmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0]),
-			GFP_KERNEL);
+		kmalloc_array(chunk, sizeof(pd->port_rcvegrbuf_phys[0]),
+			      GFP_KERNEL);
 	if (!pd->port_rcvegrbuf_phys) {
 		ret = -ENOMEM;
 		goto bail_rcvegrbuf;
-- 
2.5.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/4] staging: lustre: libcfs: use kmalloc_array instead of kmalloc
  2015-11-08 14:17   ` Geliang Tang
  (?)
@ 2015-11-08 14:17   ` Geliang Tang
  2015-11-08 14:17     ` [PATCH 4/4] staging: rtl8192u: r8192U_core: " Geliang Tang
  -1 siblings, 1 reply; 11+ messages in thread
From: Geliang Tang @ 2015-11-08 14:17 UTC (permalink / raw)
  To: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman
  Cc: Geliang Tang, lustre-devel, devel, linux-kernel

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

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
index 64a136c..3d3713b 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
@@ -60,9 +60,8 @@ int cfs_tracefile_init_arch(void)
 	/* initialize trace_data */
 	memset(cfs_trace_data, 0, sizeof(cfs_trace_data));
 	for (i = 0; i < CFS_TCD_TYPE_MAX; i++) {
-		cfs_trace_data[i] =
-			kmalloc(sizeof(union cfs_trace_data_union) *
-				num_possible_cpus(), GFP_KERNEL);
+		cfs_trace_data[i] = kmalloc_array(num_possible_cpus(),
+				sizeof(union cfs_trace_data_union), GFP_KERNEL);
 		if (cfs_trace_data[i] == NULL)
 			goto out;
 
-- 
2.5.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc
  2015-11-08 14:17   ` [PATCH 3/4] staging: lustre: libcfs: " Geliang Tang
@ 2015-11-08 14:17     ` Geliang Tang
  2016-02-08  3:55       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 11+ messages in thread
From: Geliang Tang @ 2015-11-08 14:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Raphaël Beamonte
  Cc: Geliang Tang, devel, linux-kernel

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

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/rtl8192u/r8192U_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index e06864f..07a1447 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -1725,8 +1725,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
 {
 	struct r8192_priv *priv = ieee80211_priv(dev);
 
-	priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
-			       GFP_KERNEL);
+	priv->rx_urb = kmalloc_array(MAX_RX_URB + 1, sizeof(struct urb *),
+				     GFP_KERNEL);
 	if (priv->rx_urb == NULL)
 		return -ENOMEM;
 
-- 
2.5.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc
  2015-11-08 14:17 [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang
  2015-11-08 14:17   ` Geliang Tang
@ 2015-11-09 13:49 ` Ian Abbott
  2015-11-10 14:41   ` [PATCH v2] " Geliang Tang
  1 sibling, 1 reply; 11+ messages in thread
From: Ian Abbott @ 2015-11-09 13:49 UTC (permalink / raw)
  To: Geliang Tang, H Hartley Sweeten, Greg Kroah-Hartman; +Cc: devel, linux-kernel

On 08/11/15 14:17, Geliang Tang wrote:
> Use kmalloc_array instead of kmalloc to allocate memory for an array.
>
> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>   drivers/staging/comedi/drivers/amplc_pci224.c | 8 ++++----
>   drivers/staging/comedi/drivers/ni_670x.c      | 5 +++--
>   2 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
> index b2f7679..d39f02d 100644
> --- a/drivers/staging/comedi/drivers/amplc_pci224.c
> +++ b/drivers/staging/comedi/drivers/amplc_pci224.c
> @@ -1022,14 +1022,14 @@ 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;
>

It would be better if the patch preserved the existing whitespace style 
here, even though that increases the number of lines.

> 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;
>


-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc
  2015-11-09 13:49 ` [PATCH 1/4] staging: comedi: " Ian Abbott
@ 2015-11-10 14:41   ` Geliang Tang
  2015-11-11 14:09     ` Ian Abbott
  0 siblings, 1 reply; 11+ messages in thread
From: Geliang Tang @ 2015-11-10 14:41 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman
  Cc: Geliang Tang, devel, linux-kernel

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



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc
  2015-11-10 14:41   ` [PATCH v2] " Geliang Tang
@ 2015-11-11 14:09     ` Ian Abbott
  0 siblings, 0 replies; 11+ messages in thread
From: Ian Abbott @ 2015-11-11 14:09 UTC (permalink / raw)
  To: Geliang Tang, H Hartley Sweeten, Greg Kroah-Hartman; +Cc: devel, linux-kernel

On 10/11/2015 14:41, Geliang Tang wrote:
> 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;
>

Seems fine!

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc
  2015-11-08 14:17     ` [PATCH 4/4] staging: rtl8192u: r8192U_core: " Geliang Tang
@ 2016-02-08  3:55       ` Greg Kroah-Hartman
  2016-02-23  0:55         ` Geliang Tang
  0 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2016-02-08  3:55 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Raphaël Beamonte, devel, linux-kernel

On Sun, Nov 08, 2015 at 10:17:54PM +0800, Geliang Tang wrote:
> Use kmalloc_array instead of kmalloc to allocate memory for an array.
> 
> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>  drivers/staging/rtl8192u/r8192U_core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> index e06864f..07a1447 100644
> --- a/drivers/staging/rtl8192u/r8192U_core.c
> +++ b/drivers/staging/rtl8192u/r8192U_core.c
> @@ -1725,8 +1725,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
>  {
>  	struct r8192_priv *priv = ieee80211_priv(dev);
>  
> -	priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
> -			       GFP_KERNEL);
> +	priv->rx_urb = kmalloc_array(MAX_RX_URB + 1, sizeof(struct urb *),
> +				     GFP_KERNEL);

I don't see the benefit here with this change, do you?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc
  2016-02-08  3:55       ` Greg Kroah-Hartman
@ 2016-02-23  0:55         ` Geliang Tang
  2016-02-23  1:10           ` Greg Kroah-Hartman
  0 siblings, 1 reply; 11+ messages in thread
From: Geliang Tang @ 2016-02-23  0:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Raphaël Beamonte, devel, linux-kernel, Geliang Tang

On Sun, Feb 07, 2016 at 07:55:09PM -0800, Greg Kroah-Hartman wrote:
> On Sun, Nov 08, 2015 at 10:17:54PM +0800, Geliang Tang wrote:
> > Use kmalloc_array instead of kmalloc to allocate memory for an array.
> > 
> > Signed-off-by: Geliang Tang <geliangtang@163.com>
> > ---
> >  drivers/staging/rtl8192u/r8192U_core.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> > index e06864f..07a1447 100644
> > --- a/drivers/staging/rtl8192u/r8192U_core.c
> > +++ b/drivers/staging/rtl8192u/r8192U_core.c
> > @@ -1725,8 +1725,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
> >  {
> >  	struct r8192_priv *priv = ieee80211_priv(dev);
> >  
> > -	priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
> > -			       GFP_KERNEL);
> > +	priv->rx_urb = kmalloc_array(MAX_RX_URB + 1, sizeof(struct urb *),
> > +				     GFP_KERNEL);
> 
> I don't see the benefit here with this change, do you?

It is highly likely that there is a checkpatch warning "kmalloc with multiplies"
here. But the checkpatch script does not report this warning, I think it is
because MAX_RX_URB is a macro, and there is a '+1' after it. Therefore although
it passes,I think it still should be deemed as a warning. So to use kmalloc_array
here seems better.

Thanks.

- Geliang

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc
  2016-02-23  0:55         ` Geliang Tang
@ 2016-02-23  1:10           ` Greg Kroah-Hartman
  0 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2016-02-23  1:10 UTC (permalink / raw)
  To: Geliang Tang; +Cc: devel, Raphaël Beamonte, linux-kernel

On Tue, Feb 23, 2016 at 08:55:04AM +0800, Geliang Tang wrote:
> On Sun, Feb 07, 2016 at 07:55:09PM -0800, Greg Kroah-Hartman wrote:
> > On Sun, Nov 08, 2015 at 10:17:54PM +0800, Geliang Tang wrote:
> > > Use kmalloc_array instead of kmalloc to allocate memory for an array.
> > > 
> > > Signed-off-by: Geliang Tang <geliangtang@163.com>
> > > ---
> > >  drivers/staging/rtl8192u/r8192U_core.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> > > index e06864f..07a1447 100644
> > > --- a/drivers/staging/rtl8192u/r8192U_core.c
> > > +++ b/drivers/staging/rtl8192u/r8192U_core.c
> > > @@ -1725,8 +1725,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
> > >  {
> > >  	struct r8192_priv *priv = ieee80211_priv(dev);
> > >  
> > > -	priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
> > > -			       GFP_KERNEL);
> > > +	priv->rx_urb = kmalloc_array(MAX_RX_URB + 1, sizeof(struct urb *),
> > > +				     GFP_KERNEL);
> > 
> > I don't see the benefit here with this change, do you?
> 
> It is highly likely that there is a checkpatch warning "kmalloc with multiplies"
> here. But the checkpatch script does not report this warning, I think it is
> because MAX_RX_URB is a macro, and there is a '+1' after it. Therefore although
> it passes,I think it still should be deemed as a warning. So to use kmalloc_array
> here seems better.

No, not for a statically defined size, it doesn't make any sense at all.
kmalloc_array() is to ensure that if you need to allocate a huge size of
memory, that you don't accidentally overflow the memory size with the
calculation you have made, so it does that calculation in a "safe" way.

For a static number, like you have here, it doesn't make any difference.

checkpatch.pl is a _HINT_ not a hard-and-fast-rule.

sorry,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-02-23  1:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-08 14:17 [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc Geliang Tang
2015-11-08 14:17 ` [PATCH 2/4] staging: rdma: " Geliang Tang
2015-11-08 14:17   ` Geliang Tang
2015-11-08 14:17   ` [PATCH 3/4] staging: lustre: libcfs: " Geliang Tang
2015-11-08 14:17     ` [PATCH 4/4] staging: rtl8192u: r8192U_core: " Geliang Tang
2016-02-08  3:55       ` Greg Kroah-Hartman
2016-02-23  0:55         ` Geliang Tang
2016-02-23  1:10           ` Greg Kroah-Hartman
2015-11-09 13:49 ` [PATCH 1/4] staging: comedi: " Ian Abbott
2015-11-10 14:41   ` [PATCH v2] " Geliang Tang
2015-11-11 14:09     ` Ian Abbott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.