Skip to contentSkip to conversation

PCI: imx: Fix an IS_ERR() vs NULL bug

PATCH In review Dan Carpenter 3 participants 5 messages Dec 18, 2018

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

PATCH 1/1 PCI: imx: Fix an IS_ERR() vs NULL bug

The device_link_add() function doesn't return error pointers, it returns NULL if there is an error.

Fixes 7a6991159bcd ("PCI: imx: Add multi-pd support")
---
 drivers/pci/controller/dwc/pci-imx6.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +3 -3
index b54b4590ccf9..8e7956224a5f 100644
@@ -326,9 +326,9 @@ static int imx6_pcie_attach_pd(struct device *dev)
 			DL_FLAG_STATELESS |
 			DL_FLAG_PM_RUNTIME |
 			DL_FLAG_RPM_ACTIVE);
-	if (IS_ERR(link)) {
-		dev_err(dev, "Failed to add device_link to pcie pd: %ld\n", PTR_ERR(link));
-		return PTR_ERR(link);
+	if (!link) {
+		dev_err(dev, "Failed to add device_link to pcie pd.\n");
+		return -EINVAL;
 	}
 
 	imx6_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy");
Signature · 1 line
2.17.1
#1 lore raw

T24gVHVlLCAyMDE4LTEyLTE4IGF0IDExOjIzICswMzAwLCBEYW4gQ2FycGVudGVyIHdyb3RlOg0K PiBUaGUgZGV2aWNlX2xpbmtfYWRkKCkgZnVuY3Rpb24gZG9lc24ndCByZXR1cm4gZXJyb3IgcG9p bnRlcnMsIGl0IHJldHVybnMNCj4gTlVMTCBpZiB0aGVyZSBpcyBhbiBlcnJvci4NCj4gDQo+IEZp eGVzOiA3YTY5OTExNTliY2QgKCJQQ0k6IGlteDogQWRkIG11bHRpLXBkIHN1cHBvcnQiKQ0KPiBT aWduZWQtb2ZmLWJ5OiBEYW4gQ2FycGVudGVyIDxkYW4uY2FycGVudGVyQG9yYWNsZS5jb20+DQoN ClJldmlld2VkLWJ5OiBMZW9uYXJkIENyZXN0ZXogPGxlb25hcmQuY3Jlc3RlekBueHAuY29tPg0K DQpJIGFzc3VtZSB0aGlzIHdhcyBmb3VuZCB3aXRoIGEgc3RhdGljIGNoZWNrZXI/DQo

#2 lore raw
Quoted 10 lines · Leonard Crestez
Quoted 5 lines · Dan Carpenter

The device_link_add() function doesn't return error pointers, it returns NULL if there is an error.

Fixes 7a6991159bcd ("PCI: imx: Add multi-pd support")

I assume this was found with a static checker?

It's an unpublished Smatch check... It complains about running IS_ERR() on things which aren't an error pointer. The problem is that that happens all the time intentionally so i haven't published it. I should probably make a version which only complains if it is an assignment from a function that returns NULL.

(Even then it's problematic because it can depend on the .config)

regards,
dan carpenter

#3 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

The device_link_add() function doesn't return error pointers, it returns NULL if there is an error.

Fixes 7a6991159bcd ("PCI: imx: Add multi-pd support")
---
 drivers/pci/controller/dwc/pci-imx6.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Thanks Dan, if you do not mind I will squash this in the initial commit given that it is not upstream yet.

Lorenzo

Quoted 20 lines
drivers/pci/controller/dwc/pci-imx6.c +3 -3
index b54b4590ccf9..8e7956224a5f 100644
@@ -326,9 +326,9 @@ static int imx6_pcie_attach_pd(struct device *dev)
 			DL_FLAG_STATELESS |
 			DL_FLAG_PM_RUNTIME |
 			DL_FLAG_RPM_ACTIVE);
-	if (IS_ERR(link)) {
-		dev_err(dev, "Failed to add device_link to pcie pd: %ld\n", PTR_ERR(link));
-		return PTR_ERR(link);
+	if (!link) {
+		dev_err(dev, "Failed to add device_link to pcie pd.\n");
+		return -EINVAL;
 	}
 
 	imx6_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy");
Signature · 1 line
2.17.1
#4 lore raw
Quoted 4 lines · Lorenzo Pieralisi
Quoted 3 lines · Dan Carpenter

The device_link_add() function doesn't return error pointers, it returns NULL if there is an error.

Quoted 9 lines
Quoted 5 lines
Fixes 7a6991159bcd ("PCI: imx: Add multi-pd support")
---
 drivers/pci/controller/dwc/pci-imx6.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Thanks Dan, if you do not mind I will squash this in the initial commit given that it is not upstream yet.

I don't mind at all. Thanks.

regards,
dan carpenter