public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail•com>
To: Niklas Cassel <niklas.cassel@axis•com>
Cc: Joao Pinto <Joao.Pinto@synopsys•com>,
	David Miller <davem@davemloft•net>,
	clabbe.montjoie@gmail•com, peppe.cavallaro@st•com,
	alexandre.torgue@st•com, sergei.shtylyov@cogentembedded•com,
	f.fainelli@gmail•com, netdev@vger•kernel.org
Subject: [PATCH 3/3] net: stmmac: Prefer kcalloc() over kmalloc_array()
Date: Tue, 28 Mar 2017 15:57:06 +0200	[thread overview]
Message-ID: <20170328135706.7605-3-thierry.reding@gmail.com> (raw)
In-Reply-To: <20170328135706.7605-1-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia•com>

Some of the data in the new queue structures seems to not be properly
initialized, causing undefined behaviour (networking will work about 2
out of 10 tries). kcalloc() will zero the allocated memory and results
in 10 out of 10 successful boots.

Signed-off-by: Thierry Reding <treding@nvidia•com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ec5bba85c529..845320bc3333 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1412,13 +1412,12 @@ static void free_dma_desc_resources(struct stmmac_priv *priv)
 static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 {
 	u32 rx_count = priv->plat->rx_queues_to_use;
+	struct stmmac_rx_queue *rx_q;
 	int ret = -ENOMEM;
 	u32 queue = 0;
 
 	/* Allocate RX queues array */
-	priv->rx_queue = kmalloc_array(rx_count,
-				       sizeof(struct stmmac_rx_queue),
-				       GFP_KERNEL);
+	priv->rx_queue = kcalloc(rx_count, sizeof(*rx_q), GFP_KERNEL);
 	if (!priv->rx_queue) {
 		kfree(priv->rx_queue);
 		return -ENOMEM;
@@ -1426,20 +1425,19 @@ static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 
 	/* RX queues buffers and DMA */
 	for (queue = 0; queue < rx_count; queue++) {
-		struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
+		rx_q = &priv->rx_queue[queue];
 
 		rx_q->queue_index = queue;
 		rx_q->priv_data = priv;
 
-		rx_q->rx_skbuff_dma = kmalloc_array(DMA_RX_SIZE,
-							sizeof(dma_addr_t),
-							GFP_KERNEL);
+		rx_q->rx_skbuff_dma = kcalloc(DMA_RX_SIZE, sizeof(dma_addr_t),
+					      GFP_KERNEL);
 		if (!rx_q->rx_skbuff_dma)
 			goto err_dma_buffers;
 
-		rx_q->rx_skbuff = kmalloc_array(DMA_RX_SIZE,
-						    sizeof(struct sk_buff *),
-						    GFP_KERNEL);
+		rx_q->rx_skbuff = kcalloc(DMA_RX_SIZE,
+					  sizeof(struct sk_buff *),
+					  GFP_KERNEL);
 		if (!rx_q->rx_skbuff)
 			goto err_dma_buffers;
 
@@ -1477,33 +1475,32 @@ static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 static int alloc_tx_dma_desc_resources(struct stmmac_priv *priv)
 {
 	u32 tx_count = priv->plat->tx_queues_to_use;
+	struct stmmac_tx_queue *tx_q;
 	int ret = -ENOMEM;
 	u32 queue = 0;
 
 	/* Allocate TX queues array */
-	priv->tx_queue = kmalloc_array(tx_count,
-				       sizeof(struct stmmac_tx_queue),
-				       GFP_KERNEL);
+	priv->tx_queue = kcalloc(tx_count, sizeof(*tx_q), GFP_KERNEL);
 	if (!priv->tx_queue)
 		return -ENOMEM;
 
 	/* TX queues buffers and DMA */
 	for (queue = 0; queue < tx_count; queue++) {
-		struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue];
+		tx_q = &priv->tx_queue[queue];
 
 		tx_q->queue_index = queue;
 		tx_q->priv_data = priv;
 
-		tx_q->tx_skbuff_dma = kmalloc_array(DMA_TX_SIZE,
-					  sizeof(struct stmmac_tx_info),
-					  GFP_KERNEL);
+		tx_q->tx_skbuff_dma = kcalloc(DMA_TX_SIZE,
+					      sizeof(struct stmmac_tx_info),
+					      GFP_KERNEL);
 
 		if (!tx_q->tx_skbuff_dma)
 			goto err_dma_buffers;
 
-		tx_q->tx_skbuff = kmalloc_array(DMA_TX_SIZE,
-						    sizeof(struct sk_buff *),
-						    GFP_KERNEL);
+		tx_q->tx_skbuff = kcalloc(DMA_TX_SIZE,
+					  sizeof(struct sk_buff *),
+					  GFP_KERNEL);
 		if (!tx_q->tx_skbuff)
 			goto err_dma_buffers;
 
-- 
2.12.0

  parent reply	other threads:[~2017-03-28 13:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 17:16 [PATCH net-next 0/2] net: stmmac: multiple queue fixes Joao Pinto
2017-03-24 17:16 ` [PATCH net-next 1/2] net: stmmac: fix netdev release Joao Pinto
2017-03-24 17:16 ` [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll Joao Pinto
2017-03-25  7:26   ` Corentin Labbe
2017-03-27  9:04     ` Joao Pinto
2017-03-27  9:09       ` Corentin Labbe
2017-03-27  9:12         ` Joao Pinto
2017-03-27 13:28           ` Niklas Cassel
2017-03-27 13:34             ` Joao Pinto
2017-03-27 13:36               ` Joao Pinto
2017-03-27 15:26     ` Joao Pinto
2017-03-27 17:00       ` Corentin Labbe
2017-03-27 17:06         ` Joao Pinto
2017-03-27 18:43           ` Corentin Labbe
2017-03-27 17:28         ` David Miller
2017-03-27 17:44           ` Joao Pinto
2017-03-27 18:49             ` Corentin Labbe
2017-03-27 21:00             ` David Miller
2017-03-28 13:34             ` Niklas Cassel
2017-03-28 13:56               ` Thierry Reding
2017-03-28 13:57               ` [PATCH 1/3] net: stmmac: Remove unneeded checks for NULL pointer Thierry Reding
2017-03-28 13:57                 ` [PATCH 2/3] net: stmmac: Always use the number of configured TX queues Thierry Reding
2017-03-28 14:10                   ` Niklas Cassel
2017-03-28 14:29                     ` Thierry Reding
2017-03-28 13:57                 ` Thierry Reding [this message]
2017-03-29  8:51                   ` [PATCH 3/3] net: stmmac: Prefer kcalloc() over kmalloc_array() Niklas Cassel
2017-03-28 11:23 ` [PATCH net-next 0/2] net: stmmac: multiple queue fixes Niklas Cassel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170328135706.7605-3-thierry.reding@gmail.com \
    --to=thierry.reding@gmail$(echo .)com \
    --cc=Joao.Pinto@synopsys$(echo .)com \
    --cc=alexandre.torgue@st$(echo .)com \
    --cc=clabbe.montjoie@gmail$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=f.fainelli@gmail$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=niklas.cassel@axis$(echo .)com \
    --cc=peppe.cavallaro@st$(echo .)com \
    --cc=sergei.shtylyov@cogentembedded$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox