Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45af5500 authored by Alexey Khoroshilov's avatar Alexey Khoroshilov Committed by David S. Miller
Browse files

natsemi: add checks for dma mapping errors



refill_rx() and start_tx() do not check if mapping dma memory succeed.
The patch adds the checks and failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 179ccc0a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1937,6 +1937,12 @@ static void refill_rx(struct net_device *dev)
				break; /* Better luck next round. */
			np->rx_dma[entry] = pci_map_single(np->pci_dev,
				skb->data, buflen, PCI_DMA_FROMDEVICE);
			if (pci_dma_mapping_error(np->pci_dev,
						  np->rx_dma[entry])) {
				dev_kfree_skb_any(skb);
				np->rx_skbuff[entry] = NULL;
				break; /* Better luck next round. */
			}
			np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]);
		}
		np->rx_ring[entry].cmd_status = cpu_to_le32(np->rx_buf_sz);
@@ -2093,6 +2099,12 @@ static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev)
	np->tx_skbuff[entry] = skb;
	np->tx_dma[entry] = pci_map_single(np->pci_dev,
				skb->data,skb->len, PCI_DMA_TODEVICE);
	if (pci_dma_mapping_error(np->pci_dev, np->tx_dma[entry])) {
		np->tx_skbuff[entry] = NULL;
		dev_kfree_skb_irq(skb);
		dev->stats.tx_dropped++;
		return NETDEV_TX_OK;
	}

	np->tx_ring[entry].addr = cpu_to_le32(np->tx_dma[entry]);