Skip to contentSkip to conversation

check return value of request_region in matroxfb_base.c

PATCH In review Darren Jenkins\ 5 participants 18 messages Feb 27, 2006 – Mar 16, 2006

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check return value of request_region in matroxfb_base.c

G'day list,

matroxfb_base.c calles 'request_region' @ 1737 without checking the return value.

The patch below adds a check for this and plugs into the existing error path.

drivers/video/matrox/matroxfb_base.c renamed from drivers/video/matrox/matroxfb_base.c.orig +5 -1
@@ -1734,7 +1734,11 @@ static int initMatrox2(WPMINFO struct bo
 #endif	/* CONFIG_MTRR */
 
 	if (!ACCESS_FBINFO(devflags.novga))
-		request_region(0x3C0, 32, "matrox");
+		if (!request_region(0x3C0, 32, "matrox")) {
+			printk(KERN_ERR "matroxfb: failed to request_region");
+			err = -EBUSY;
+			goto failVideoIO;
+		}
 	matroxfb_g450_connect(PMINFO2);
 	ACCESS_FBINFO(hw_switch->reset(PMINFO2));
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw

PATCH 1/1 check return value of request region in ali5455.c

G'day list,

ali5455.c calls request_region without checking it's return value @ line 3460.

The patch below simply checks the return value and copies local error style.

sound/oss/ali5455.c renamed from sound/oss/ali5455.c.orig +7 -1
@@ -3457,7 +3457,13 @@ static int __devinit ali_probe(struct pc
 	card->channel[4].port = 0xb0;
 	card->channel[4].num = 4;
 	/* claim our iospace and irq */
-	request_region(card->iobase, 256, card_names[pci_id->driver_data]);
+	if (!request_region(card->iobase, 256, 
+				card_names[pci_id->driver_data])) {
+		printk(KERN_ERR "ali_audio: request_region failed");
+		kfree(card);
+		return -EBUSY
+	}
+	
 	if (request_irq(card->irq, &ali_interrupt, SA_SHIRQ,
 			card_names[pci_id->driver_data], card)) {
 		printk(KERN_ERR "ali_audio: unable to allocate irq %d\n",

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw

Re: [KJ][Patch] check return value of request_region in

In reply to Darren Jenkins\
Quoted 7 lines · Darren Jenkins\

G'day list,

matroxfb_base.c calles 'request_region' @ 1737 without checking the return value.

The patch below adds a check for this and plugs into the existing error path.

Won't this conflict with reserving same I/O ports? Only primary card succeeds with reservation, so if you really want to fix this "bug", then remove this I/O reservation from matroxfb completely, matroxfb never touches this I/O region, it just reserves it to make sure that you won't load vesafb and matroxfb for same head. Your fix makes use of matroxfb with two Matrox cards in the box impossible, as on second card 0x3C0 reservation must fail as first head made reservation already.
Petr

Quoted 10 lines
drivers/video/matrox/matroxfb_base.c renamed from drivers/video/matrox/matroxfb_base.c.orig +0 -0
@@ -1734,7 +1734,11 @@ static int initMatrox2(WPMINFO struct bo
 #endif	/* CONFIG_MTRR */
 

drivers/video/matrox/matroxfb_base.c static int initMatrox2(WPMINFO struct bo · line 1744

Quoted 10 lines
drivers/video/matrox/matroxfb_base.c renamed from drivers/video/matrox/matroxfb_base.c.orig +5 -1
 	if (!ACCESS_FBINFO(devflags.novga))
-		request_region(0x3C0, 32, "matrox");
+		if (!request_region(0x3C0, 32, "matrox")) {
+			printk(KERN_ERR "matroxfb: failed to request_region");
+			err = -EBUSY;
+			goto failVideoIO;
+		}
 	matroxfb_g450_connect(PMINFO2);
 	ACCESS_FBINFO(hw_switch->reset(PMINFO2));
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#3 lore raw

PATCH 1/1 check return value of request_irq in amiserial.c

In reply to Darren Jenkins\

G'day list

amiserial.c does not check the return value of request_irq @ lines 2060 and 2061 in function rs_init();

The patch below checks the return value of the two calls and cleans up before exiting on failure.

When trying to compile this file I found that this is some built-in amiga serial driver and isn't used on i386 (only m68k and ppc), so 1, this isn't even compile tested and 2 the patch might not be required as the driver init might only be used in early boot code, I don't know. (I thought I was safe from that problem as it was in drivers/)

drivers/char/amiserial.c renamed from drivers/char/amiserial.c.orig +16 -2
@@ -2057,8 +2057,14 @@ static int __init rs_init(void)
 	local_irq_save(flags);
 
 	/* set ISRs, and then disable the rx interrupts */
-	request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", state);
-	request_irq(IRQ_AMIGA_RBF, ser_rx_int, SA_INTERRUPT, "serial RX", state);
+	if (request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", state) < 0)
+	{
+		goto err_irq;
+	}
+	if (request_irq(IRQ_AMIGA_RBF, ser_rx_int, SA_INTERRUPT, "serial RX", state) < 0)
+	{
+		goto err_irq_2;
+	}
 
 	/* turn off Rx and Tx interrupts */
 	custom.intena = IF_RBF | IF_TBE;
@@ -2078,6 +2084,14 @@ static int __init rs_init(void)
 	ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR);  /* inputs */
 
 	return 0;
+
+err_irq_2:
+	free_irq(IRQ_AMIGA_TBE, state);
+err_irq:
+	local_irq_restore(flags);
+	release_mem_region(CUSTOM_PHYSADDR+0x30, 4);
+	printk(KERN_WARN "rs_init could not request_irq\n");
+	return -EBUSY;
 }
 
 static __exit void rs_exit(void) 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#4 lore raw

PATCH 1/1 check return value of request_irq in pcnet_cs.c

In reply to Darren Jenkins\

G'day list

pcnet_cs.c called request_irq without checking its return value @ line 1036.

The patch below just checks the return value and returns -EBUSY on failure.

This file also contains 4 space indenting so I might follow with a patch to fix that too.

drivers/net/pcmcia/pcnet_cs.c renamed from drivers/net/pcmcia/pcnet_cs.c.orig +2 -1
@@ -1033,7 +1033,8 @@ static int pcnet_open(struct net_device 
     link->open++;
 
     set_misc_reg(dev);
-    request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
+    if (request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev) < 0 )
+	return -EBUSY
 
     info->phy_id = info->eth_phy;
     info->link_status = 0x00;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#5 lore raw

Re: [KJ][Patch] check return value of request_irq in pcnet_cs.c

In reply to Darren Jenkins\
Quoted 16 lines · On Mon, 13 Mar 2006 15:37:33 +1100 Darren Jenkins\\ wrote:

G'day list

pcnet_cs.c called request_irq without checking its return value @ line 1036.

The patch below just checks the return value and returns -EBUSY on failure.

This file also contains 4 space indenting so I might follow with a patch to fix that too.

drivers/net/pcmcia/pcnet_cs.c static int pcnet_open(struct net_device · line 1037

Quoted 6 lines
drivers/net/pcmcia/pcnet_cs.c renamed from drivers/net/pcmcia/pcnet_cs.c.orig +2 -1
@@ -1033,7 +1033,8 @@ static int pcnet_open(struct net_device 
     link->open++;
 
     set_misc_reg(dev);
-    request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
+    if (request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev) < 0 )
+	return -EBUSY

and this built OK for you ???

---
~Randy
You can't do anything without having to do something else first. -- Belefant's Law

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#6 lore raw

Re: [KJ][Patch] check return value of request_irq in pcnet_cs.c

In reply to Darren Jenkins\
Quoted 2 lines · Randy.Dunlap

and this built OK for you ???

Good point, I forgot to make it before sending, as I was still editing the file.
Sorry about that list, here is an improved patch.

drivers/net/pcmcia/pcnet_cs.c.back renamed from drivers/net/pcmcia/pcnet_cs.c.orig +2 -1
@@ -1033,7 +1033,8 @@ static int pcnet_open(struct net_device 
     link->open++;
 
     set_misc_reg(dev);
-    request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
+    if (request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev) < 0 )
+	return -EBUSY;
 
     info->phy_id = info->eth_phy;
     info->link_status = 0x00;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#7 lore raw

Re: [KJ][Patch] check return value of request_irq in pcnet_cs.c

In reply to Darren Jenkins\
Quoted 14 lines · On Mon, 13 Mar 2006 16:16:56 +1100 Darren Jenkins\\ wrote:
Quoted 2 lines · Randy.Dunlap

and this built OK for you ???

Good point, I forgot to make it before sending, as I was still editing the file.
Sorry about that list, here is an improved patch.

drivers/net/pcmcia/pcnet_cs.c.back static int pcnet_open(struct net_device · line 1040

Quoted 9 lines
drivers/net/pcmcia/pcnet_cs.c.back renamed from drivers/net/pcmcia/pcnet_cs.c.orig +2 -1
@@ -1033,7 +1033,8 @@ static int pcnet_open(struct net_device 
     link->open++;
 
     set_misc_reg(dev);
-    request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
+    if (request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev) < 0 )
+	return -EBUSY;
 
     info->phy_id = info->eth_phy;
     info->link_status = 0x00;

Yes, that's better, but has some "improper" whitespace:
don't put a space between 0 and ')'.

---
~Randy
You can't do anything without having to do something else first. -- Belefant's Law

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#8 lore raw

Re: [KJ][Patch] check return value of request_irq in pcnet_cs.c

In reply to Darren Jenkins\
Quoted 4 lines · Randy.Dunlap

Yes, that's better, but has some "improper" whitespace:
don't put a space between 0 and ')'.

Ok, here is an even better than the 'improved patch' patch then. :)

drivers/net/pcmcia/pcnet_cs.c.back renamed from drivers/net/pcmcia/pcnet_cs.c.orig +2 -1
@@ -1033,7 +1033,8 @@ static int pcnet_open(struct net_device 
     link->open++;
 
     set_misc_reg(dev);
-    request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
+    if (request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev) < 0)
+	return -EBUSY;
 
     info->phy_id = info->eth_phy;
     info->link_status = 0x00;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#9 lore raw

PATCH 1/1 check return value of request_irq in i82365.c

In reply to Darren Jenkins\

G'day list

i82365.c calls request_irq without checking the return value @ line 1297.

The patch below checks the return value, and serialises the error path, which is currently a little confusing.

This file also has 4 space indenting(what is up with pcmcia drivers?), so I might follow with a patch fixing the coding style for it too.(tomorrow)

This patch is compile tested.

drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +26 -16
@@ -1264,20 +1264,17 @@ static int __init init_i82365(void)
 
     ret = driver_register(&i82365_driver);
     if (ret)
-	return ret;
+	goto out;
 
     i82365_device = platform_device_alloc("i82365", 0);
-    if (i82365_device) {
-	    ret = platform_device_add(i82365_device);
-	    if (ret)
-		    platform_device_put(i82365_device);
-    } else
-	    ret = -ENOMEM;
-
-    if (ret) {
-	driver_unregister(&i82365_driver);
-	return ret;
+    if (!i82365_device) {
+	ret = -ENOMEM;
+	goto ur_out;
     }
+   
+    ret = platform_device_add(i82365_device);
+    if (ret)
+	goto pdp_out;
 
     printk(KERN_INFO "Intel ISA PCIC probe: ");
     sockets = 0;
@@ -1286,15 +1283,18 @@ static int __init init_i82365(void)
 
     if (sockets == 0) {
 	printk("not found.\n");
-	platform_device_unregister(i82365_device);
-	release_region(i365_base, 2);
-	driver_unregister(&i82365_driver);
-	return -ENODEV;
+	ret = -ENODEV;
+	goto r_out;
     }
 
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt)< 0)
+	{
+	    printk(KERN_ERR "init_i82365 could not request_irq");
+	    ret = -EBUSY;
+	    goto r_out;
+	}
     
     /* register sockets with the pcmcia core */
     for (i = 0; i < sockets; i++) {
@@ -1325,6 +1325,16 @@ static int __init init_i82365(void)
     }
     
     return 0;
+
+r_out:
+    release_region(i365_base, 2);
+    platform_device_del(i82365_device);
+pdp_out:
+    platform_device_put(i82365_device);
+ur_out:
+    driver_unregister(&i82365_driver);
+out:
+    return ret;
     
 } /* init_i82365 */
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#10 lore raw

Re: [KJ][Patch] check return value of request_irq in i82365.c

In reply to Darren Jenkins\
Quoted 38 lines · Darren Jenkins
drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +8 -14
@@ -1264,20 +1264,17 @@ static int __init init_i82365(void)
 
     ret = driver_register(&i82365_driver);
     if (ret)
-	return ret;
+	goto out;
 
     i82365_device = platform_device_alloc("i82365", 0);
-    if (i82365_device) {
-	    ret = platform_device_add(i82365_device);
-	    if (ret)
-		    platform_device_put(i82365_device);
-    } else
-	    ret = -ENOMEM;
-
-    if (ret) {
-	driver_unregister(&i82365_driver);
-	return ret;
+    if (!i82365_device) {
+	ret = -ENOMEM;
+	goto ur_out;
     }
+   
+    ret = platform_device_add(i82365_device);
+    if (ret)
+	goto pdp_out;
 
     printk(KERN_INFO "Intel ISA PCIC probe: ");
     sockets = 0;
@@ -1286,15 +1283,18 @@ static int __init init_i82365(void)
 
     if (sockets == 0) {
 	printk("not found.\n");
-	platform_device_unregister(i82365_device);
-	release_region(i365_base, 2);
-	driver_unregister(&i82365_driver);

drivers/pcmcia/i82365.c static int __init init_i82365(void) · line 1293

Quoted 10 lines
drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +4 -2
-	return -ENODEV;
+	ret = -ENODEV;
+	goto r_out;
     }
 
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt)< 0)
+	{

^-- You might want to have this on the above line as with the if's before. Also a space before the '<' would be good.

Cheers, Tobias

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#11 lore raw

Re: [KJ][Patch] check return value of request_irq in i82365.c

In reply to Darren Jenkins\
Quoted 9 lines · Tobias Klauser

Review

Quoted 5 lines
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
(quoted diff) +2 -1
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt)< 0)
+	{

^-- You might want to have this on the above line as with the if's before. Also a space before the '<' would be good.

Cheers, Tobias

OK here is the patch with your change, doing it on two lines like this was the best I could make it look in 80 cols.
Also I noticed another problem where isa_probe() might or might not succeed with a request_region() meaning that we might release_region() on something we don't own. The patch below fixes this too.

If this patch is OK I will follow with the coding style clean up.

drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +31 -19
@@ -770,7 +770,7 @@ MODULE_DEVICE_TABLE(isapnp, id_table);
 static struct pnp_dev *i82365_pnpdev;
 #endif
 
-static void __init isa_probe(void)
+static int __init isa_probe(void)
 {
     int i, j, sock, k, ns, id;
     kio_addr_t port;
@@ -805,7 +805,7 @@ static void __init isa_probe(void)
     if (!request_region(i365_base, 2, "i82365")) {
 	if (sockets == 0)
 	    printk("port conflict at %#lx\n", i365_base);
-	return;
+	return -EBUSY;
     }
 
     id = identify(i365_base, 0);
@@ -844,6 +844,7 @@ static void __init isa_probe(void)
 	    if (ns != 0) add_pcic(ns, id);
 	}
     }
+    return 0;
 }
 
 /*====================================================================*/
@@ -1264,37 +1265,37 @@ static int __init init_i82365(void)
 
     ret = driver_register(&i82365_driver);
     if (ret)
-	return ret;
+	goto out;
 
     i82365_device = platform_device_alloc("i82365", 0);
-    if (i82365_device) {
-	    ret = platform_device_add(i82365_device);
-	    if (ret)
-		    platform_device_put(i82365_device);
-    } else
-	    ret = -ENOMEM;
-
-    if (ret) {
-	driver_unregister(&i82365_driver);
-	return ret;
+    if (!i82365_device) {
+	ret = -ENOMEM;
+	goto ur_out;
     }
+   
+    ret = platform_device_add(i82365_device);
+    if (ret)
+	goto pdp_out;
 
     printk(KERN_INFO "Intel ISA PCIC probe: ");
     sockets = 0;
 
-    isa_probe();
+    i = isa_probe();
 
     if (sockets == 0) {
 	printk("not found.\n");
-	platform_device_unregister(i82365_device);
-	release_region(i365_base, 2);
-	driver_unregister(&i82365_driver);
-	return -ENODEV;
+	ret = -ENODEV;
+	goto r_out;
     }
 
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365", 
+							pcic_interrupt) < 0){
+	    printk(KERN_ERR "init_i82365 could not request_irq");
+	    ret = -EBUSY;
+	    goto r_out;
+	}
     
     /* register sockets with the pcmcia core */
     for (i = 0; i < sockets; i++) {
@@ -1325,6 +1326,17 @@ static int __init init_i82365(void)
     }
     
     return 0;
