diff mbox

drivers: infiniband: hw: Add pci_dma_mapping_error() call

Message ID 1417281677-7133-1-git-send-email-tinajohnson.1234@gmail.com (mailing list archive)
State Rejected
Headers show

Commit Message

Tina Johnson Nov. 29, 2014, 5:21 p.m. UTC
Added a pci_dma_mapping_error() call to check for mapping errors before
further using the dma handle. The previously allocated skb is freed in
case of a mapping error. Unchecked dma handles were found using Coccinelle:

@rule1@
expression e1;
identifier x;
@@

*x = pci_map_single(...);
 ... when != pci_dma_mapping_error(e1,x)

Signed-off-by: Tina Johnson <tinajohnson.1234@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/infiniband/hw/amso1100/c2.c |    4 ++++
 1 file changed, 4 insertions(+)
diff mbox

Patch

diff --git a/drivers/infiniband/hw/amso1100/c2.c b/drivers/infiniband/hw/amso1100/c2.c
index 766a71c..c623e82 100644
--- a/drivers/infiniband/hw/amso1100/c2.c
+++ b/drivers/infiniband/hw/amso1100/c2.c
@@ -231,6 +231,10 @@  static inline int c2_rx_alloc(struct c2_port *c2_port, struct c2_element *elem)
 	mapaddr =
 	    pci_map_single(c2dev->pcidev, skb->data, maplen,
 			   PCI_DMA_FROMDEVICE);
+	if (pci_dma_mapping_error(c2dev->pcidev, mapaddr)) {
+		dev_kfree_skb(skb);
+		return -ENOMEM;
+	}
 
 	/* Set the sk_buff RXP_header to RXP_HRXD_READY */
 	rxp_hdr = (struct c2_rxp_hdr *) skb->data;