1
0
Fork 0

net: cleanups in RX queue allocation

Clean up in RX queue allocation.  In netif_set_real_num_rx_queues
return error on attempt to set zero queues, or requested number is
greater than number of allocated queues.  In netif_alloc_rx_queues,
do BUG_ON if queue_count is zero.

Signed-off-by: Tom Herbert <therbert@google.com>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
hifive-unleashed-5.1
Tom Herbert 2010-10-18 18:00:16 +00:00 committed by David S. Miller
parent 55513fb428
commit bd25fa7ba5
1 changed files with 17 additions and 19 deletions

View File

@ -1583,12 +1583,12 @@ int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq)
{
int rc;
if (rxq < 1 || rxq > dev->num_rx_queues)
return -EINVAL;
if (dev->reg_state == NETREG_REGISTERED) {
ASSERT_RTNL();
if (rxq > dev->num_rx_queues)
return -EINVAL;
rc = net_rx_queue_update_kobjects(dev, dev->real_num_rx_queues,
rxq);
if (rc)
@ -5013,25 +5013,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;
BUG_ON(count < 1);
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;
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;
}