[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190412141327.2122-1-colin.king@canonical.com>
Date: Fri, 12 Apr 2019 15:13:27 +0100
From: Colin King <colin.king@...onical.com>
To: Ariel Elior <aelior@...vell.com>, GR-everest-linux-l2@...vell.com,
"David S . Miller" <davem@...emloft.net>, netdev@...r.kernel.org
Cc: kernel-janitors@...r.kernel.org
Subject: [PATCH] qede: fix write to free'd pointer error and double free of ptp
From: Colin Ian King <colin.king@...onical.com>
The err2 error return path calls qede_ptp_disable that cleans up
on an error and frees ptp. After this, the free'd ptp is dereferenced
when ptp->clock is set to NULL and the code falls-through to error
path err1 that frees ptp again.
Fix this by calling qede_ptp_disable and exiting via an error
return path that does not set ptp->clock or kfree ptp.
Addresses-Coverity: ("Write to pointer after free")
Fixes: 035744975aec ("qede: Add support for PTP resource locking.")
Signed-off-by: Colin Ian King <colin.king@...onical.com>
---
drivers/net/ethernet/qlogic/qede/qede_ptp.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 5f3f42a25361..7923dbd3b810 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -490,18 +490,17 @@ int qede_ptp_enable(struct qede_dev *edev, bool init_tc)
ptp->clock = ptp_clock_register(&ptp->clock_info, &edev->pdev->dev);
if (IS_ERR(ptp->clock)) {
- rc = -EINVAL;
DP_ERR(edev, "PTP clock registration failed\n");
- goto err2;
+ qede_ptp_disable(edev);
+ rc = -EINVAL;
+ goto err2;
}
return 0;
-err2:
- qede_ptp_disable(edev);
- ptp->clock = NULL;
err1:
kfree(ptp);
+err2:
edev->ptp = NULL;
return rc;
--
2.20.1
Powered by blists - more mailing lists