Skip to contentSkip to conversation

PCI: xgene: double free on init error

PATCH In review Dan Carpenter 3 participants 4 messages Jan 21, 2017 – Jan 31, 2017

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

PATCH 1/1 PCI: xgene: double free on init error

The "port" variable was allocated with devm_kzalloc() so if we free it with kfree() it will be freed twice. Also I changed it to propogate the error from devm_ioremap_resource() instead of returning -ENOMEM.

Fixes c5d460396100 ("PCI: Add MCFG quirks for X-Gene host controller")
drivers/pci/host/pci-xgene.c +2 -5
index 7c3b54b..142a166 100644
@@ -246,14 +246,11 @@ static int xgene_pcie_ecam_init(struct pci_config_window *cfg, u32 ipversion)
 	ret = xgene_get_csr_resource(adev, &csr);
 	if (ret) {
 		dev_err(dev, "can't get CSR resource\n");
-		kfree(port);
 		return ret;
 	}
 	port->csr_base = devm_ioremap_resource(dev, &csr);
-	if (IS_ERR(port->csr_base)) {
-		kfree(port);
-		return -ENOMEM;
-	}
+	if (IS_ERR(port->csr_base))
+		return PTR_ERR(port->csr_base);
 
 	port->cfg_base = cfg->win;
 	port->version = ipversion;
#1 lore raw
Quoted 6 lines · Dan Carpenter

The "port" variable was allocated with devm_kzalloc() so if we free it with kfree() it will be freed twice. Also I changed it to propogate the error from devm_ioremap_resource() instead of returning -ENOMEM.

Fixes c5d460396100 ("PCI: Add MCFG quirks for X-Gene host controller")

Waiting for Tanmay's ack, ping :)

Quoted 25 lines
drivers/pci/host/pci-xgene.c +2 -6
index 7c3b54b..142a166 100644
@@ -246,14 +246,11 @@ static int xgene_pcie_ecam_init(struct pci_config_window *cfg, u32 ipversion)
 	ret = xgene_get_csr_resource(adev, &csr);
 	if (ret) {
 		dev_err(dev, "can't get CSR resource\n");
-		kfree(port);
 		return ret;
 	}
 	port->csr_base = devm_ioremap_resource(dev, &csr);
-	if (IS_ERR(port->csr_base)) {
-		kfree(port);
-		return -ENOMEM;
-	}
+	if (IS_ERR(port->csr_base))
+		return PTR_ERR(port->csr_base);
 
 	port->cfg_base = cfg->win;
 	port->version = ipversion;
--

To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Hi,

Quoted 30 lines · Bjorn Helgaas
Quoted 6 lines · Dan Carpenter

The "port" variable was allocated with devm_kzalloc() so if we free it with kfree() it will be freed twice. Also I changed it to propogate the error from devm_ioremap_resource() instead of returning -ENOMEM.

Fixes c5d460396100 ("PCI: Add MCFG quirks for X-Gene host controller")

Waiting for Tanmay's ack, ping :)

Quoted 19 lines
drivers/pci/host/pci-xgene.c +2 -5
index 7c3b54b..142a166 100644
@@ -246,14 +246,11 @@ static int xgene_pcie_ecam_init(struct pci_config_window *cfg, u32 ipversion)
      ret = xgene_get_csr_resource(adev, &csr);
      if (ret) {
              dev_err(dev, "can't get CSR resource\n");
-             kfree(port);
              return ret;
      }
      port->csr_base = devm_ioremap_resource(dev, &csr);
-     if (IS_ERR(port->csr_base)) {
-             kfree(port);
-             return -ENOMEM;
-     }
+     if (IS_ERR(port->csr_base))
+             return PTR_ERR(port->csr_base);
 
Quoted 2 lines

drivers/pci/host/pci-xgene.c static int xgene_pcie_ecam_init(struct pci_config_window *cfg, u32 ipversion) · line 256

Quoted 2 lines
drivers/pci/host/pci-xgene.c +0 -0
      port->cfg_base = cfg->win;
      port->version = ipversion;

Sorry for delay. Patch looks good to me. Thanks.

Thanks,
Tanmay

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

The "port" variable was allocated with devm_kzalloc() so if we free it with kfree() it will be freed twice. Also I changed it to propogate the error from devm_ioremap_resource() instead of returning -ENOMEM.

Fixes c5d460396100 ("PCI: Add MCFG quirks for X-Gene host controller")

Applied with Tanmay's ack to pci/host-xgene for v4.11, thanks!

Quoted 25 lines
drivers/pci/host/pci-xgene.c +2 -6
index 7c3b54b..142a166 100644
@@ -246,14 +246,11 @@ static int xgene_pcie_ecam_init(struct pci_config_window *cfg, u32 ipversion)
 	ret = xgene_get_csr_resource(adev, &csr);
 	if (ret) {
 		dev_err(dev, "can't get CSR resource\n");
-		kfree(port);
 		return ret;
 	}
 	port->csr_base = devm_ioremap_resource(dev, &csr);
-	if (IS_ERR(port->csr_base)) {
-		kfree(port);
-		return -ENOMEM;
-	}
+	if (IS_ERR(port->csr_base))
+		return PTR_ERR(port->csr_base);
 
 	port->cfg_base = cfg->win;
 	port->version = ipversion;
--

To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html