Skip to contentSkip to conversation

cxl/pci: Fix potential bogus return value upon successful probing

PATCH Superseded Davidlohr Bueso 4 participants 5 messages Nov 14, 2024 – Nov 15, 2024 CXL

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Davidlohr Bueso

author maintainer
#0 lore raw

PATCH 1/1 cxl/pci: Fix potential bogus return value upon successful probing

If cxl_pci_ras_unmask() returns non-zero, cxl_pci_probe() will end up returning that value, instead of zero. Found by code inspeaction.

Fixes 248529edc86 (cxl: add RAS status unmasking for CXL)
---
 drivers/cxl/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/pci.c +1 -1
index 188412d45e0d..01092e5b3b46 100644
@@ -948,7 +948,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	pci_save_state(pdev);
 
-	return rc;
+	return 0;
 }
 
 static const struct pci_device_id cxl_mem_pci_tbl[] = {
Signature · 1 line
2.47.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Davidlohr Bueso

If cxl_pci_ras_unmask() returns non-zero, cxl_pci_probe() will end up returning that value, instead of zero. Found by code inspeaction.

/inspeaction/inspection/

Other than that,

Fan

Quoted 20 lines
Fixes 248529edc86 (cxl: add RAS status unmasking for CXL)
---
 drivers/cxl/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/pci.c +1 -1
index 188412d45e0d..01092e5b3b46 100644
@@ -948,7 +948,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	pci_save_state(pdev);
 
-	return rc;
+	return 0;
 }
 
 static const struct pci_device_id cxl_mem_pci_tbl[] = {
Signature · 1 line
Fan Ni
maintainer
#2 lore raw
In reply to Davidlohr Bueso
Quoted 3 lines · Davidlohr Bueso

If cxl_pci_ras_unmask() returns non-zero, cxl_pci_probe() will end up returning that value, instead of zero. Found by code inspeaction.

I agree that the return value should be 0 if we get this far, because all rc's that need to be returned, are returned immediately.

But...the set and check of 'rc' for the calls cannot lead to a 'return rc' seems like a bad pattern. Most of those are dev_dbg() messages.

This last one that bit us here, is repeating the same pattern of those before it:

	rc = cxl_pci_ras_unmask(pdev);
        if (rc)
                dev_dbg(&pdev->dev, "No RAS reporting unmasked\n");

This can be:

	if (cxl_pci_ras_unmask(pdev))
		dev_dbg(&pdev->dev, "No RAS reporting unmasked\n");

There are a bunch that follow this pattern in that function, mostly in the pmu_count loop.

How about tidying up the rc pattern throughout the function?

--Alison

Quoted 30 lines
Fixes 248529edc86 (cxl: add RAS status unmasking for CXL)
---
 drivers/cxl/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/pci.c +1 -1
index 188412d45e0d..01092e5b3b46 100644
@@ -948,7 +948,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	pci_save_state(pdev);
 
-	return rc;
+	return 0;
 }
 
 

static const struct pci_device_id cxl_mem_pci_tbl[] = {

Signature · 1 line
2.47.0
author maintainer
#3 lore raw

On Thu, 14 Nov 2024, Alison Schofield wrote:\n

Quoted 4 lines

This can be:

	if (cxl_pci_ras_unmask(pdev))
		dev_dbg(&pdev->dev, "No RAS reporting unmasked\n");

Yeah, it later occured to me that this was better. Will send a v2.

Quoted 5 lines

There are a bunch that follow this pattern in that function, mostly in the pmu_count loop.

How about tidying up the rc pattern throughout the function?

I think since this is an actual fix, any tidying up can come later.

Thanks,
Davidlohr

#4 lore raw
Quoted 9 lines · Davidlohr Bueso

On Thu, 14 Nov 2024, Alison Schofield wrote:\n

Quoted 4 lines

This can be:

	if (cxl_pci_ras_unmask(pdev))
		dev_dbg(&pdev->dev, "No RAS reporting unmasked\n");

Yeah, it later occured to me that this was better. Will send a v2.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

There are a bunch that follow this pattern in that function, mostly in the pmu_count loop.

How about tidying up the rc pattern throughout the function?

I think since this is an actual fix, any tidying up can come later.

Yea that can come later. Sorry if I implied differently. Ira