diff mbox

[v1,15/25] PCI: generic: Free resource list close to where it's allocated

Message ID 20160606230636.20936.29083.stgit@bhelgaas-glaptop2.roam.corp.google.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Bjorn Helgaas June 6, 2016, 11:06 p.m. UTC
Previously we allocated the PCI resource list in
gen_pci_parse_request_of_pci_ranges(), but if we had an error, we freed it
on error in gen_pci_init().

Reorder gen_pci_init() so we can take care of error path cleanup in
gen_pci_parse_request_of_pci_ranges() instead.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pci-host-common.c |   32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)


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

Comments

Tyler Baker June 20, 2016, 4:56 p.m. UTC | #1
Hi Bjorn,

On 6 June 2016 at 16:06, Bjorn Helgaas <bhelgaas@google.com> wrote:
> Previously we allocated the PCI resource list in
> gen_pci_parse_request_of_pci_ranges(), but if we had an error, we freed it
> on error in gen_pci_init().
>
> Reorder gen_pci_init() so we can take care of error path cleanup in
> gen_pci_parse_request_of_pci_ranges() instead.
>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

The kernelci.org bot has reported[0] new qemu-aarch64
(arm64-defconfig) boot failures[1][2] in next-20160620. I've
bisected[3] this boot failure down to this patch, and confirmed
reverting it on top of next-20160620 resolves the boot issue.

I have not investigated further, but you can easily reproduce[4] the
boot failure on an x86 host running qemu-system-aarch64 (I'm running
qemu-system 2.6).

Cheers,

Tyler

[0] https://kernelci.org/boot/all/job/next/kernel/next-20160620/
[1] https://storage.kernelci.org/next/next-20160620/arm64-defconfig/lab-cambridge/boot-apm-mustang-kvm-guest.txt
[2] https://storage.kernelci.org/next/next-20160620/arm64-defconfig/lab-tbaker/boot-qemu-aarch64,legacy.txt
[3] http://hastebin.com/segiruribu.vbs
[4] http://hastebin.com/dafuzicuyi.avrasm
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lorenzo Pieralisi June 20, 2016, 5:22 p.m. UTC | #2
On Mon, Jun 20, 2016 at 09:56:45AM -0700, Tyler Baker wrote:
> Hi Bjorn,
> 
> On 6 June 2016 at 16:06, Bjorn Helgaas <bhelgaas@google.com> wrote:
> > Previously we allocated the PCI resource list in
> > gen_pci_parse_request_of_pci_ranges(), but if we had an error, we freed it
> > on error in gen_pci_init().
> >
> > Reorder gen_pci_init() so we can take care of error path cleanup in
> > gen_pci_parse_request_of_pci_ranges() instead.
> >
> > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> 
> The kernelci.org bot has reported[0] new qemu-aarch64
> (arm64-defconfig) boot failures[1][2] in next-20160620. I've
> bisected[3] this boot failure down to this patch, and confirmed
> reverting it on top of next-20160620 resolves the boot issue.
> 
> I have not investigated further, but you can easily reproduce[4] the
> boot failure on an x86 host running qemu-system-aarch64 (I'm running
> qemu-system 2.6).

That's most likely because pci_ecam_create() requires the bus_range
resource (its busr parameter) to be initialized when it is called
and that's not the case after this patch is applied if I read it
correctly.

It is probably a NULL pointer dereference in pci_ecam_create().

Thanks,
Lorenzo

