Skip to content

Commit 0d66e04

Browse files
eunovmfelipebalbi
authored andcommitted
usb: gadget: goku_udc: fix potential crashes in probe
goku_probe() goes to error label "err" and invokes goku_remove() in case of failures of pci_enable_device(), pci_resource_start() and ioremap(). goku_remove() gets a device from pci_get_drvdata(pdev) and works with it without any checks, in particular it dereferences a corresponding pointer. But goku_probe() did not set this device yet. So, one can expect various crashes. The patch moves setting the device just after allocation of memory for it. Found by Linux Driver Verification project (linuxtesting.org). Reported-by: Pavel Andrianov <andrianov@ispras.ru> Signed-off-by: Evgeny Novikov <novikov@ispras.ru> Signed-off-by: Felipe Balbi <balbi@kernel.org>
1 parent 1384ab4 commit 0d66e04

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/usb/gadget/udc/goku_udc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
17601760
goto err;
17611761
}
17621762

1763+
pci_set_drvdata(pdev, dev);
17631764
spin_lock_init(&dev->lock);
17641765
dev->pdev = pdev;
17651766
dev->gadget.ops = &goku_ops;
@@ -1793,7 +1794,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
17931794
}
17941795
dev->regs = (struct goku_udc_regs __iomem *) base;
17951796

1796-
pci_set_drvdata(pdev, dev);
17971797
INFO(dev, "%s\n", driver_desc);
17981798
INFO(dev, "version: " DRIVER_VERSION " %s\n", dmastr());
17991799
INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base);

0 commit comments

Comments
 (0)