Skip to contentSkip to conversation

request_region fixes for ppc prep_request_io

PATCH In review Jesper Juhl 1 participant 1 message Feb 24, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 5/13 request_region fixes for ppc prep_request_io

request_region fixes for ppc prep_request_io.

---

 arch/ppc/platforms/prep_setup.c |   51 ++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 7 deletions(-)
arch/ppc/platforms/prep_setup.c +44 -7
@@ -1064,20 +1064,57 @@ prep_map_io(void)
 	io_block_mapping(0xf0000000, PREP_ISA_MEM_BASE, 0x08000000, _PAGE_IO);
 }
 
+static inline int
+prep_request_region(unsigned long start, unsigned long n, const char *name)
+{
+	struct resource *region;
+	
+	region = request_region(start, n, name);
+	if (!region) {
+		printk(KERN_WARNING "prep_request_io: could not allocate "
+				    "%s region\n", name);
+		return 0;
+	}
+	return 1;
+}
+
 static int __init
 prep_request_io(void)
 {
-	if (_machine == _MACH_prep) {
+	int tmp;
+
+	if (_machine != _MACH_prep)
+		return 0;
+
 #ifdef CONFIG_NVRAM
-		request_region(PREP_NVRAM_AS0, 0x8, "nvram");
+	tmp = prep_request_region(PREP_NVRAM_AS0, 0x8, "nvram");
+	if (!tmp)
+		goto out_nvram;
 #endif
-		request_region(0x00,0x20,"dma1");
-		request_region(0x40,0x20,"timer");
-		request_region(0x80,0x10,"dma page reg");
-		request_region(0xc0,0x20,"dma2");
-	}
+	tmp = prep_request_region(0x00,0x20,"dma1");
+	if (!tmp)
+		goto out_dma1;
+	tmp = prep_request_region(0x40,0x20,"timer");
+	if (!tmp)
+		goto out_timer;
+	tmp = prep_request_region(0x80,0x10,"dma page reg");
+	if (!tmp)
+		goto out_dma_page;
+	tmp = prep_request_region(0xc0,0x20,"dma2");
+	if (!tmp)
+		goto out_dma2;
 
 	return 0;
+ out_dma2:
+ 	release_region(0x80,0x10);
+ out_dma_page:
+ 	release_region(0x40,0x20);
+ out_timer:
+ 	release_region(0x00,0x20);
+ out_dma1:
+ 	release_region(PREP_NVRAM_AS0, 0x8);
+ out_nvram:
+	return -EBUSY;
 }
 
 device_initcall(prep_request_io);