Skip to contentSkip to conversation

staging: comedi: addi_apci_3xxx: check return value

PATCH In review Pan Bian 2 participants 2 messages Apr 23, 2017 – Apr 24, 2017 Staging

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 staging: comedi: addi_apci_3xxx: check return value

From: Pan Bian <[email protected]>

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.

---
 drivers/staging/comedi/drivers/addi_apci_3xxx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/comedi/drivers/addi_apci_3xxx.c +2 -0
index b6af3eb..a07d5bd 100644
@@ -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,
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Pan Bian

From: Pan Bian <[email protected]>

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.

---
 drivers/staging/comedi/drivers/addi_apci_3xxx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/comedi/drivers/addi_apci_3xxx.c +0 -0
index b6af3eb..a07d5bd 100644

drivers/staging/comedi/drivers/addi_apci_3xxx.c static int apci3xxx_auto_attach(struct comedi_device *dev, · line 794

Quoted 8 lines
drivers/staging/comedi/drivers/addi_apci_3xxx.c +2 -0
@@ -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,

Looks good. Thanks for the fix.

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]> )=-
-=(                          Web: http://www.mev.co.uk/  )=-