+
+r_out:
+    if (i == 0)
+	release_region(i365_base, 2);
+    platform_device_del(i82365_device);
+pdp_out:
+    platform_device_put(i82365_device);
+ur_out:
+    driver_unregister(&i82365_driver);
+out:
+    return ret;
     
 } /* init_i82365 */
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#12 lore raw

Re: [KJ][Patch] check return value of request_irq in i82365.c

In reply to Darren Jenkins\
Quoted 92 lines · On Tue, 14 Mar 2006 19:44:37 +1100 Darren Jenkins\\ wrote:
Quoted 9 lines · Tobias Klauser

Review

Quoted 5 lines
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
(quoted diff) +2 -1
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt)< 0)
+	{

^-- You might want to have this on the above line as with the if's before. Also a space before the '<' would be good.

Cheers, Tobias

OK here is the patch with your change, doing it on two lines like this was the best I could make it look in 80 cols.
Also I noticed another problem where isa_probe() might or might not succeed with a request_region() meaning that we might release_region() on something we don't own. The patch below fixes this too.

If this patch is OK I will follow with the coding style clean up.

drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +14 -18
@@ -770,7 +770,7 @@ MODULE_DEVICE_TABLE(isapnp, id_table);
 static struct pnp_dev *i82365_pnpdev;
 #endif
 
-static void __init isa_probe(void)
+static int __init isa_probe(void)
 {
     int i, j, sock, k, ns, id;
     kio_addr_t port;
@@ -805,7 +805,7 @@ static void __init isa_probe(void)
     if (!request_region(i365_base, 2, "i82365")) {
 	if (sockets == 0)
 	    printk("port conflict at %#lx\n", i365_base);
-	return;
+	return -EBUSY;
     }
 
     id = identify(i365_base, 0);
@@ -844,6 +844,7 @@ static void __init isa_probe(void)
 	    if (ns != 0) add_pcic(ns, id);
 	}
     }
