public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] isicom: Fix buffer allocation
@ 2008-04-29 13:17 Alan Cox
  2008-04-29 15:26 ` Olivier Galibert
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2008-04-29 13:17 UTC (permalink / raw)
  To: akpm, linux-kernel

Fix the rather strange buffer management on open that turned up while
auditing for BKL dependancies

Signed-off-by: Alan Cox <alan@redhat.com>

diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/drivers/char/isicom.c linux-2.6.25-mm1/drivers/char/isicom.c
--- linux.vanilla-2.6.25-mm1/drivers/char/isicom.c	2008-04-28 11:36:48.000000000 +0100
+++ linux-2.6.25-mm1/drivers/char/isicom.c	2008-04-14 10:56:25.000000000 +0100
@@ -813,15 +813,13 @@
 		return 0;
 	if (!port->xmit_buf) {
 		/* Relies on BKL */
-		void *xmit_buf = (void *)get_zeroed_page(GFP_KERNEL);
-
-		if (xmit_buf == NULL)
+		unsigned long page  = get_zeroed_page(GFP_KERNEL);
+		if (page == 0)
 			return -ENOMEM;
-		if (port->xmit_buf) {
-			free_page((unsigned long)xmit_buf);
-			return -ERESTARTSYS;
-		}
-		port->xmit_buf = xmit_buf;
+		if (port->xmit_buf)
+			free_page(page);
+		else
+			port->xmit_buf = (unsigned char *) page;
 	}
 
 	spin_lock_irqsave(&card->card_lock, flags);

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

* Re: [PATCH] isicom: Fix buffer allocation
  2008-04-29 13:17 [PATCH] isicom: Fix buffer allocation Alan Cox
@ 2008-04-29 15:26 ` Olivier Galibert
  2008-04-29 15:59   ` Alan Cox
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Galibert @ 2008-04-29 15:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: alan

On Tue, Apr 29, 2008 at 02:17:33PM +0100, Alan Cox wrote:
> Fix the rather strange buffer management on open that turned up while
> auditing for BKL dependancies
> 
> Signed-off-by: Alan Cox <alan@redhat.com>
> 
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/drivers/char/isicom.c linux-2.6.25-mm1/drivers/char/isicom.c
> --- linux.vanilla-2.6.25-mm1/drivers/char/isicom.c	2008-04-28 11:36:48.000000000 +0100
> +++ linux-2.6.25-mm1/drivers/char/isicom.c	2008-04-14 10:56:25.000000000 +0100
> @@ -813,15 +813,13 @@
>  		return 0;
>  	if (!port->xmit_buf) {
>  		/* Relies on BKL */
> +		unsigned long page  = get_zeroed_page(GFP_KERNEL);
> +		if (page == 0)
>  			return -ENOMEM;
> +		if (port->xmit_buf)
> +			free_page(page);
> +		else
> +			port->xmit_buf = (unsigned char *) page;
>  	}


Still looks rather strange.  An if(x) inside an if(!x) ?

  OG.

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

* Re: [PATCH] isicom: Fix buffer allocation
  2008-04-29 15:26 ` Olivier Galibert
@ 2008-04-29 15:59   ` Alan Cox
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Cox @ 2008-04-29 15:59 UTC (permalink / raw)
  To: Olivier Galibert, linux-kernel, alan

On Tue, Apr 29, 2008 at 05:26:07PM +0200, Olivier Galibert wrote:
> > @@ -813,15 +813,13 @@
> >  		return 0;
> >  	if (!port->xmit_buf) {
> >  		/* Relies on BKL */
> > +		unsigned long page  = get_zeroed_page(GFP_KERNEL);
> > +		if (page == 0)
> >  			return -ENOMEM;
> > +		if (port->xmit_buf)
> > +			free_page(page);
> > +		else
> > +			port->xmit_buf = (unsigned char *) page;
> >  	}
> 
> 
> Still looks rather strange.  An if(x) inside an if(!x) ?

The joys of parallelism. The serial drivers mostly do this because they
are using the BKL for open/close paths being a bit prehistoric (its on
the hit list ;))

CPU #1

	open
	port->xmit_buf == NULL
	get_zeroed_page [Can sleep dropping BKL]

CPU #2

	get_zeroed_page
	port->xmit_buf == NULL
		port->xmit_buf = page

CPU #1

	port->xmit_buf != NULL
		free page

A fine example of why proper locking is good ;)


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

end of thread, other threads:[~2008-04-29 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-29 13:17 [PATCH] isicom: Fix buffer allocation Alan Cox
2008-04-29 15:26 ` Olivier Galibert
2008-04-29 15:59   ` Alan Cox

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