kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darren Jenkins\\" <darrenrjenkins@gmail.com>
To: kernel-janitors@vger.kernel.org
Subject: [KJ][Patch] check return value of request_region and request_irq
Date: Wed, 15 Mar 2006 12:46:54 +0000	[thread overview]
Message-ID: <1142426815.7781.47.camel@localhost.localdomain> (raw)
In-Reply-To: <1141029654.7765.6.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 3347 bytes --]

G'day list,

m32r_pcc.c calls request_irq without checking its return value @ line
346, and request_region without checking its return value @ line 333.

The patch below checks the two return values, and serialises the error
path of init_m32r_pcc().

Note this driver is for the m32r arch so this patch is not even compile
tested, it might not even come close to compiling(I would appreciate a
report either way). Also this may be a low level driver that will never
fail a request_region or request_irq, I don't know.
(I figured why the hell not send a patch?)

Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>


--- linux-2.6.16-rc6/drivers/pcmcia/m32r_pcc.c.orig	2006-03-14 20:55:44.000000000 +1100
+++ linux-2.6.16-rc6/drivers/pcmcia/m32r_pcc.c	2006-03-15 23:32:00.000000000 +1100
@@ -312,7 +312,7 @@ static int __init is_alive(u_short sock)
 	return 0;
 }
 
-static void add_pcc_socket(ulong base, int irq, ulong mapaddr, kio_addr_t ioaddr)
+static int add_pcc_socket(ulong base, int irq, ulong mapaddr, kio_addr_t ioaddr)
 {
   	pcc_socket_t *t = &socket[pcc_sockets];
 
@@ -330,7 +330,8 @@ static void add_pcc_socket(ulong base, i
 
 	/* add pcc */
 	if (t->base > 0) {
-		request_region(t->base, 0x20, "m32r-pcc");
+		if ( request_region(t->base, 0x20, "m32r-pcc")== 0)
+			return -EBUSY;
 	}
 
 	printk(KERN_INFO "  %s ", pcc[pcc_sockets].name);
@@ -343,11 +344,13 @@ static void add_pcc_socket(ulong base, i
 	t->socket.irq_mask = 0;
 	t->socket.pci_irq = 2 + pcc_sockets; /* XXX */
 
-	request_irq(irq, pcc_interrupt, 0, "m32r-pcc", pcc_interrupt);
+	if (request_irq(irq, pcc_interrupt, 0, "m32r-pcc", pcc_interrupt) < 0) {
+		release_region(t->base, 0x20);
+		return -EBUSY;
 
 	pcc_sockets++;
 
-	return;
+	return 0;
 }
 
 
@@ -692,32 +695,38 @@ static struct platform_device pcc_device
 static int __init init_m32r_pcc(void)
 {
 	int i, ret;
+  	pcc_socket_t *t;
 
 	ret = driver_register(&pcc_driver);
 	if (ret)
-		return ret;
+		goto out;
 
 	ret = platform_device_register(&pcc_device);
-	if (ret){
-		driver_unregister(&pcc_driver);
-		return ret;
-	}
+	if (ret)
+		goto pdr_out;
+
 
 	printk(KERN_INFO "m32r PCC probe:\n");
 
 	pcc_sockets = 0;
 
-	add_pcc_socket(M32R_PCC0_BASE, PCC0_IRQ, M32R_PCC0_MAPBASE, 0x1000);
+	ret = add_pcc_socket(M32R_PCC0_BASE, PCC0_IRQ,
+						M32R_PCC0_MAPBASE, 0x1000);
+	if (ret)	
+		goto ap_out;
 
 #ifdef CONFIG_M32RPCC_SLOT2
-	add_pcc_socket(M32R_PCC1_BASE, PCC1_IRQ, M32R_PCC1_MAPBASE, 0x2000);
+	ret = add_pcc_socket(M32R_PCC1_BASE, PCC1_IRQ,
+						M32R_PCC1_MAPBASE, 0x2000);
+	if (ret) 
+		goto aps_out;
+
 #endif
 
 	if (pcc_sockets == 0) {
 		printk("socket is not found.\n");
-		platform_device_unregister(&pcc_device);
-		driver_unregister(&pcc_driver);
-		return -ENODEV;
+		ret = -ENODEV;
+		goto ns_out;
 	}
 
 	/* Set up interrupt handler(s) */
@@ -750,6 +759,25 @@ static int __init init_m32r_pcc(void)
 	}
 
 	return 0;
+	
+	
+ns_out:
+#ifdef CONFIG_M32RPCC_SLOT2
+	free_irq(PCC1_IRQ, pcc_interrupt);
+	t = &socket[--pcc_sockets];
+	release_region(t->base, 0x20);
+#endif	
+aps_out:
+	free_irq(PCC0_IRQ, pcc_interrupt);
+	t = &socket[--pcc_sockets];
+	release_region(t->base, 0x20);
+ap_out:
+	platform_device_unregister(&pcc_device);
+pdr_out:
+	driver_unregister(&pcc_driver);
+out:
+	return ret;
+	
 } /* init_m32r_pcc */
 
 static void __exit exit_m32r_pcc(void)



[-- Attachment #2: Type: text/plain, Size: 168 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2006-03-15 12:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-27  8:40 [KJ][Patch] check return value of request_region in matroxfb_base.c Darren Jenkins\
2006-03-01  7:12 ` [KJ][Patch] check return value of request region in ali5455.c Darren Jenkins\
2006-03-03  6:31 ` [KJ][Patch] check return value of request_region in Petr Vandrovec
2006-03-11 13:48 ` [KJ][Patch] check return value of request_irq in amiserial.c Darren Jenkins\
2006-03-13  4:37 ` [KJ][Patch] check return value of request_irq in pcnet_cs.c Darren Jenkins\
2006-03-13  5:00 ` Randy.Dunlap
2006-03-13  5:16 ` Darren Jenkins\
2006-03-13  5:27 ` Randy.Dunlap
2006-03-13  6:16 ` Darren Jenkins\
2006-03-13 11:56 ` [KJ][Patch] check return value of request_irq in i82365.c Darren Jenkins\
2006-03-13 12:29 ` Tobias Klauser
2006-03-14  8:44 ` Darren Jenkins\
2006-03-14 16:26 ` Randy.Dunlap
2006-03-15  7:02 ` Darren Jenkins\
2006-03-15  7:32 ` Nishanth Aravamudan
2006-03-15 12:46 ` Darren Jenkins\ [this message]
2006-03-15 12:57 ` [KJ][Patch] check return value of request_region and request_irq Tobias Klauser
2006-03-16 10:45 ` [KJ][Patch] check return value of request_region and Darren Jenkins\

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1142426815.7781.47.camel@localhost.localdomain \
    --to=darrenrjenkins@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).