qlcnic: cleanup skb allocation
authorAmit Kumar Salecha <amit.salecha@qlogic.com>
Tue, 22 Jun 2010 03:18:58 +0000 (03:18 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 23 Jun 2010 20:16:28 +0000 (13:16 -0700)
No need to maintian separate state for alloced and freed skb.
This can be done by null check.

Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/qlcnic/qlcnic.h
drivers/net/qlcnic/qlcnic_ethtool.c
drivers/net/qlcnic/qlcnic_init.c

index 99ccdd8ac41966ecc4142b515a2975cf2e63775a..86e47811c25bbe33d43c8cc10f0f384c50e362b7 100644 (file)
@@ -381,7 +381,6 @@ struct qlcnic_rx_buffer {
        struct sk_buff *skb;
        u64 dma;
        u16 ref_handle;
-       u16 state;
 };
 
 /* Board types */
@@ -423,7 +422,6 @@ struct qlcnic_adapter_stats {
        u64  xmit_on;
        u64  xmit_off;
        u64  skb_alloc_failure;
-       u64  null_skb;
        u64  null_rxbuf;
        u64  rx_dma_map_error;
        u64  tx_dma_map_error;
index 3e4822ad5a8076e3bc747c3cef32ec45e7a28a7c..a4f112022715cefdc615074efa593f728a038dbf 100644 (file)
@@ -69,8 +69,6 @@ static const struct qlcnic_stats qlcnic_gstrings_stats[] = {
                QLC_SIZEOF(stats.xmit_off), QLC_OFF(stats.xmit_off)},
        {"skb_alloc_failure", QLC_SIZEOF(stats.skb_alloc_failure),
                QLC_OFF(stats.skb_alloc_failure)},
-       {"null skb",
-               QLC_SIZEOF(stats.null_skb), QLC_OFF(stats.null_skb)},
        {"null rxbuf",
                QLC_SIZEOF(stats.null_rxbuf), QLC_OFF(stats.null_rxbuf)},
        {"rx dma map error", QLC_SIZEOF(stats.rx_dma_map_error),
index 058ce61501c357e6d27a4d9deb402799ae5e0c09..1c3d5a90d21a04d3213dff3766ba744e6b47c85b 100644 (file)
@@ -112,14 +112,15 @@ void qlcnic_release_rx_buffers(struct qlcnic_adapter *adapter)
                rds_ring = &recv_ctx->rds_rings[ring];
                for (i = 0; i < rds_ring->num_desc; ++i) {
                        rx_buf = &(rds_ring->rx_buf_arr[i]);
-                       if (rx_buf->state == QLCNIC_BUFFER_FREE)
+                       if (rx_buf->skb == NULL)
                                continue;
+
                        pci_unmap_single(adapter->pdev,
                                        rx_buf->dma,
                                        rds_ring->dma_size,
                                        PCI_DMA_FROMDEVICE);
-                       if (rx_buf->skb != NULL)
-                               dev_kfree_skb_any(rx_buf->skb);
+
+                       dev_kfree_skb_any(rx_buf->skb);
                }
        }
 }
@@ -266,7 +267,6 @@ int qlcnic_alloc_sw_resources(struct qlcnic_adapter *adapter)
                        list_add_tail(&rx_buf->list,
                                        &rds_ring->free_list);
                        rx_buf->ref_handle = i;
-                       rx_buf->state = QLCNIC_BUFFER_FREE;
                        rx_buf++;
                }
                spin_lock_init(&rds_ring->lock);
@@ -1281,14 +1281,12 @@ qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
        dma_addr_t dma;
        struct pci_dev *pdev = adapter->pdev;
 
-       buffer->skb = dev_alloc_skb(rds_ring->skb_size);
-       if (!buffer->skb) {
+       skb = dev_alloc_skb(rds_ring->skb_size);
+       if (!skb) {
                adapter->stats.skb_alloc_failure++;
                return -ENOMEM;
        }
 
-       skb = buffer->skb;
-
        skb_reserve(skb, 2);
 
        dma = pci_map_single(pdev, skb->data,
@@ -1297,13 +1295,11 @@ qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
        if (pci_dma_mapping_error(pdev, dma)) {
                adapter->stats.rx_dma_map_error++;
                dev_kfree_skb_any(skb);
-               buffer->skb = NULL;
                return -ENOMEM;
        }
 
        buffer->skb = skb;
        buffer->dma = dma;
-       buffer->state = QLCNIC_BUFFER_BUSY;
 
        return 0;
 }
@@ -1316,14 +1312,15 @@ static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
 
        buffer = &rds_ring->rx_buf_arr[index];
 
+       if (unlikely(buffer->skb == NULL)) {
+               WARN_ON(1);
+               return NULL;
+       }
+
        pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size,
                        PCI_DMA_FROMDEVICE);
 
        skb = buffer->skb;
-       if (!skb) {
-               adapter->stats.null_skb++;
-               goto no_skb;
-       }
 
        if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) {
                adapter->stats.csummed++;
@@ -1335,8 +1332,7 @@ static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
        skb->dev = adapter->netdev;
 
        buffer->skb = NULL;
-no_skb:
-       buffer->state = QLCNIC_BUFFER_FREE;
+
        return skb;
 }
 
@@ -1511,7 +1507,7 @@ qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
 
                WARN_ON(desc_cnt > 1);
 
-               if (rxbuf)
+               if (likely(rxbuf))
                        list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
                else
                        adapter->stats.null_rxbuf++;