Re: [PATCH 13/30] viafb: Separate global and fb-specific data

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jonathan Corbet
Date: Friday, April 30, 2010 - 9:21 am

On Thu, 29 Apr 2010 20:19:02 +0200
Bruno Prémont <bonbons@linux-vserver.org> wrote:


It would be better, yes, I'll add a patch to fix it up.


Not sure it matters, but I can make that change.


Yes, I can fix that (see above :)


This I'm less convinced about; as I split the functions apart, I've
tried to get away from the "all or nothing" mode of operation.  Now, if
framebuffer setup fails, there will likely be very little solace in
knowing that the GPIOs still work, but I would still rather allow
things that succeed to function when possible.

That said, the code doesn't currently quite work that way.  So I guess
I'll goto out_teardown here :)

jon

viafb: Fix initialization error paths

Properly localize error cleanup, and make sure that the iomem regions are
unmapped if framebuffer initialization fails.

Reported-by: Bruno Prémont <bonbons@linux-vserver.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
 drivers/video/via/via-core.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c
index 2b5773a..b8a8783 100644
--- a/drivers/video/via/via-core.c
+++ b/drivers/video/via/via-core.c
@@ -454,26 +454,32 @@ static int viafb_get_fb_size_from_pci(int chip_type)
  */
 static int __devinit via_pci_setup_mmio(struct viafb_dev *vdev)
 {
+	int ret;
 	/*
 	 * Hook up to the device registers.
 	 */
 	vdev->engine_start = pci_resource_start(vdev->pdev, 1);
 	vdev->engine_len = pci_resource_len(vdev->pdev, 1);
-	/* If this fails, others will notice later */
 	vdev->engine_mmio = ioremap_nocache(vdev->engine_start,
 			vdev->engine_len);
-
+	if (vdev->engine_mmio == NULL)
+		return -ENOMEM;
 	/*
-	 * Likewise with I/O memory.
+	 * Likewise with framebuffer memory.
 	 */
 	vdev->fbmem_start = pci_resource_start(vdev->pdev, 0);
-	vdev->fbmem_len = viafb_get_fb_size_from_pci(vdev->chip_type);
-	if (vdev->fbmem_len < 0)
-		return vdev->fbmem_len;
+	ret = vdev->fbmem_len = viafb_get_fb_size_from_pci(vdev->chip_type);
+	if (ret < 0)
+		goto out_unmap;
 	vdev->fbmem = ioremap_nocache(vdev->fbmem_start, vdev->fbmem_len);
-	if (vdev->fbmem == NULL)
-		return -ENOMEM;
+	if (vdev->fbmem == NULL) {
+		ret = -ENOMEM;
+		goto out_unmap;
+	}
 	return 0;
+out_unmap:
+	iounmap(vdev->engine_mmio);
+	return ret;
 }
 
 static void __devexit via_pci_teardown_mmio(struct viafb_dev *vdev)
@@ -566,13 +572,13 @@ static int __devinit via_pci_probe(struct pci_dev *pdev,
 	spin_lock_init(&global_dev.reg_lock);
 	ret = via_pci_setup_mmio(&global_dev);
 	if (ret)
-		goto out_teardown;
+		return ret;
 	/*
 	 * Set up the framebuffer device
 	 */
 	ret = via_fb_pci_probe(&global_dev);
 	if (ret)
-		return ret;
+		goto out_teardown;
 	/*
 	 * Create our subdevices.
 	 */
-- 
1.7.0.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] Second OLPC Viafb series, v2, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 02/30] viafb: use proper pci config API, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 04/30] viafb: Retain GEMODE reserved bits, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 05/30] viafb: Unify duplicated set_bpp() code, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 12/30] viafb: Move core stuff into via-core.c, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 13/30] viafb: Separate global and fb-specific data, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 14/30] viafb: add a driver for GPIO lines, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 15/30] viafb: package often used basic io functions, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 19/30] viafb: Introduce viafb_find_i2c_adapter(), Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 20/30] via: Rationalize vt1636 detection, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 22/30] viafb: Add a simple VX855 DMA engine driver, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 25/30] viafb: unify modesetting functions, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 27/30] viafb: replace inb/outb, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 28/30] viafb: improve misc register handling, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 29/30] viafb: fix proc entry removal, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
[PATCH 30/30] viafb: make procfs entries optional, Jonathan Corbet, (Wed Apr 28, 3:17 pm)
Re: [RFC] Second OLPC Viafb series, v2, Bruno Prémont, (Thu Apr 29, 10:26 am)
Re: [RFC] Second OLPC Viafb series, v2, Jonathan Corbet, (Fri Apr 30, 8:39 am)
Re: [PATCH 13/30] viafb: Separate global and fb-specific data, Jonathan Corbet, (Fri Apr 30, 9:21 am)
Re: [PATCH 13/30] viafb: Separate global and fb-specific data, Florian Tobias Schan ..., (Fri Apr 30, 11:07 am)
Re: [PATCH 13/30] viafb: Separate global and fb-specific data, Jonathan Corbet, (Fri Apr 30, 11:22 am)
Re: [PATCH 13/30] viafb: Separate global and fb-specific data, Florian Tobias Schan ..., (Fri Apr 30, 11:43 am)
Re: [PATCH 02/30] viafb: use proper pci config API, Florian Tobias Schan ..., (Sat May 1, 7:01 am)
Re: [PATCH 12/30] viafb: Move core stuff into via-core.c, Florian Tobias Schan ..., (Sat May 1, 8:02 am)
Re: [PATCH 12/30] viafb: Move core stuff into via-core.c, Jonathan Corbet, (Sat May 1, 8:08 am)
Re: [PATCH 12/30] viafb: Move core stuff into via-core.c, Florian Tobias Schan ..., (Sat May 1, 8:29 am)
Re: [RFC] Second OLPC Viafb series, v2, Florian Tobias Schan ..., (Sat May 1, 2:28 pm)
Re: [RFC] Second OLPC Viafb series, v2, Jonathan Corbet, (Sat May 1, 3:57 pm)
Re: [PATCH 24/30] viafb: Add a driver for the video captur ..., Florian Tobias Schan ..., (Sat May 1, 6:18 pm)
Re: [PATCH 02/30] viafb: use proper pci config API, Jonathan Corbet, (Mon May 3, 7:37 pm)