Commit 5ef8de79 authored by Dave Jones's avatar Dave Jones Committed by Linus Torvalds

[PATCH] fix serial close hang

2.4/2.5 kernels suffer from an infinitely long hang when a serial tty device
is closed, and there are characters waiting to be sent.  The hang occurs in
tty_wait_until_sent.

There is a timeout 'closing_wait' which defines how long to wait for the TX
buffers to empty; the problem is that the serial layer totally ignores it.
It is stored in two structures, 'info' and 'state'.  It is initialised in
the 'state' structure, but used from the 'info' structure.

It turns out that 'hub6' was also missing.

I'm not currently clear what the expected behaviour should be when the
timeout is changed via setserial, and others have the port open - I've
opted to preserve the timeout until all users close the port.  It's
trivial to change this behaviour though.
parent bd4b161b
...@@ -3095,36 +3095,52 @@ static int get_async_struct(int line, struct async_struct **ret_info) ...@@ -3095,36 +3095,52 @@ static int get_async_struct(int line, struct async_struct **ret_info)
sstate = rs_table + line; sstate = rs_table + line;
sstate->count++; sstate->count++;
if (sstate->info) { info = sstate->info;
*ret_info = sstate->info;
return 0; /*
} * If the async_struct is already allocated, do the fastpath.
*/
if (info)
goto out;
info = kmalloc(sizeof(struct async_struct), GFP_KERNEL); info = kmalloc(sizeof(struct async_struct), GFP_KERNEL);
if (!info) { if (!info) {
sstate->count--; sstate->count--;
return -ENOMEM; return -ENOMEM;
} }
memset(info, 0, sizeof(struct async_struct)); memset(info, 0, sizeof(struct async_struct));
init_waitqueue_head(&info->open_wait); init_waitqueue_head(&info->open_wait);
init_waitqueue_head(&info->close_wait); init_waitqueue_head(&info->close_wait);
init_waitqueue_head(&info->delta_msr_wait); init_waitqueue_head(&info->delta_msr_wait);
info->magic = SERIAL_MAGIC; info->magic = SERIAL_MAGIC;
info->port = sstate->port; info->port = sstate->port;
info->hub6 = sstate->hub6;
info->flags = sstate->flags; info->flags = sstate->flags;
info->io_type = sstate->io_type;
info->iomem_base = sstate->iomem_base;
info->iomem_reg_shift = sstate->iomem_reg_shift;
info->xmit_fifo_size = sstate->xmit_fifo_size; info->xmit_fifo_size = sstate->xmit_fifo_size;
info->state = sstate;
info->line = line; info->line = line;
info->iomem_base = sstate->iomem_base;
info->iomem_reg_shift = sstate->iomem_reg_shift;
info->io_type = sstate->io_type;
info->tqueue.routine = do_softint; info->tqueue.routine = do_softint;
info->tqueue.data = info; info->tqueue.data = info;
info->state = sstate;
if (sstate->info) { if (sstate->info) {
kfree(info); kfree(info);
*ret_info = sstate->info; info = sstate->info;
return 0; } else {
sstate->info = info;
}
out:
/*
* If this is the first open, copy over some timeouts.
*/
if (sstate->count == 1) {
info->closing_wait = sstate->closing_wait;
} }
*ret_info = sstate->info = info; *ret_info = info;
return 0; return 0;
} }
......
...@@ -70,7 +70,7 @@ struct async_struct { ...@@ -70,7 +70,7 @@ struct async_struct {
int x_char; /* xon/xoff character */ int x_char; /* xon/xoff character */
int close_delay; int close_delay;
unsigned short closing_wait; unsigned short closing_wait;
unsigned short closing_wait2; unsigned short closing_wait2; /* obsolete */
int IER; /* Interrupt Enable Register */ int IER; /* Interrupt Enable Register */
int MCR; /* Modem control register */ int MCR; /* Modem control register */
int LCR; /* Line control register */ int LCR; /* Line control register */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment