Skip to contentSkip to conversation

octeontx2-af: Fix pointer dereference before sanity check

PATCH In review Sai Krishna 2 participants 4 messages Jun 7, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 octeontx2-af: Fix pointer dereference before sanity check

PTP pointer is being dereferenced before NULL, error check. Fixed the same to avoid NULL dereference and smatch checker warning.

Fixes 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon")
---
 drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +3 -3
index 3411e2e47d46..6a7dfb181fa8 100644
@@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev)
 	struct ptp *ptp = pci_get_drvdata(pdev);
 	u64 clock_cfg;
 
-	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
-		hrtimer_cancel(&ptp->hrtimer);
-
 	if (IS_ERR_OR_NULL(ptp))
 		return;
 
+	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
+		hrtimer_cancel(&ptp->hrtimer);
+
 	/* Disable PTP clock */
 	clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
 	clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Sai Krishna

PTP pointer is being dereferenced before NULL, error check. Fixed the same to avoid NULL dereference and smatch checker warning.

please use imperative mood, you could say:
Move validation of ptp pointer before its usage

Quoted 4 lines
Fixes 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon")
Quoted 14 lines
---
 drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +0 -2
index 3411e2e47d46..6a7dfb181fa8 100644
@@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev)
 	struct ptp *ptp = pci_get_drvdata(pdev);
 	u64 clock_cfg;
 
-	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
-		hrtimer_cancel(&ptp->hrtimer);

drivers/net/ethernet/marvell/octeontx2/af/ptp.c static void ptp_remove(struct pci_dev *pdev) · line 460

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +3 -1
-
 	if (IS_ERR_OR_NULL(ptp))
 		return;
 
+	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
+		hrtimer_cancel(&ptp->hrtimer);
+
 	/* Disable PTP clock */
 	clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
 	clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;

i wonder if ptp_remove() would be able to free the struct ptp that ptp_probe() allocated - then you wouldn't have to use devm_kzalloc().

Quoted 4 lines
Signature · 1 line
2.25.1
#2 lore raw
Quoted 12 lines

-----Original Message-----
From: Maciej Fijalkowski <[email protected]>
Sent: Wednesday, June 7, 2023 5:17 PM
To: Sai Krishna Gajula <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Sunil Kovvuri Goutham <[email protected]>; [email protected]; Naveen Mamindlapalli <[email protected]>
Subject: Re: [net PATCH] octeontx2-af: Fix pointer dereference before sanity check

Quoted 7 lines
Quoted 2 lines · Sai Krishna

PTP pointer is being dereferenced before NULL, error check. Fixed the same to avoid NULL dereference and smatch checker warning.

please use imperative mood, you could say:
Move validation of ptp pointer before its usage

I will change in V2 patch.

Quoted 27 lines
Quoted 2 lines
Fixes 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on

CN10K silicon")

Quoted 2 lines

Review

Quoted 5 lines
---
 drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c

Quoted 13 lines

index 3411e2e47d46..6a7dfb181fa8 100644

drivers/net/ethernet/marvell/octeontx2/af/ptp.c +0 -3
@@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev)
 	struct ptp *ptp = pci_get_drvdata(pdev);
 	u64 clock_cfg;
 
-	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
-		hrtimer_cancel(&ptp->hrtimer);
-
 	if (IS_ERR_OR_NULL(ptp))
 		return;
 
Quoted 10 lines

drivers/net/ethernet/marvell/octeontx2/af/ptp.c static void ptp_remove(struct pci_dev *pdev) · line 460

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +3 -0
+	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
+		hrtimer_cancel(&ptp->hrtimer);
+
 	/* Disable PTP clock */
 	clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
 	clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;

i wonder if ptp_remove() would be able to free the struct ptp that ptp_probe() allocated - then you wouldn't have to use devm_kzalloc().

We intend to use devm_kzalloc() so that we do not need to call kfree in the remove function. Please let us know why you prefer to manually free the resource.

Thanks,
Sai

Quoted 4 lines
Quoted 4 lines

--
2.25.1

#3 lore raw
Quoted 58 lines · Sai Krishna Gajula
Quoted 12 lines

-----Original Message-----
From: Maciej Fijalkowski <[email protected]>
Sent: Wednesday, June 7, 2023 5:17 PM
To: Sai Krishna Gajula <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Sunil Kovvuri Goutham <[email protected]>; [email protected]; Naveen Mamindlapalli <[email protected]>
Subject: Re: [net PATCH] octeontx2-af: Fix pointer dereference before sanity check

Quoted 7 lines
Quoted 2 lines · Sai Krishna

PTP pointer is being dereferenced before NULL, error check. Fixed the same to avoid NULL dereference and smatch checker warning.

please use imperative mood, you could say:
Move validation of ptp pointer before its usage

I will change in V2 patch.

Quoted 27 lines
Quoted 2 lines
Fixes 2ef4e45d99b1 ("octeontx2-af: Add PTP PPS Errata workaround on

CN10K silicon")

Quoted 2 lines

Review

Quoted 5 lines
---
 drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c

Quoted 13 lines

index 3411e2e47d46..6a7dfb181fa8 100644

drivers/net/ethernet/marvell/octeontx2/af/ptp.c +0 -3
@@ -449,12 +449,12 @@ static void ptp_remove(struct pci_dev *pdev)
 	struct ptp *ptp = pci_get_drvdata(pdev);
 	u64 clock_cfg;
 
-	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
-		hrtimer_cancel(&ptp->hrtimer);
-
 	if (IS_ERR_OR_NULL(ptp))
 		return;
 
Quoted 10 lines

drivers/net/ethernet/marvell/octeontx2/af/ptp.c static void ptp_remove(struct pci_dev *pdev) · line 460

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +3 -0
+	if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
+		hrtimer_cancel(&ptp->hrtimer);
+
 	/* Disable PTP clock */
 	clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
 	clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;

i wonder if ptp_remove() would be able to free the struct ptp that ptp_probe() allocated - then you wouldn't have to use devm_kzalloc().

Quoted 3 lines

We intend to use devm_kzalloc() so that we do not need to call kfree in the remove function. Please let us know why you prefer to manually free the resource.

I just don't think this is really necessary as this object's lifetime scope is clearly defined, i am in the rush now but i can try to come up with further arguments later on if needed.

Quoted 7 lines

Thanks,
Sai

Quoted 4 lines
Quoted 4 lines

--
2.25.1