Skip to contentSkip to conversation

PCI: j721e: Properly check the error of a syscon lookup

PATCH Superseded Anton Protopopov 4 participants 8 messages Nov 27 – Dec 1

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: j721e: Properly check the error of a syscon lookup

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

---

(Accidentally bumped into this while working on BPF stuff.)

 drivers/pci/controller/cadence/pci-j721e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pci-j721e.c +2 -0
index 822602836b12..fdae51e368e0 100644
@@ -334,6 +334,8 @@ static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie)
 						"ti,syscon-acspcie-proxy-ctrl");
 	if (!syscon)
 		return 0;
+	if (IS_ERR(syscon))
+		return PTR_ERR(syscon);
 
 	return j721e_enable_acspcie_refclk(pcie, syscon);
 }
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Anton Protopopov
Quoted 9 lines · Anton Protopopov

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

---

Regards,
Aksh Garg

Quoted 19 lines

(Accidentally bumped into this while working on BPF stuff.)

  drivers/pci/controller/cadence/pci-j721e.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pci-j721e.c +2 -0
index 822602836b12..fdae51e368e0 100644
@@ -334,6 +334,8 @@ static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie)
  						"ti,syscon-acspcie-proxy-ctrl");
  	if (!syscon)
  		return 0;
+	if (IS_ERR(syscon))
+		return PTR_ERR(syscon);
 
  	return j721e_enable_acspcie_refclk(pcie, syscon);
  }
#3 lore raw
In reply to Anton Protopopov

[+cc Simon, Ye for possible similar problems in pinctrl-rockchip.c]

Quoted 5 lines · Anton Protopopov

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

"Properly" in the subject is a noise word that takes up space without adding much value.

IIUC this avoids issues like a kernel oops when using an error pointer (-EINVAL, etc) as a regmap pointer.

There are only five callers of syscon_regmap_lookup_by_phandle_optional() in the tree. wpcm_fiu_probe() looks right, and you're fixing this one.

The other three are in drivers/pinctrl/pinctrl-rockchip.c, which looks kind of suspicious, or at least too complicated to verify at a glance. These were added by:

63113d4fce6c ("pinctrl: rockchip: Add RV1106 pinctrl support") dbd2317d7b9f ("pinctrl: rockchip: Add rk3506 pinctrl support")

Quoted 22 lines
Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

---

(Accidentally bumped into this while working on BPF stuff.)

 drivers/pci/controller/cadence/pci-j721e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pci-j721e.c +2 -0
index 822602836b12..fdae51e368e0 100644
@@ -334,6 +334,8 @@ static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie)
 						"ti,syscon-acspcie-proxy-ctrl");
 	if (!syscon)
 		return 0;
+	if (IS_ERR(syscon))
+		return PTR_ERR(syscon);
 
 	return j721e_enable_acspcie_refclk(pcie, syscon);
 }
#4 lore raw
Quoted 4 lines · Bjorn Helgaas

[+cc Simon, Ye for possible similar problems in pinctrl-rockchip.c]

On Fri, Nov 27, 2026 at 10:19:13AM +0000, Anton Protopopov wrote:

Quoted 8 lines
Quoted 5 lines

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

"Properly" in the subject is a noise word that takes up space without adding much value.

Yes, thanks, not needed.

Quoted 2 lines

IIUC this avoids issues like a kernel oops when using an error pointer (-EINVAL, etc) as a regmap pointer.

I will add this to the commit description.

Quoted 2 lines

There are only five callers of syscon_regmap_lookup_by_phandle_optional() in the tree. wpcm_fiu_probe() looks right

Actually, I think it also stores an error and later dereferences it in similar way. Probably should be something like

fiu->shm_regmap = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "nuvoton,shm");
+ if (IS_ERR(fiu->shm_regmap))
+ return dev_err_probe(dev, PTR_ERR(fiu->shm_regmap),
+ "Failed to look up the SHM syscon\n");

Quoted 4 lines

and you're fixing this one.

The other three are in drivers/pinctrl/pinctrl-rockchip.c, which looks kind of suspicious, or at least too complicated to verify at a glance.

Yes, 2 of 3 look buggy. Should I send fixes for all of them?

