net: hns3: fix ethtool tx copybreak buf size indicating not aligned issue
[linux-2.6-microblaze.git] / drivers / net / ethernet / hisilicon / hns3 / hns3_enet.c
index 0b8a73c..1613723 100644 (file)
@@ -1028,13 +1028,12 @@ static bool hns3_can_use_tx_sgl(struct hns3_enet_ring *ring,
 
 static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)
 {
+       u32 alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;
        struct hns3_tx_spare *tx_spare;
        struct page *page;
-       u32 alloc_size;
        dma_addr_t dma;
        int order;
 
-       alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;
        if (!alloc_size)
                return;
 
@@ -1044,30 +1043,35 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)
        if (!tx_spare) {
                /* The driver still work without the tx spare buffer */
                dev_warn(ring_to_dev(ring), "failed to allocate hns3_tx_spare\n");
-               return;
+               goto devm_kzalloc_error;
        }
 
        page = alloc_pages_node(dev_to_node(ring_to_dev(ring)),
                                GFP_KERNEL, order);
        if (!page) {
                dev_warn(ring_to_dev(ring), "failed to allocate tx spare pages\n");
-               devm_kfree(ring_to_dev(ring), tx_spare);
-               return;
+               goto alloc_pages_error;
        }
 
        dma = dma_map_page(ring_to_dev(ring), page, 0,
                           PAGE_SIZE << order, DMA_TO_DEVICE);
        if (dma_mapping_error(ring_to_dev(ring), dma)) {
                dev_warn(ring_to_dev(ring), "failed to map pages for tx spare\n");
-               put_page(page);
-               devm_kfree(ring_to_dev(ring), tx_spare);
-               return;
+               goto dma_mapping_error;
        }
 
        tx_spare->dma = dma;
        tx_spare->buf = page_address(page);
        tx_spare->len = PAGE_SIZE << order;
        ring->tx_spare = tx_spare;
+       return;
+
+dma_mapping_error:
+       put_page(page);
+alloc_pages_error:
+       devm_kfree(ring_to_dev(ring), tx_spare);
+devm_kzalloc_error:
+       ring->tqp->handle->kinfo.tx_spare_buf_size = 0;
 }
 
 /* Use hns3_tx_spare_space() to make sure there is enough buffer