staging: comedi: addi_apci_3xxx: check return value
authorPan Bian <bianpan2016@163.com>
Sun, 23 Apr 2017 09:52:55 +0000 (17:52 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 25 Apr 2017 18:43:42 +0000 (20:43 +0200)
Function pci_ioremap_bar() will return a NULL pointer if there is no
enough memory. However, in function apci3xxx_auto_attach(), the return
value of function pci_ioremap_bar() is not validated. This may result in
NULL dereference in following access to dev->mmio. This patch fixes the
bug.

Signed-off-by: Pan Bian <bianpan2016@163.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/addi_apci_3xxx.c

index 82c22110f128e127ae85401cad624eab7d925dc6..be1f6133ff1c8a08f78130810970a515fc01d20f 100644 (file)
@@ -787,6 +787,8 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
 
        dev->iobase = pci_resource_start(pcidev, 2);
        dev->mmio = pci_ioremap_bar(pcidev, 3);
+       if (!dev->mmio)
+               return -ENOMEM;
 
        if (pcidev->irq > 0) {
                ret = request_irq(pcidev->irq, apci3xxx_irq_handler,