[PATCH 1/2] drivers, pcmcia: check return code of request_irq and request_region in drivers/pcmcia/m32r_cfc.c

Qiaowei Ren qiaowei.ren at intel.com
Wed Jan 22 14:03:23 EST 2014


The patch below adds a check to drivers/pcmcia/m32r_cfc.c for the
return code of request_irq and request_region.

Signed-off-by: Qiaowei Ren <qiaowei.ren at intel.com>
---
 drivers/pcmcia/m32r_cfc.c |   40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index a26f38c..8797b93 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -286,6 +286,7 @@ static int __init is_alive(u_short sock)
 static void add_pcc_socket(ulong base, int irq, ulong mapaddr,
 			   unsigned int ioaddr)
 {
+	unsigned long reg_base;
 	pcc_socket_t *t = &socket[pcc_sockets];
 
 	pr_debug("m32r_cfc: add_pcc_socket: base=%#lx, irq=%d, "
@@ -312,14 +313,18 @@ static void add_pcc_socket(ulong base, int irq, ulong mapaddr,
 
 	/* add pcc */
 #if !defined(CONFIG_PLAT_USRV)
-	request_region((unsigned int)PLD_CFRSTCR, 0x20, "m32r_cfc");
+	if (!request_region((unsigned long)PLD_CFRSTCR, 0x20, "m32r_cfc")) {
+		printk(KERN_ERR "m32r_cfc: request_region 0x%x failed.\n",
+				PLD_CFRSTCR);
+		return;
+	}
 #else	/* CONFIG_PLAT_USRV */
-	{
-		unsigned int reg_base;
-
-		reg_base = (unsigned int)PLD_CFRSTCR;
-		reg_base |= pcc_sockets << 8;
-		request_region(reg_base, 0x20, "m32r_cfc");
+	reg_base = (unsigned long)PLD_CFRSTCR;
+	reg_base |= pcc_sockets << 8;
+	if (!request_region(reg_base, 0x20, "m32r_cfc")) {
+		printk(KERN_ERR "m32r_cfc: request_region 0x%x failed.\n",
+				reg_base);
+		return;
 	}
 #endif	/* CONFIG_PLAT_USRV */
 	printk(KERN_INFO "  %s ", pcc[pcc_sockets].name);
@@ -338,10 +343,16 @@ static void add_pcc_socket(ulong base, int irq, ulong mapaddr,
 
 #ifndef CONFIG_PLAT_USRV
 	/* insert interrupt */
-	request_irq(irq, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt);
+	if (request_irq(irq, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt) != 0) {
+		printk(KERN_ERR "m32r_cfc: request_irq %d failed.\n", irq);
+		goto out1;
+	}
 #ifndef CONFIG_PLAT_MAPPI3
 	/* eject interrupt */
-	request_irq(irq+1, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt);
+	if (request_irq(irq+1, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt) != 0) {
+		printk(KERN_ERR "m32r_cfc: request_irq %d failed.\n", irq+1);
+		goto out2;
+	}
 #endif
 	pr_debug("m32r_cfc: enable CFMSK, RDYSEL\n");
 	pcc_set(pcc_sockets, (unsigned int)PLD_CFIMASK, 0x01);
@@ -351,6 +362,17 @@ static void add_pcc_socket(ulong base, int irq, ulong mapaddr,
 #endif
 	pcc_sockets++;
 
+out2:
+#ifndef CONFIG_PLAT_USRV
+	free_irq(irq, pcc_interrupt);
+#endif
+
+out1:
+#if !defined(CONFIG_PLAT_USRV)
+	release_region(PLD_CFRSTCR, 0x20);
+#else	/* CONFIG_PLAT_USRV */
+	release_region(reg_base, 0x20);
+#endif	/* CONFIG_PLAT_USRV */
 	return;
 }
 
-- 
1.7.1




More information about the linux-pcmcia mailing list