drivers: atm: eni: Add pci_dma_mapping_error() call
authorTina Johnson <tinajohnson.1234@gmail.com>
Thu, 20 Nov 2014 10:24:54 +0000 (15:54 +0530)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Nov 2014 20:03:40 +0000 (15:03 -0500)
Added a pci_dma_mapping_error() call to check for mapping errors before
further using the dma handle. In case of error, control goes to a new label
where the incoming skb is freed. 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>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/atm/eni.c

index d65975aba4ecfdd3297d0fc1ad8151f6560b1fda..c7fab3ee14eef1e28af86e69a253925d30f491ea 100644 (file)
@@ -356,6 +356,8 @@ static int do_rx_dma(struct atm_vcc *vcc,struct sk_buff *skb,
        if (skb) {
                paddr = pci_map_single(eni_dev->pci_dev,skb->data,skb->len,
                    PCI_DMA_FROMDEVICE);
+               if (pci_dma_mapping_error(eni_dev->pci_dev, paddr))
+                       goto dma_map_error;
                ENI_PRV_PADDR(skb) = paddr;
                if (paddr & 3)
                        printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d has "
@@ -481,6 +483,7 @@ trouble:
        if (paddr)
                pci_unmap_single(eni_dev->pci_dev,paddr,skb->len,
                    PCI_DMA_FROMDEVICE);
+dma_map_error:
        if (skb) dev_kfree_skb_irq(skb);
        return -1;
 }