net: libwx: fix memory leak in wx_setup_rx_resources
authorZhengchao Shao <shaozhengchao@huawei.com>
Tue, 18 Apr 2023 06:54:50 +0000 (14:54 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 20 Apr 2023 13:39:15 +0000 (15:39 +0200)
When wx_alloc_page_pool() failed in wx_setup_rx_resources(), it doesn't
release DMA buffer. Add dma_free_coherent() in the error path to release
the DMA buffer.

Fixes: 850b971110b2 ("net: libwx: Allocate Rx and Tx resources")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230418065450.2268522-1-shaozhengchao@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/wangxun/libwx/wx_lib.c

index eb89a274083e79d02b3ac632084a72618ce318df..1e8d8b7b0c62e2b1c38a39e97d0e8488b09f5ec6 100644 (file)
@@ -1798,10 +1798,13 @@ static int wx_setup_rx_resources(struct wx_ring *rx_ring)
        ret = wx_alloc_page_pool(rx_ring);
        if (ret < 0) {
                dev_err(rx_ring->dev, "Page pool creation failed: %d\n", ret);
-               goto err;
+               goto err_desc;
        }
 
        return 0;
+
+err_desc:
+       dma_free_coherent(dev, rx_ring->size, rx_ring->desc, rx_ring->dma);
 err:
        kvfree(rx_ring->rx_buffer_info);
        rx_ring->rx_buffer_info = NULL;