> 
> Cheers,
> 
> Tyler
> 
> [0] https://kernelci.org/boot/all/job/next/kernel/next-20160620/
> [1] https://storage.kernelci.org/next/next-20160620/arm64-defconfig/lab-cambridge/boot-apm-mustang-kvm-guest.txt
> [2] https://storage.kernelci.org/next/next-20160620/arm64-defconfig/lab-tbaker/boot-qemu-aarch64,legacy.txt
> [3] http://hastebin.com/segiruribu.vbs
> [4] http://hastebin.com/dafuzicuyi.avrasm
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas June 21, 2016, 3:14 p.m. UTC | #3
On Mon, Jun 20, 2016 at 06:22:40PM +0100, Lorenzo Pieralisi wrote:
> On Mon, Jun 20, 2016 at 09:56:45AM -0700, Tyler Baker wrote:
> > Hi Bjorn,
> > 
> > On 6 June 2016 at 16:06, Bjorn Helgaas <bhelgaas@google.com> wrote:
> > > Previously we allocated the PCI resource list in
> > > gen_pci_parse_request_of_pci_ranges(), but if we had an error, we freed it
> > > on error in gen_pci_init().
> > >
> > > Reorder gen_pci_init() so we can take care of error path cleanup in
> > > gen_pci_parse_request_of_pci_ranges() instead.
> > >
> > > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> > 
> > The kernelci.org bot has reported[0] new qemu-aarch64
> > (arm64-defconfig) boot failures[1][2] in next-20160620. I've
> > bisected[3] this boot failure down to this patch, and confirmed
> > reverting it on top of next-20160620 resolves the boot issue.
> > 
> > I have not investigated further, but you can easily reproduce[4] the
> > boot failure on an x86 host running qemu-system-aarch64 (I'm running
> > qemu-system 2.6).
> 
> That's most likely because pci_ecam_create() requires the bus_range
> resource (its busr parameter) to be initialized when it is called
> and that's not the case after this patch is applied if I read it
> correctly.
> 
> It is probably a NULL pointer dereference in pci_ecam_create().

Yep, thanks everybody, I dropped that ill-considered patch altogether.

> > [0] https://kernelci.org/boot/all/job/next/kernel/next-20160620/
> > [1] https://storage.kernelci.org/next/next-20160620/arm64-defconfig/lab-cambridge/boot-apm-mustang-kvm-guest.txt
> > [2] https://storage.kernelci.org/next/next-20160620/arm64-defconfig/lab-tbaker/boot-qemu-aarch64,legacy.txt
> > [3] http://hastebin.com/segiruribu.vbs
> > [4] http://hastebin.com/dafuzicuyi.avrasm
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pci/host/pci-host-common.c b/drivers/pci/host/pci-host-common.c
index 8cba7ab..16a4e61 100644
--- a/drivers/pci/host/pci-host-common.c
+++ b/drivers/pci/host/pci-host-common.c
@@ -73,6 +73,7 @@  static int gen_pci_parse_request_of_pci_ranges(struct device *dev,
 	return 0;
 
 out_release_res:
+	pci_free_resource_list(resources);
 	return err;
 }
 
@@ -89,33 +90,30 @@  static struct pci_config_window *gen_pci_init(struct device *dev,
 	struct resource *bus_range = NULL;
 	struct pci_config_window *cfg;
 
-	/* Parse our PCI ranges and request their resources */
-	err = gen_pci_parse_request_of_pci_ranges(dev, resources, &bus_range);
-	if (err)
-		goto err_out;
-
 	err = of_address_to_resource(dev->of_node, 0, &cfgres);
 	if (err) {
 		dev_err(dev, "missing \"reg\" property\n");
-		goto err_out;
+		return err;
 	}
 
 	cfg = pci_ecam_create(dev, &cfgres, bus_range, ops);
-	if (IS_ERR(cfg)) {
-		err = PTR_ERR(cfg);
-		goto err_out;
-	}
+	if (IS_ERR(cfg))
+		return PTR_ERR(cfg);
 
 	err = devm_add_action(dev, gen_pci_unmap_cfg, cfg);
-	if (err) {
-		gen_pci_unmap_cfg(cfg);
-		goto err_out;
-	}
+	if (err)
+		goto err_cfg;
+
+	/* Parse our PCI ranges and request their resources */
+	err = gen_pci_parse_request_of_pci_ranges(dev, resources, &bus_range);
+	if (err)
+		goto err_cfg;
+
 	return cfg;
 
-err_out:
-	pci_free_resource_list(resources);
-	return ERR_PTR(err);
+err_cfg:
+	gen_pci_unmap_cfg(cfg);
+	return err;
 }
 
 int pci_host_common_probe(struct platform_device *pdev,