public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/cdrom/isp16.c check_region() fix
@ 2003-12-29 19:42 Omkhar Arasaratnam
  2003-12-29 20:04 ` Christoph Hellwig
  2003-12-29 20:13 ` viro
  0 siblings, 2 replies; 3+ messages in thread
From: Omkhar Arasaratnam @ 2003-12-29 19:42 UTC (permalink / raw)
  To: axeboe; +Cc: linux-kernel

check_region is depreciated in 2.6, this replaces it with request_region

As this is my first patch to the kernel, please let me know if I did anything wrong


--- /usr/src/linux/drivers/cdrom/isp16.c	2001-09-07 12:28:38.000000000 -0400
+++ drivers/cdrom/isp16.c	2003-12-29 14:07:24.000000000 -0500
@@ -121,11 +121,12 @@
 		return (0);
 	}
 
-	if (check_region(ISP16_IO_BASE, ISP16_IO_SIZE)) {
+	if (!request_region(ISP16_IO_BASE, ISP16_IO_SIZE,"isp16")) {
 		printk("ISP16: i/o ports already in use.\n");
 		return (-EIO);
 	}
-
+	release_region(ISP16_IO_BASE, ISP16_IO_SIZE);
+	
 	if ((isp16_type = isp16_detect()) < 0) {
 		printk("ISP16: no cdrom interface found.\n");
 		return (-EIO);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/cdrom/isp16.c check_region() fix
  2003-12-29 19:42 [PATCH] drivers/cdrom/isp16.c check_region() fix Omkhar Arasaratnam
@ 2003-12-29 20:04 ` Christoph Hellwig
  2003-12-29 20:13 ` viro
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2003-12-29 20:04 UTC (permalink / raw)
  To: Omkhar Arasaratnam; +Cc: axeboe, linux-kernel

On Mon, Dec 29, 2003 at 02:42:23PM -0500, Omkhar Arasaratnam wrote:
> --- /usr/src/linux/drivers/cdrom/isp16.c	2001-09-07 12:28:38.000000000 -0400
> +++ drivers/cdrom/isp16.c	2003-12-29 14:07:24.000000000 -0500
> @@ -121,11 +121,12 @@
>  		return (0);
>  	}
>  
> -	if (check_region(ISP16_IO_BASE, ISP16_IO_SIZE)) {
> +	if (!request_region(ISP16_IO_BASE, ISP16_IO_SIZE,"isp16")) {
>  		printk("ISP16: i/o ports already in use.\n");
>  		return (-EIO);
>  	}
> -
> +	release_region(ISP16_IO_BASE, ISP16_IO_SIZE);

This doesn't really buy you anything.  You must claim the I/O ports as long
as you're possibly using them - i.e. claim them early when probing for
the device, and release them only when you're done with the device.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/cdrom/isp16.c check_region() fix
  2003-12-29 19:42 [PATCH] drivers/cdrom/isp16.c check_region() fix Omkhar Arasaratnam
  2003-12-29 20:04 ` Christoph Hellwig
@ 2003-12-29 20:13 ` viro
  1 sibling, 0 replies; 3+ messages in thread
From: viro @ 2003-12-29 20:13 UTC (permalink / raw)
  To: Omkhar Arasaratnam; +Cc: axeboe, linux-kernel

On Mon, Dec 29, 2003 at 02:42:23PM -0500, Omkhar Arasaratnam wrote:
> check_region is depreciated in 2.6, this replaces it with request_region
> 
> As this is my first patch to the kernel, please let me know if I did anything wrong

It's pointless - the reason why check_region() is bad applies to your code.
The problem with check_region() is simple - it gives no protection against
somebody else grabbing the ports in question just as you've got "it's free"
from check_region().  The same problem exists with your replacement -
as soon as you've released the region it could've been grabbed by anybody.

Note that there's another problem - on rmmod we release the region we
hadn't grabbed.  Proper fix is
	a) replace check_region with request_region
	b) check that we don't have any IO on those ports before that
point (surprisingly many drivers are buggy that way - they do some IO
and then go "oops, looks like somebody held these ports after all;
oh, well, let's hope we hadn't screwed them too badly").  AFAICS isp16
is OK in that repect, though.
	c) make sure that we release that region on all failure exits
past that point, so that insmod failure would not leave it grabbed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-29 20:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-29 19:42 [PATCH] drivers/cdrom/isp16.c check_region() fix Omkhar Arasaratnam
2003-12-29 20:04 ` Christoph Hellwig
2003-12-29 20:13 ` viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox