[PATCH] staging: mt7621-eth: Refactor RX ring resource allocation and cleanup
Greg Kroah-Hartman
gregkh at linuxfoundation.org
Sun May 20 12:40:46 UTC 2018
On Fri, May 18, 2018 at 08:33:27PM +0300, Kamal Heib wrote:
> Simplify the code of allocate and cleanup RX ring resources by using
> helper functions, also make sure to free the allocated resources in
> cause of allocation failure.
>
> Signed-off-by: Kamal Heib <kamalheib1 at gmail.com>
> ---
> drivers/staging/mt7621-eth/mtk_eth_soc.c | 122 ++++++++++++++++++++-----------
> 1 file changed, 81 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/staging/mt7621-eth/mtk_eth_soc.c b/drivers/staging/mt7621-eth/mtk_eth_soc.c
> index 2c7a2e666bfb..16cd514e9790 100644
> --- a/drivers/staging/mt7621-eth/mtk_eth_soc.c
> +++ b/drivers/staging/mt7621-eth/mtk_eth_soc.c
> @@ -278,38 +278,87 @@ static inline void mtk_set_txd_pdma(struct mtk_tx_dma *txd,
> WRITE_ONCE(dma_txd->txd2, txd->txd2);
> }
>
> -static void mtk_clean_rx(struct mtk_eth *eth, struct mtk_rx_ring *ring)
> +static void mtk_rx_unmap_dma(struct mtk_eth *eth, struct mtk_rx_ring *ring)
> {
> int i;
>
> - if (ring->rx_data && ring->rx_dma) {
> - for (i = 0; i < ring->rx_ring_size; i++) {
> - if (!ring->rx_data[i])
> - continue;
> - if (!ring->rx_dma[i].rxd1)
> - continue;
> + for (i = 0; i < ring->rx_ring_size; i++) {
> + if (ring->rx_dma[i].rxd1)
> dma_unmap_single(eth->dev,
> ring->rx_dma[i].rxd1,
> ring->rx_buf_size,
> DMA_FROM_DEVICE);
> + }
> +}
> +
> +static int mtk_rx_map_dma(struct mtk_eth *eth, struct mtk_rx_ring *ring)
> +{
> + int i, pad;
> +
> + if (!eth->soc->rx_2b_offset)
> + pad = NET_IP_ALIGN;
> +
> + for (i = 0; i < ring->rx_ring_size; i++) {
> + dma_addr_t dma_addr = dma_map_single(eth->dev,
> + ring->rx_data[i] + NET_SKB_PAD + pad,
> + ring->rx_buf_size,
> + DMA_FROM_DEVICE);
> + if (unlikely(dma_mapping_error(eth->dev, dma_addr)))
> + goto unmap_dma;
Only use unlikely/likely if you can measure the difference without using
it. Almost always the compiler/processor will do better than you ever
will. The last time this was measured, humans got it wrong over 80% of
the time incorrect.
So please drop, unless you can measure it.
thanks,
greg k-h
More information about the devel
mailing list