Quoted 27 lines

These were added by:

63113d4fce6c ("pinctrl: rockchip: Add RV1106 pinctrl support") dbd2317d7b9f ("pinctrl: rockchip: Add rk3506 pinctrl support")

Quoted 22 lines
Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

---

(Accidentally bumped into this while working on BPF stuff.)

 drivers/pci/controller/cadence/pci-j721e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pci-j721e.c +2 -0
index 822602836b12..fdae51e368e0 100644
@@ -334,6 +334,8 @@ static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie)
                                              "ti,syscon-acspcie-proxy-ctrl");
      if (!syscon)
              return 0;
+     if (IS_ERR(syscon))
+             return PTR_ERR(syscon);
 
      return j721e_enable_acspcie_refclk(pcie, syscon);
 }
#5 lore raw

[+cc Jonathan for wpcm_fiu_probe()]

Quoted 29 lines · Anton Protopopov
Quoted 4 lines · Bjorn Helgaas

[+cc Simon, Ye for possible similar problems in pinctrl-rockchip.c]

On Fri, Nov 27, 2026 at 10:19:13AM +0000, Anton Protopopov wrote:

Quoted 8 lines
Quoted 5 lines

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

"Properly" in the subject is a noise word that takes up space without adding much value.

Yes, thanks, not needed.

Quoted 2 lines

IIUC this avoids issues like a kernel oops when using an error pointer (-EINVAL, etc) as a regmap pointer.

I will add this to the commit description.

Quoted 2 lines

There are only five callers of syscon_regmap_lookup_by_phandle_optional() in the tree. wpcm_fiu_probe() looks right

Actually, I think it also stores an error and later dereferences it in similar way. Probably should be something like

fiu->shm_regmap = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "nuvoton,shm");

Review

Quoted 3 lines
(quoted diff) +3 -0
+          if (IS_ERR(fiu->shm_regmap))
+                  return dev_err_probe(dev, PTR_ERR(fiu->shm_regmap),
+                                       "Failed to look up the SHM syscon\n");

Yeah, you're right. wpcm_fiu at least checks fiu->shm_regmap for NULL before using it, but obviously the error pointers are non-NULL, so checking for NULL isn't enough.

Quoted 6 lines
Quoted 4 lines

and you're fixing this one.

The other three are in drivers/pinctrl/pinctrl-rockchip.c, which looks kind of suspicious, or at least too complicated to verify at a glance.

Yes, 2 of 3 look buggy. Should I send fixes for all of them?

Somebody should :)

Quoted 27 lines
Quoted 27 lines

These were added by:

63113d4fce6c ("pinctrl: rockchip: Add RV1106 pinctrl support") dbd2317d7b9f ("pinctrl: rockchip: Add rk3506 pinctrl support")

Quoted 22 lines
Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

---

(Accidentally bumped into this while working on BPF stuff.)

 drivers/pci/controller/cadence/pci-j721e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pci-j721e.c +2 -0
index 822602836b12..fdae51e368e0 100644
@@ -334,6 +334,8 @@ static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie)
                                              "ti,syscon-acspcie-proxy-ctrl");
      if (!syscon)
              return 0;
+     if (IS_ERR(syscon))
+             return PTR_ERR(syscon);
 
      return j721e_enable_acspcie_refclk(pcie, syscon);
 }
#6 lore raw
Quoted 41 lines · Bjorn Helgaas

[+cc Jonathan for wpcm_fiu_probe()]

Quoted 29 lines · Anton Protopopov
Quoted 4 lines · Bjorn Helgaas

[+cc Simon, Ye for possible similar problems in pinctrl-rockchip.c]

On Fri, Nov 27, 2026 at 10:19:13AM +0000, Anton Protopopov wrote:

Quoted 8 lines
Quoted 5 lines

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

"Properly" in the subject is a noise word that takes up space without adding much value.

Yes, thanks, not needed.

Quoted 2 lines

IIUC this avoids issues like a kernel oops when using an error pointer (-EINVAL, etc) as a regmap pointer.

I will add this to the commit description.

Quoted 2 lines

There are only five callers of syscon_regmap_lookup_by_phandle_optional() in the tree. wpcm_fiu_probe() looks right

