diff mbox

[2/3] net: cleanups in RX queue allocation

Message ID alpine.DEB.1.00.1010181056590.16238@pokey.mtv.corp.google.com
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Tom Herbert Oct. 18, 2010, 6:02 p.m. UTC
Clean up in RX queue allocation.  In netif_set_real_num_rx_queues
return error on attempt to set zero queues, and set
dev->num_rx_queues if device not registered (similar to TX
allocation).  In netif_alloc_rx_queues, do BUG_ON if queue
count is zero.

Signed-off-by: Tom Herbert <therbert@google.com>
---
 net/core/dev.c |   36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 deletions(-)

Comments

Ben Hutchings Oct. 18, 2010, 9:37 p.m. UTC | #1
On Mon, 2010-10-18 at 11:02 -0700, Tom Herbert wrote:
> Clean up in RX queue allocation.  In netif_set_real_num_rx_queues
> return error on attempt to set zero queues, and set
> dev->num_rx_queues if device not registered (similar to TX
> allocation).
[...]

John Fastabend just removed this assignment as it is apparently
undesirable for ixgbe.

Ben.
diff mbox

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index 76db105..77b860d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1583,6 +1583,9 @@  int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq)
 {
 	int rc;
 
+	if (rxq < 1)
+		return -EINVAL;
+
 	if (dev->reg_state == NETREG_REGISTERED) {
 		ASSERT_RTNL();
 
@@ -1593,7 +1596,8 @@  int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq)
 						  rxq);
 		if (rc)
 			return rc;
-	}
+	} else
+		dev->num_rx_queues = rxq;
 
 	dev->real_num_rx_queues = rxq;
 	return 0;
@@ -5013,25 +5017,23 @@  static int netif_alloc_rx_queues(struct net_device *dev)
 {
 #ifdef CONFIG_RPS
 	unsigned int i, count = dev->num_rx_queues;
+	struct netdev_rx_queue *rx;
 
-	if (count) {
-		struct netdev_rx_queue *rx;
-
-		rx = kcalloc(count, sizeof(struct netdev_rx_queue), GFP_KERNEL);
-		if (!rx) {
-			pr_err("netdev: Unable to allocate %u rx queues.\n",
-			       count);
-			return -ENOMEM;
-		}
-		dev->_rx = rx;
+	BUG_ON(count < 1);
 
-		/*
-		 * Set a pointer to first element in the array which holds the
-		 * reference count.
-		 */
-		for (i = 0; i < count; i++)
-			rx[i].first = rx;
+	rx = kcalloc(count, sizeof(struct netdev_rx_queue), GFP_KERNEL);
+	if (!rx) {
+		pr_err("netdev: Unable to allocate %u rx queues.\n", count);
+		return -ENOMEM;
 	}
+	dev->_rx = rx;
+
+	/*
+	 * Set a pointer to first element in the array which holds the
+	 * reference count.
+	 */
+	for (i = 0; i < count; i++)
+		rx[i].first = rx;
 #endif
 	return 0;
 }