Skip to contentSkip to conversation

PCI: sky1: Fix missing cleanup of ECAM config on probe failure

PATCH Applied Felix Gu 4 participants 4 messages Mar 23 – Mar 24

Subsystems (5)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 PCI: sky1: Fix missing cleanup of ECAM config on probe failure

When devm_kzalloc() for reg_off fails, the code returns -ENOMEM without freeing pcie->cfg, which was allocated earlier by pci_ecam_create().

Add the missing pci_ecam_free() call to properly release the allocated ECAM configuration window on this error path.

Fixes a0d9f2c08f45 ("PCI: sky1: Add PCIe host support for CIX Sky1")
---
 drivers/pci/controller/cadence/pci-sky1.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/cadence/pci-sky1.c +3 -1
index d8c216dc120d..9853a9c82c0e 100644
@@ -176,8 +176,10 @@ static int sky1_pcie_probe(struct platform_device *pdev)
 	cdns_pcie->is_rc = 1;
 
 	reg_off = devm_kzalloc(dev, sizeof(*reg_off), GFP_KERNEL);
-	if (!reg_off)
+	if (!reg_off) {
+		pci_ecam_free(pcie->cfg);
 		return -ENOMEM;
+	}
 
 	reg_off->ip_reg_bank_offset = SKY1_IP_REG_BANK;
 	reg_off->ip_cfg_ctrl_reg_offset = SKY1_IP_CFG_CTRL_REG_BANK;

---
base-commit: 785f0eb2f85decbe7c1ef9ae922931f0194ffc2e
change-id: 20260323-sky1-890a90a72bc6

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Felix Gu

When devm_kzalloc() for reg_off fails, the code returns -ENOMEM without freeing pcie->cfg, which was allocated earlier by pci_ecam_create().

Add the missing pci_ecam_free() call to properly release the allocated ECAM configuration window on this error path.

Fixes a0d9f2c08f45 ("PCI: sky1: Add PCIe host support for CIX Sky1")
Quoted 26 lines
---
  drivers/pci/controller/cadence/pci-sky1.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/cadence/pci-sky1.c +3 -2
index d8c216dc120d..9853a9c82c0e 100644
@@ -176,8 +176,10 @@ static int sky1_pcie_probe(struct platform_device *pdev)
  	cdns_pcie->is_rc = 1;
 
  	reg_off = devm_kzalloc(dev, sizeof(*reg_off), GFP_KERNEL);
-	if (!reg_off)
+	if (!reg_off) {
+		pci_ecam_free(pcie->cfg);
  		return -ENOMEM;
+	}
 
  	reg_off->ip_reg_bank_offset = SKY1_IP_REG_BANK;
  	reg_off->ip_cfg_ctrl_reg_offset = SKY1_IP_CFG_CTRL_REG_BANK;
 
---

base-commit: 785f0eb2f85decbe7c1ef9ae922931f0194ffc2e
change-id: 20260323-sky1-890a90a72bc6

Best regards,

#2 lore raw
In reply to Felix Gu
Quoted 8 lines · Felix Gu

When devm_kzalloc() for reg_off fails, the code returns -ENOMEM without freeing pcie->cfg, which was allocated earlier by pci_ecam_create().

Add the missing pci_ecam_free() call to properly release the allocated ECAM configuration window on this error path.

[...]

Applied, thanks!

[1/1] PCI: sky1: Fix missing cleanup of ECAM config on probe failure

      commit: 72e76b63d6ff6d1f96acccbfc6c118656f63e66a

Best regards,

Signature · 1 line
Manivannan Sadhasivam <[email protected]>
#3 lore raw
Quoted 2 lines
Quoted 2 lines

Add the missing pci_ecam_free() call to properly release the allocated ECAM configuration window on this error path.

…

Quoted 4 lines

Applied, thanks!

[1/1] PCI: sky1: Fix missing cleanup of ECAM config on probe failure

      commit: 72e76b63d6ff6d1f96acccbfc6c118656f63e66a

Can the application of another goto chain become more desirable for the implementation of the function “sky1_pcie_probe”?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.0-rc5#n526

Regards,
Markus