Actually, I think it also stores an error and later dereferences it in similar way. Probably should be something like

fiu->shm_regmap = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "nuvoton,shm");

Review

Quoted 3 lines
(quoted diff) +3 -0
+          if (IS_ERR(fiu->shm_regmap))
+                  return dev_err_probe(dev, PTR_ERR(fiu->shm_regmap),
+                                       "Failed to look up the SHM syscon\n");

Yeah, you're right. wpcm_fiu at least checks fiu->shm_regmap for NULL before using it, but obviously the error pointers are non-NULL, so checking for NULL isn't enough.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

and you're fixing this one.

The other three are in drivers/pinctrl/pinctrl-rockchip.c, which looks kind of suspicious, or at least too complicated to verify at a glance.

Yes, 2 of 3 look buggy. Should I send fixes for all of them?

Somebody should :)

Ok, I will send (tomorrow). Thanks for brief replies!

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

These were added by:

63113d4fce6c ("pinctrl: rockchip: Add RV1106 pinctrl support") dbd2317d7b9f ("pinctrl: rockchip: Add rk3506 pinctrl support")

Quoted 22 lines
Fixes 82c4be4168e2 ("PCI: j721e: Enable ACSPCIE Refclk if "ti,syscon-acspcie-proxy-ctrl" exists")

---

(Accidentally bumped into this while working on BPF stuff.)

 drivers/pci/controller/cadence/pci-j721e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/cadence/pci-j721e.c +2 -0
index 822602836b12..fdae51e368e0 100644
@@ -334,6 +334,8 @@ static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie)
                                              "ti,syscon-acspcie-proxy-ctrl");
      if (!syscon)
              return 0;
+     if (IS_ERR(syscon))
+             return PTR_ERR(syscon);
 
      return j721e_enable_acspcie_refclk(pcie, syscon);
 }
#7 lore raw
Quoted 45 lines · Anton Protopopov
Quoted 43 lines · Bjorn Helgaas

[+cc Jonathan for wpcm_fiu_probe()]

Quoted 29 lines · Anton Protopopov
Quoted 4 lines · Bjorn Helgaas

[+cc Simon, Ye for possible similar problems in pinctrl-rockchip.c]

On Fri, Nov 27, 2026 at 10:19:13AM +0000, Anton Protopopov wrote:

Quoted 8 lines
Quoted 5 lines

The syscon_regmap_lookup_by_phandle_optional() function returns NULL only when the property is missing (-ENODEV). On other errors it returns an error pointer. The j721e_pcie_ctrl_init() function checks only for NULL and passes an error pointer to j721e_enable_acspcie_refclk(), which uses it as a regmap. Propagate the error instead.

"Properly" in the subject is a noise word that takes up space without adding much value.

Yes, thanks, not needed.

Quoted 2 lines

IIUC this avoids issues like a kernel oops when using an error pointer (-EINVAL, etc) as a regmap pointer.

I will add this to the commit description.

Quoted 2 lines

There are only five callers of syscon_regmap_lookup_by_phandle_optional() in the tree. wpcm_fiu_probe() looks right

Actually, I think it also stores an error and later dereferences it in similar way. Probably should be something like

fiu->shm_regmap = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "nuvoton,shm");

Review

Quoted 3 lines
(quoted diff) +3 -0
+          if (IS_ERR(fiu->shm_regmap))
+                  return dev_err_probe(dev, PTR_ERR(fiu->shm_regmap),
+                                       "Failed to look up the SHM syscon\n");

Yeah, you're right. wpcm_fiu at least checks fiu->shm_regmap for NULL before using it, but obviously the error pointers are non-NULL, so checking for NULL isn't enough.

Quoted 2 lines
Quoted 2 lines

and you're fixing this one.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The other three are in drivers/pinctrl/pinctrl-rockchip.c, which looks kind of suspicious, or at least too complicated to verify at a glance.

Yes, 2 of 3 look buggy. Should I send fixes for all of them?

Somebody should :)

Ok, I will send (tomorrow). Thanks for brief replies!

Sent. This patch grew into two patches (the second is not related, but fixes the same functions and sashiko was blaming my patch on this pre-existing bug).

Quoted 1 line

[...]