diff options
author | Sieng-Piaw Liew <liew.s.piaw@gmail.com> | 2022-07-19 08:20:45 +0800 |
---|---|---|
committer | Álvaro Fernández Rojas <noltari@gmail.com> | 2023-03-04 19:28:16 +0100 |
commit | 65ebe311304a32423a46bf4efe62f29cda06acab (patch) | |
tree | d188c5b99064e38668ce8cb18289a3124a334432 /target/linux/bmips/files | |
parent | a6a54135ef7dca13a3f042afe83a99ce0218622c (diff) | |
download | upstream-65ebe311304a32423a46bf4efe62f29cda06acab.tar.gz upstream-65ebe311304a32423a46bf4efe62f29cda06acab.tar.bz2 upstream-65ebe311304a32423a46bf4efe62f29cda06acab.zip |
bmips: check for DMA error when refilling Rx
dma_mapping_error() should be called as dma_map_single() could fail and
return error.
Signed-off-by: Sieng-Piaw Liew <liew.s.piaw@gmail.com>
Diffstat (limited to 'target/linux/bmips/files')
-rw-r--r-- | target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c b/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c index c655ae8d27..64736ebf61 100644 --- a/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c +++ b/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c @@ -270,6 +270,7 @@ static int bcm6368_enetsw_refill_rx(struct net_device *dev, bool napi_mode) if (!priv->rx_buf[desc_idx]) { unsigned char *buf; + dma_addr_t p; if (likely(napi_mode)) buf = napi_alloc_frag(priv->rx_frag_size); @@ -279,11 +280,15 @@ static int bcm6368_enetsw_refill_rx(struct net_device *dev, bool napi_mode) if (unlikely(!buf)) break; + p = dma_map_single(&priv->pdev->dev, buf + NET_SKB_PAD, + priv->rx_buf_size, DMA_FROM_DEVICE); + if (unlikely(dma_mapping_error(&priv->pdev->dev, p))) { + skb_free_frag(buf); + break; + } + priv->rx_buf[desc_idx] = buf; - desc->address = dma_map_single(&priv->pdev->dev, - buf + NET_SKB_PAD, - priv->rx_buf_size, - DMA_FROM_DEVICE); + desc->address = p; } len_stat = priv->rx_buf_size << DMADESC_LENGTH_SHIFT; @@ -563,6 +568,7 @@ bcm6368_enetsw_start_xmit(struct sk_buff *skb, struct net_device *dev) struct bcm6368_enetsw_desc *desc; u32 len_stat; netdev_tx_t ret; + dma_addr_t p; /* lock against tx reclaim */ spin_lock(&priv->tx_lock); @@ -597,13 +603,19 @@ bcm6368_enetsw_start_xmit(struct sk_buff *skb, struct net_device *dev) data = skb_put_zero(skb, needed); } + /* fill descriptor */ + p = dma_map_single(&priv->pdev->dev, skb->data, skb->len, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(&priv->pdev->dev, p))) { + dev_kfree_skb(skb); + ret = NETDEV_TX_OK; + goto out_unlock; + } + /* point to the next available desc */ desc = &priv->tx_desc_cpu[priv->tx_curr_desc]; priv->tx_skb[priv->tx_curr_desc] = skb; - - /* fill descriptor */ - desc->address = dma_map_single(&priv->pdev->dev, skb->data, skb->len, - DMA_TO_DEVICE); + desc->address = p; len_stat = (skb->len << DMADESC_LENGTH_SHIFT) & DMADESC_LENGTH_MASK; len_stat |= DMADESC_ESOP_MASK | DMADESC_APPEND_CRC | |