From: Dan Carpenter Date: Tue, 4 Apr 2017 19:32:26 +0000 (+0000) Subject: PCI: xgene: Fix double free on init error X-Git-Tag: v4.10.10~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcfd2ac4abfbeddaec28499481647b4db35bede2;p=thirdparty%2Fkernel%2Fstable.git PCI: xgene: Fix double free on init error [ Upstream commit 1ded56df3247d358390ae6dc09ccee620262ac5f ] 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") Also-posted-by: Shawn Lin Signed-off-by: Dan Carpenter Signed-off-by: Bjorn Helgaas Acked-by: Tanmay Inamdar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/pci/host/pci-xgene.c b/drivers/pci/host/pci-xgene.c index 7c3b54b9eb17c..142a1669dd821 100644 --- a/drivers/pci/host/pci-xgene.c +++ b/drivers/pci/host/pci-xgene.c @@ -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;