+    return 0;
 }
 
 /*====================================================================*/
@@ -1264,37 +1265,37 @@ static int __init init_i82365(void)
 
     ret = driver_register(&i82365_driver);
     if (ret)
-	return ret;
+	goto out;
 
     i82365_device = platform_device_alloc("i82365", 0);
-    if (i82365_device) {
-	    ret = platform_device_add(i82365_device);
-	    if (ret)
-		    platform_device_put(i82365_device);
-    } else
-	    ret = -ENOMEM;
-
-    if (ret) {
-	driver_unregister(&i82365_driver);
-	return ret;
+    if (!i82365_device) {
+	ret = -ENOMEM;
+	goto ur_out;
     }
+   
+    ret = platform_device_add(i82365_device);
+    if (ret)
+	goto pdp_out;
 
     printk(KERN_INFO "Intel ISA PCIC probe: ");
     sockets = 0;
 
-    isa_probe();
+    i = isa_probe();
 
     if (sockets == 0) {
 	printk("not found.\n");
-	platform_device_unregister(i82365_device);
-	release_region(i365_base, 2);
-	driver_unregister(&i82365_driver);
-	return -ENODEV;
+	ret = -ENODEV;
+	goto r_out;
     }

drivers/pcmcia/i82365.c static int __init init_i82365(void) · line 1298

Quoted 10 lines
drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +6 -1
 
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365", 
+							pcic_interrupt) < 0){
+	    printk(KERN_ERR "init_i82365 could not request_irq");
+	    ret = -EBUSY;
+	    goto r_out;
+	}

