Skip to contentSkip to conversation

Convert serial_core oopses to BUG_ON

PATCH In review Russell King 6 participants 12 messages Feb 26, 2006 – Mar 1, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Convert serial_core oopses to BUG_ON

Hi,

With reference to these two bugs:

	http://bugzilla.kernel.org/show_bug.cgi?id=5958
	http://bugzilla.kernel.org/show_bug.cgi?id=6131

it seems that folk are under the impression that serial_core is responsible for these bugs. It isn't.

Calling serial functions to flush buffers, or try to send more data after the port has been closed or hung up is a bug in the code doing the calling, not in the serial_core driver.

Make this explicitly obvious by adding BUG_ON()'s.

I don't particularly want to add these BUG_ON()'s since they have a performance impact, but it seems that they're necessary to convey sufficient understanding about where the bug lies. The Bluetooth problem has been around for _ages_ (longer than the entry in bugzilla) and no one seems the least bit interested in fixing the fscking thing.

I can only hope that adding these BUG_ON()'s provides sufficient clarity to cause people to look elsewhere.

drivers/serial/serial_core.c +17 -0
@@ -71,6 +71,11 @@ static void uart_change_pm(struct uart_s
 void uart_write_wakeup(struct uart_port *port)
 {
 	struct uart_info *info = port->info;
+	/*
+	 * This means you called this function _after_ the port was
+	 * closed.  No cookie for you.
+	 */
+	BUG_ON(!info);
 	tasklet_schedule(&info->tlet);
 }
 
@@ -479,6 +484,12 @@ uart_write(struct tty_struct *tty, const
 	unsigned long flags;
 	int c, ret = 0;
 
+	/*
+	 * This means you called this function _after_ the port was
+	 * closed.  No cookie for you.
+	 */
+	BUG_ON(!state);
+
 	if (!circ->buf)
 		return 0;
 
@@ -521,6 +532,12 @@ static void uart_flush_buffer(struct tty
 	struct uart_port *port = state->port;
 	unsigned long flags;
 
+	/*
+	 * This means you called this function _after_ the port was
+	 * closed.  No cookie for you.
+	 */
+	BUG_ON(!state);
+
 	DPRINTK("uart_flush_buffer(%d) called\n", tty->index);
 
 	spin_lock_irqsave(&port->lock, flags);
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#1 lore raw
Quoted 6 lines · Russell King

Calling serial functions to flush buffers, or try to send more data
after the port has been closed or hung up is a bug in the code doing the calling, not in the serial_core driver.

Make this explicitly obvious by adding BUG_ON()'s.

If we make it

	if (!info) {
		WARN_ON(1);
		return;
	}

will that allow people's kernels to limp along until it gets fixed?

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 5 lines · Russell King

Calling serial functions to flush buffers, or try to send more data after the port has been closed or hung up is a bug in the code doing the calling, not in the serial_core driver.

Make this explicitly obvious by adding BUG_ON()'s.

Quoted 8 lines

If we make it

	if (!info) {
		WARN_ON(1);
		return;
	}

will that allow people's kernels to limp along until it gets fixed?

Any reason we don't have a WARN(), btw?

Signature · 2 lines
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 
#3 lore raw
In reply to Andrew Morton
Quoted 8 lines · Andrew Morton
Quoted 6 lines · Russell King

Calling serial functions to flush buffers, or try to send more data
after the port has been closed or hung up is a bug in the code doing the calling, not in the serial_core driver.

Make this explicitly obvious by adding BUG_ON()'s.

Quoted 8 lines

If we make it

	if (!info) {
		WARN_ON(1);
		return;
	}

will that allow people's kernels to limp along until it gets fixed?

"until" - I think you mean "if anyone ever bothers" so no I don't agree. The bluetooth folk seem to have absolutely no interest in bug fixing. Can we mark bluetooth broken please?

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#4 lore raw
Quoted 8 lines · Russell King
Quoted 7 lines · Andrew Morton

If we make it

	if (!info) {
		WARN_ON(1);
		return;
	}
Quoted 5 lines
Quoted 1 line

will that allow people's kernels to limp along until it gets fixed?

"until" - I think you mean "if anyone ever bothers" so no I don't agree. The bluetooth folk seem to have absolutely no interest in bug fixing. Can we mark bluetooth broken please?

Sorry, I mean just mark BT_HCIUART broken, not the whole of bluetooth.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#5 lore raw
In reply to Andrew Morton
Quoted 8 lines · Andrew Morton
Quoted 6 lines · Russell King

Calling serial functions to flush buffers, or try to send more data
after the port has been closed or hung up is a bug in the code doing the calling, not in the serial_core driver.

Make this explicitly obvious by adding BUG_ON()'s.

Quoted 8 lines

If we make it

	if (!info) {
		WARN_ON(1);
		return;
	}

will that allow people's kernels to limp along until it gets fixed?

It will oops in hard-to-guess, place, anyway. BUG_ON is right.

Signature · 1 line
Thanks, Sharp!
#6 lore raw
Quoted 13 lines · Pavel Machek
Quoted 10 lines · Andrew Morton
Quoted 6 lines · Russell King

Calling serial functions to flush buffers, or try to send more data
after the port has been closed or hung up is a bug in the code doing the calling, not in the serial_core driver.

Make this explicitly obvious by adding BUG_ON()'s.

If we make it

Quoted 8 lines
Quoted 6 lines
	if (!info) {
		WARN_ON(1);
		return;
	}

will that allow people's kernels to limp along until it gets fixed?

It will oops in hard-to-guess, place, anyway.

Will it? Where? Unfixably?

Quoted 1 line

BUG_ON is right.

WARN_ON+return is far better. It keeps people's machines working until the bug gets fixed.

#7 lore raw
Quoted 2 lines · Andrew Morton
Quoted 1 line

It will oops in hard-to-guess, place, anyway.

Will it? Where? Unfixably?

http://www.linux-mips.org/archives/linux-mips/2006-02/msg00241.html is one example we just had on MIPS. On SGI IP22, using the serial console, you'd get the following on shutdown:

The system is going down for reboot NOW!
INIT: Sending processes the TERM signal
INIT: Sending proces

and then nothing at all. I'd never have suspected the serial driver, had not users reported that the machine shutdowns properly when using the framebuffer.

For the record, I don't mind whether it's BUG_ON or WARN_ON, but I just wanted to give this as an example of an "oops in hard-to-guess, place".

Signature · 2 lines
Martin Michlmayr
[email protected]
#8 lore raw
Quoted 17 lines · Martin Michlmayr
Quoted 2 lines · Andrew Morton
Quoted 1 line

It will oops in hard-to-guess, place, anyway.

Will it? Where? Unfixably?

http://www.linux-mips.org/archives/linux-mips/2006-02/msg00241.html is one example we just had on MIPS. On SGI IP22, using the serial console, you'd get the following on shutdown:

The system is going down for reboot NOW!
INIT: Sending processes the TERM signal
INIT: Sending proces

and then nothing at all. I'd never have suspected the serial driver, had not users reported that the machine shutdowns properly when using the framebuffer.

Quoted 5 lines

For the record, I don't mind whether it's BUG_ON or WARN_ON, but I just wanted to give this as an example of an "oops in hard-to-guess, place".

From my reading of the above thread, putting the proposed workaround into

serial core will indeed allow people's machines to keep running while reminding us about the driver bugs.

#9 lore raw
Quoted 18 lines · Andrew Morton
Quoted 17 lines · Martin Michlmayr
Quoted 2 lines · Andrew Morton
Quoted 1 line

It will oops in hard-to-guess, place, anyway.

Will it? Where? Unfixably?

http://www.linux-mips.org/archives/linux-mips/2006-02/msg00241.html is one example we just had on MIPS. On SGI IP22, using the serial console, you'd get the following on shutdown:

The system is going down for reboot NOW!
INIT: Sending processes the TERM signal
INIT: Sending proces

and then nothing at all. I'd never have suspected the serial driver, had not users reported that the machine shutdowns properly when using the framebuffer.

Quoted 7 lines
Quoted 5 lines

For the record, I don't mind whether it's BUG_ON or WARN_ON, but I just wanted to give this as an example of an "oops in hard-to-guess, place".

From my reading of the above thread, putting the proposed workaround into

serial core will indeed allow people's machines to keep running while reminding us about the driver bugs.

I would much rather the buggy drivers were actually fixed - is there a reason why the drivers can't actually be fixed (other than lazyness)?

Once they're fixed, adding a BUG_ON then becomes practical IMHO - it'll stop new driver writers being confused.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#10 lore raw
Quoted 24 lines · Russell King
Quoted 23 lines · Andrew Morton
Quoted 22 lines · Martin Michlmayr
Quoted 2 lines · Andrew Morton
Quoted 1 line

It will oops in hard-to-guess, place, anyway.

Will it? Where? Unfixably?

http://www.linux-mips.org/archives/linux-mips/2006-02/msg00241.html is one example we just had on MIPS. On SGI IP22, using the serial console, you'd get the following on shutdown:

The system is going down for reboot NOW!
INIT: Sending processes the TERM signal
INIT: Sending proces

and then nothing at all. I'd never have suspected the serial driver, had not users reported that the machine shutdowns properly when using the framebuffer.

For the record, I don't mind whether it's BUG_ON or WARN_ON, but I just wanted to give this as an example of an "oops in hard-to-guess, place".

From my reading of the above thread, putting the proposed workaround into

Quoted 8 lines
Quoted 2 lines

serial core will indeed allow people's machines to keep running while reminding us about the driver bugs.

I would much rather the buggy drivers were actually fixed - is there a reason why the drivers can't actually be fixed (other than lazyness)?

Once they're fixed, adding a BUG_ON then becomes practical IMHO - it'll stop new driver writers being confused.

Okay, but lets add BUG_ONs that actually work. BUG_ON in second hunk could never trigger, and last hunk did not help in specific case of bluetooth problem. This should be better: it warns at right places, but allows system to survive. I'll now try to fix bluetooth problem.

drivers/serial/serial_core.c +29 -3
index 95fb493..cc1faa3 100644
@@ -71,6 +71,11 @@ static void uart_change_pm(struct uart_s
 void uart_write_wakeup(struct uart_port *port)
 {
 	struct uart_info *info = port->info;
+	/*
+	 * This means you called this function _after_ the port was
+	 * closed.  No cookie for you.
+	 */
+	BUG_ON(!info);
 	tasklet_schedule(&info->tlet);
 }
 
@@ -471,14 +476,26 @@ static void uart_flush_chars(struct tty_
 }
 
 static int
-uart_write(struct tty_struct *tty, const unsigned char * buf, int count)
+uart_write(struct tty_struct *tty, const unsigned char *buf, int count)
 {
 	struct uart_state *state = tty->driver_data;
-	struct uart_port *port = state->port;
-	struct circ_buf *circ = &state->info->xmit;
+	struct uart_port *port;
+	struct circ_buf *circ;
 	unsigned long flags;
 	int c, ret = 0;
 
+	/*
+	 * This means you called this function _after_ the port was
+	 * closed.  No cookie for you.
+	 */
+	if (!state || !state->info) {
+		WARN_ON(1);
+		return -EL3HLT;
+	}
+
+	port = state->port;
+	circ = &state->info->xmit;
+
 	if (!circ->buf)
 		return 0;
 
@@ -521,6 +538,15 @@ static void uart_flush_buffer(struct tty
 	struct uart_port *port = state->port;
 	unsigned long flags;
 
+	/*
+	 * This means you called this function _after_ the port was
+	 * closed.  No cookie for you.
+	 */
+	if (!state || !state->info) {
+		WARN_ON(1);
+		return;
+	}
+
 	DPRINTK("uart_flush_buffer(%d) called\n", tty->index);
 
 	spin_lock_irqsave(&port->lock, flags);
Signature · 1 line
Web maintainer for suspend.sf.net (www.sf.net/projects/suspend) wanted...
#11 lore raw
Quoted 9 lines · Pavel Machek
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

From my reading of the above thread, putting the proposed workaround into

serial core will indeed allow people's machines to keep running while reminding us about the driver bugs.

I would much rather the buggy drivers were actually fixed - is there a reason why the drivers can't actually be fixed (other than lazyness)?

Quoted 7 lines
Quoted 2 lines

Once they're fixed, adding a BUG_ON then becomes practical IMHO - it'll stop new driver writers being confused.

Okay, but lets add BUG_ONs that actually work. BUG_ON in second hunk could never trigger, and last hunk did not help in specific case of bluetooth problem. This should be better: it warns at right places, but allows system to survive.

I like that approach, thanks.

Quoted 1 line

I'll now try to fix bluetooth problem.

Please keep Marcel Cc'ed.

drivers/serial/serial_core.c static void uart_flush_chars(struct tty_ · line 493

Quoted 1 line
drivers/serial/serial_core.c +1 -0
+		return -EL3HLT;

ooh, I always wanted to use that ;)