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


Groups > linux.kernel > #1265103 > unrolled thread

[PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc

Started byGeliang Tang <geliangtang@163.com>
First post2015-11-08 15:30 +0100
Last post2015-11-11 15:10 +0100
Articles 6 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [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

#1265103 — [PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc

FromGeliang Tang <geliangtang@163.com>
Date2015-11-08 15:30 +0100
Subject[PATCH 1/4] staging: comedi: use kmalloc_array instead of kmalloc
Message-ID<qsz8J-1gC-9@gated-at.bofh.it>
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


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

[toc] | [next] | [standalone]


#1265104 — [PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc

FromGeliang Tang <geliangtang@163.com>
Date2015-11-08 15:30 +0100
Subject[PATCH 4/4] staging: rtl8192u: r8192U_core: use kmalloc_array instead of kmalloc
Message-ID<qsz8K-1gC-27@gated-at.bofh.it>
In reply to#1265103
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


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

[toc] | [prev] | [next] | [standalone]


#1265105 — [PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc

FromGeliang Tang <geliangtang@163.com>
Date2015-11-08 15:30 +0100
Subject[PATCH 2/4] staging: rdma: use kmalloc_array instead of kmalloc
Message-ID<qsz8K-1gC-29@gated-at.bofh.it>
In reply to#1265103
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


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

[toc] | [prev] | [next] | [standalone]


#1265675

FromIan Abbott <abbotti@mev.co.uk>
Date2015-11-09 14:50 +0100
Message-ID<qsUZz-73K-1@gated-at.bofh.it>
In reply to#1265103
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/  )=-
--
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/

[toc] | [prev] | [next] | [standalone]


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

FromGeliang Tang <geliangtang@163.com>
Date2015-11-10 15:50 +0100
Subject[PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc
Message-ID<qtipc-6iz-21@gated-at.bofh.it>
In reply to#1265675
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/

[toc] | [prev] | [next] | [standalone]


#1267205 — Re: [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc

FromIan Abbott <abbotti@mev.co.uk>
Date2015-11-11 15:10 +0100
SubjectRe: [PATCH v2] staging: comedi: use kmalloc_array instead of kmalloc
Message-ID<qtEg2-3OD-7@gated-at.bofh.it>
In reply to#1266552
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/  )=-
--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web