Failures to open a serial port can result in the module
count being decremented too much. If it goes negative,
you can't unload the serial module.
The problem is due to the behavior of tty_open() in
tty_io.c when the call to tty->driver.open() (rs_open()
in serial.c) returns an error. It calls release_dev()
in tty_io.c which calls tty->driver.close() (rs_close()
in serial.c). The module usage count has been
incremented by rs_open() but decremented by both
rs_open() and rs_close(), resulting in an incorrect
module usage count.
To reproduce the problem, try the following as root on
a configured, available serial port which has nothing
plugged into it.
$ lsmod | grep serial
serial 54128 0
$ stty -clocal < /dev/ttyS0
$ stty clocal </dev/ttyS0
# The above will block for ever waiting for carrier
detect.
# Hit Ctrl-C to interrupt.
$ lsmod | grep serial
serial 54128 -1
$
The patch removes most of the MOD_DEC_USE_COUNT calls
in rs_open() apart from a few cases at the start of the
function for which the rs_close() call doesn't do it
either.
Patch to fix module usage count problem in serial-5.05