From: Jonathan Lemon <jonathan.lemon@gmail.com>
Date: Thu, 5 Aug 2021 12:52:43 -0700
Subject: ptp: ocp: Fix the error handling path for the class device.
Patch-mainline: v5.15-rc1
Git-commit: d12f23fa5142594796a0498d11b5f21463060dac
References: jsc#SLE-19253
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>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
drivers/ptp/ptp_ocp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -1381,7 +1381,6 @@ ptp_ocp_device_init(struct ptp_ocp *bp,
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,
out:
ptp_ocp_dev_release(&bp->dev);
+ put_device(&bp->dev);
return err;
}