Skip to content

Commit

Permalink
firewire: nosy: do not ignore errors in ioremap_nocache()
Browse files Browse the repository at this point in the history
There is no check if ioremap_nocache() returns a valid pointer.
Potentially it can lead to null pointer dereference.

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

Signed-off-by: Alexey Khoroshilov <[email protected]>
Signed-off-by: Stefan Richter <[email protected]> (renamed goto labels)
  • Loading branch information
khoroshilov authored and Stefan Richter committed Oct 9, 2016
1 parent c8d2bc9 commit 6449e31
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/firewire/nosy.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)

lynx->registers = ioremap_nocache(pci_resource_start(dev, 0),
PCILYNX_MAX_REGISTER);
if (lynx->registers == NULL) {
dev_err(&dev->dev, "Failed to map registers\n");
ret = -ENOMEM;
goto fail_deallocate_lynx;
}

lynx->rcv_start_pcl = pci_alloc_consistent(lynx->pci_device,
sizeof(struct pcl), &lynx->rcv_start_pcl_bus);
Expand All @@ -578,7 +583,7 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
lynx->rcv_buffer == NULL) {
dev_err(&dev->dev, "Failed to allocate receive buffer\n");
ret = -ENOMEM;
goto fail_deallocate;
goto fail_deallocate_buffers;
}
lynx->rcv_start_pcl->next = cpu_to_le32(lynx->rcv_pcl_bus);
lynx->rcv_pcl->next = cpu_to_le32(PCL_NEXT_INVALID);
Expand Down Expand Up @@ -641,7 +646,7 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
dev_err(&dev->dev,
"Failed to allocate shared interrupt %d\n", dev->irq);
ret = -EIO;
goto fail_deallocate;
goto fail_deallocate_buffers;
}

lynx->misc.parent = &dev->dev;
Expand All @@ -668,7 +673,7 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
reg_write(lynx, PCI_INT_ENABLE, 0);
free_irq(lynx->pci_device->irq, lynx);

fail_deallocate:
fail_deallocate_buffers:
if (lynx->rcv_start_pcl)
pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
Expand All @@ -679,6 +684,8 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
pci_free_consistent(lynx->pci_device, PAGE_SIZE,
lynx->rcv_buffer, lynx->rcv_buffer_bus);
iounmap(lynx->registers);

fail_deallocate_lynx:
kfree(lynx);

fail_disable:
Expand Down

0 comments on commit 6449e31

Please sign in to comment.