Skip to contentSkip to conversation

PATCH: SBC EPX does not check/claim I/O ports it uses

PATCH Alan Cox 4 participants 6 messages Jan 17, 2006 – Jan 18, 2006 Char and misc drivers

lore
Share & tools
lore

Alan Cox

author
#0 lore raw

Can't test this as I lack the hardware, can you check it seems right Calin.

drivers/char/watchdog/sbc_epx_c3.c +5 -0
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.16-rc1/drivers/char/watchdog/sbc_epx_c3.c linux-2.6.16-rc1/drivers/char/watchdog/sbc_epx_c3.c
@@ -25,6 +25,7 @@
 #include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -180,6 +181,9 @@
 static int __init watchdog_init(void)
 {
 	int ret;
+	
+	if (!request_region(EPXC3_WATCHDOG_CTL_REG, 2, "epxc3_watchdog"))
+		return -EBUSY;
 
 	ret = register_reboot_notifier(&epx_c3_notifier);
 	if (ret) {
@@ -205,6 +209,7 @@
 {
 	misc_deregister(&epx_c3_miscdev);
 	unregister_reboot_notifier(&epx_c3_notifier);
+	release_region(EPXC3_WATCHDOG_CTL_REG, 2);
 }
 
 module_init(watchdog_init);
#1 lore raw

Hi,

drivers/char/watchdog/sbc_epx_c3.c line 189

Quoted 10 lines
drivers/char/watchdog/sbc_epx_c3.c +3 -0
@@ -180,6 +181,9 @@
 static int __init watchdog_init(void)
 {
        int ret;
+
+       if (!request_region(EPXC3_WATCHDOG_CTL_REG, 2, "epxc3_watchdog"))
+               return -EBUSY;
 
        ret = register_reboot_notifier(&epx_c3_notifier);
        if (ret) {

Shouldn't resource be released when register_reboot_notifier() or misc_register() fails?

Bartlomiej

author
#2 lore raw
Quoted 5 lines · Bartlomiej Zolnierkiewicz
Quoted 2 lines
        ret = register_reboot_notifier(&epx_c3_notifier);
        if (ret) {

Shouldn't resource be released when register_reboot_notifier() or misc_register() fails?

Yes, let me insert my brain and post a corrected patch.

author
#3 lore raw

PATCH: SBC EPX does not check/claim I/O ports it uses (2nd Edition)

In reply to Bartlomiej Zolnierkiewicz
drivers/char/watchdog/sbc_epx_c3.c +10 -2
@@ -25,6 +25,7 @@
 #include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -180,12 +181,15 @@
 static int __init watchdog_init(void)
 {
 	int ret;
+	
+	if (!request_region(EPXC3_WATCHDOG_CTL_REG, 2, "epxc3_watchdog"))
+		return -EBUSY;
 
 	ret = register_reboot_notifier(&epx_c3_notifier);
 	if (ret) {
 		printk(KERN_ERR PFX "cannot register reboot notifier "
 			"(err=%d)\n", ret);
-		return ret;
+		goto out;
 	}
 
 	ret = misc_register(&epx_c3_miscdev);
@@ -193,12 +197,16 @@
 		printk(KERN_ERR PFX "cannot register miscdev on minor=%d "
 			"(err=%d)\n", WATCHDOG_MINOR, ret);
 		unregister_reboot_notifier(&epx_c3_notifier);
-		return ret;
+		goto out;
 	}
 
 	printk(banner);
 
 	return 0;
+
+out:
+	release_region(EPXC3_WATCHDOG_CTL_REG, 2);
+	return ret;
 }
 
 static void __exit watchdog_exit(void)
#4 lore raw

Re: PATCH: SBC EPX does not check/claim I/O ports it uses (2nd Edition)

Quoted 37 lines · Alan Cox
drivers/char/watchdog/sbc_epx_c3.c +6 -2
@@ -25,6 +25,7 @@
 #include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -180,12 +181,15 @@
 static int __init watchdog_init(void)
 {
 	int ret;
+	
+	if (!request_region(EPXC3_WATCHDOG_CTL_REG, 2, "epxc3_watchdog"))
+		return -EBUSY;
 
 	ret = register_reboot_notifier(&epx_c3_notifier);
 	if (ret) {
 		printk(KERN_ERR PFX "cannot register reboot notifier "
 			"(err=%d)\n", ret);
-		return ret;
+		goto out;
 	}
 
 	ret = misc_register(&epx_c3_miscdev);
@@ -193,12 +197,16 @@
 		printk(KERN_ERR PFX "cannot register miscdev on minor=%d "
 			"(err=%d)\n", WATCHDOG_MINOR, ret);
 		unregister_reboot_notifier(&epx_c3_notifier);
-		return ret;
+		goto out;
 	}
 

drivers/char/watchdog/sbc_epx_c3.c line 212

Quoted 10 lines
drivers/char/watchdog/sbc_epx_c3.c +4 -0
 	printk(banner);
 
 	return 0;
+
+out:
+	release_region(EPXC3_WATCHDOG_CTL_REG, 2);
+	return ret;
 }
 
 static void __exit watchdog_exit(void)

But now, you forgot to add release_region in this (exit) function :)?

regards,

Signature · 3 lines
Jiri Slaby         www.fi.muni.cz/~xslaby
\_.-^-._   [email protected]   _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E
#5 lore raw

Re: PATCH: SBC EPX does not check/claim I/O ports it uses (2nd Edition)

Quoted 3 lines · Jiri Slaby
Quoted 2 lines

static void __exit watchdog_exit(void)

But now, you forgot to add release_region in this (exit) function :)?

yup. That'll give a nice oops reading /proc/ioports after rmmod...

drivers/char/watchdog/sbc_epx_c3.c renamed from drivers/char/watchdog/sbc_epx_c3.c~sbc-epx-does-not-check-claim-i-o-ports-it-uses-2nd-edition-fix +1 -0
@@ -213,6 +213,7 @@ static void __exit watchdog_exit(void)
 {
 	misc_deregister(&epx_c3_miscdev);
 	unregister_reboot_notifier(&epx_c3_notifier);
+	release_region(EPXC3_WATCHDOG_CTL_REG, 2);
 }
 
 module_init(watchdog_init);

_