well.... if you have to make any more changes, add a space after the "< 0)" and before the opening '{'.
The "grammar" isn't tough IMO. Maybe you are just used to not using whitespace?

---
~Randy
You can't do anything without having to do something else first. -- Belefant's Law

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#13 lore raw

Re: [KJ][Patch] check return value of request_irq in i82365.c

In reply to Darren Jenkins\
Quoted 4 lines · Randy.Dunlap

well.... if you have to make any more changes, add a space after the "< 0)" and before the opening '{'.
The "grammar" isn't tough IMO. Maybe you are just used to not using whitespace?

White-space lol, I usually use a lot more, but I have never been restricted to 80 columns before and I'm not used to using the K&R coding style that you old folks all seem to use. :P

Here is an improved patch. I guess I will start with the style cleanups, unless there are anymore problems.

drivers/pcmcia/i82365.c renamed from drivers/pcmcia/i82365.c.orig +31 -19
@@ -770,7 +770,7 @@ MODULE_DEVICE_TABLE(isapnp, id_table);
 static struct pnp_dev *i82365_pnpdev;
 #endif
 
-static void __init isa_probe(void)
+static int __init isa_probe(void)
 {
     int i, j, sock, k, ns, id;
     kio_addr_t port;
@@ -805,7 +805,7 @@ static void __init isa_probe(void)
     if (!request_region(i365_base, 2, "i82365")) {
 	if (sockets == 0)
 	    printk("port conflict at %#lx\n", i365_base);
-	return;
+	return -EBUSY;
     }
 
     id = identify(i365_base, 0);
@@ -844,6 +844,7 @@ static void __init isa_probe(void)
 	    if (ns != 0) add_pcic(ns, id);
 	}
     }
+    return 0;
 }
 
 /*====================================================================*/
@@ -1264,37 +1265,37 @@ static int __init init_i82365(void)
 
     ret = driver_register(&i82365_driver);
     if (ret)
-	return ret;
+	goto out;
 
     i82365_device = platform_device_alloc("i82365", 0);
-    if (i82365_device) {
-	    ret = platform_device_add(i82365_device);
-	    if (ret)
-		    platform_device_put(i82365_device);
-    } else
-	    ret = -ENOMEM;
-
-    if (ret) {
-	driver_unregister(&i82365_driver);
-	return ret;
+    if (!i82365_device) {
+	ret = -ENOMEM;
+	goto ur_out;
     }
+   
+    ret = platform_device_add(i82365_device);
+    if (ret)
+	goto pdp_out;
 
     printk(KERN_INFO "Intel ISA PCIC probe: ");
     sockets = 0;
 
-    isa_probe();
+    i = isa_probe();
 
     if (sockets == 0) {
 	printk("not found.\n");
-	platform_device_unregister(i82365_device);
-	release_region(i365_base, 2);
-	driver_unregister(&i82365_driver);
-	return -ENODEV;
+	ret = -ENODEV;
+	goto r_out;
     }
 
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
-	request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+	if (request_irq(cs_irq, pcic_interrupt, 0, "i82365",
+							pcic_interrupt) < 0) {
+	    printk(KERN_ERR "init_i82365 could not request_irq");
+	    ret = -EBUSY;
+	    goto r_out;
+	}
     
     /* register sockets with the pcmcia core */
     for (i = 0; i < sockets; i++) {
@@ -1325,6 +1326,17 @@ static int __init init_i82365(void)
     }
     
     return 0;
+
+r_out:
+    if (i == 0)
+	release_region(i365_base, 2);
+    platform_device_del(i82365_device);
+pdp_out:
+    platform_device_put(i82365_device);
+ur_out:
+    driver_unregister(&i82365_driver);
+out:
+    return ret;
     
 } /* init_i82365 */
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#14 lore raw

Re: [KJ][Patch] check return value of request_irq in i82365.c

In reply to Darren Jenkins\
Quoted 7 lines · Darren Jenkins
Quoted 4 lines · Randy.Dunlap

well.... if you have to make any more changes, add a space after the "< 0)" and before the opening '{'.
The "grammar" isn't tough IMO. Maybe you are just used to not using whitespace?

Quoted 6 lines

White-space lol, I usually use a lot more, but I have never been restricted to 80 columns before and I'm not used to using the K&R coding style that you old folks all seem to use. :P

Here is an improved patch. I guess I will start with the style cleanups, unless there are anymore problems.

Without looking at the thread, it's now impossible to know what the does :) Always keep the description tag with each patch you send out.

Thanks,
Nish

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#15 lore raw

PATCH 1/1 check return value of request_region and request_irq

In reply to Darren Jenkins\

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?)

drivers/pcmcia/m32r_pcc.c renamed from drivers/pcmcia/m32r_pcc.c.orig +42 -14
@@ -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)

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#16 lore raw

Re: [KJ][Patch] check return value of request_region and request_irq

In reply to Darren Jenkins\
Quoted 12 lines · Darren Jenkins
drivers/pcmcia/m32r_pcc.c renamed from drivers/pcmcia/m32r_pcc.c.orig +1 -1
@@ -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];
 

drivers/pcmcia/m32r_pcc.c static void add_pcc_socket(ulong base, i · line 333

Quoted 5 lines
drivers/pcmcia/m32r_pcc.c renamed from drivers/pcmcia/m32r_pcc.c.orig +1 -1
@@ -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)

Whitespaces again

Cheers, Tobias

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#17 lore raw

Re: [KJ][Patch] check return value of request_region and

In reply to Darren Jenkins\
Quoted 11 lines · Tobias Klauser

Review static void add_pcc_socket(ulong base, i · line 333

Quoted 7 lines
(quoted diff) +1 -1
@@ -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)

Whitespaces again

Cheers, Tobias

Thanks Tobias.

Here is an updated patch.

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?)

drivers/pcmcia/m32r_pcc.c renamed from drivers/pcmcia/m32r_pcc.c.orig +42 -14
@@ -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)

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors