summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEvgeny Novikov <novikov@ispras.ru>2020-10-02 17:01:55 +0200
committerFelipe Balbi <balbi@kernel.org>2020-10-27 09:55:45 +0100
commit0d66e04875c5aae876cf3d4f4be7978fa2b00523 (patch)
tree7b14d2c0967c1b34359efc24d85bfd072094e21c /drivers
parentusb: dwc3: pci: add support for the Intel Alder Lake-S (diff)
downloadlinux-0d66e04875c5aae876cf3d4f4be7978fa2b00523.tar.xz
linux-0d66e04875c5aae876cf3d4f4be7978fa2b00523.zip
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/udc/goku_udc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c
index 25c1d6ab5adb..3e1267d38774 100644
--- a/drivers/usb/gadget/udc/goku_udc.c
+++ b/drivers/usb/gadget/udc/goku_udc.c
@@ -1760,6 +1760,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto err;
}
+ pci_set_drvdata(pdev, dev);
spin_lock_init(&dev->lock);
dev->pdev = pdev;
dev->gadget.ops = &goku_ops;
@@ -1793,7 +1794,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
}
dev->regs = (struct goku_udc_regs __iomem *) base;
- pci_set_drvdata(pdev, dev);
INFO(dev, "%s\n", driver_desc);
INFO(dev, "version: " DRIVER_VERSION " %s\n", dmastr());
INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base);