ptp: ocp: Fix the error handling path for the class device.

Move the put_device() call to the error handling path, so the
device is released after the .release callback, avoiding a
use-after-free.

Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jonathan Lemon 2021-08-05 12:52:43 -07:00 committed by David S. Miller
parent 596690e9f4
commit d12f23fa51
1 changed files with 1 additions and 1 deletions

View File

@ -1381,7 +1381,6 @@ ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
err = device_add(&bp->dev);
if (err) {
dev_err(&bp->dev, "device add failed: %d\n", err);
put_device(&bp->dev);
goto out;
}
@ -1391,6 +1390,7 @@ ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
out:
ptp_ocp_dev_release(&bp->dev);
put_device(&bp->dev);
return err;
}