diff options
author | Jia-Ju Bai <baijiaju1990@gmail.com> | 2017-12-12 16:24:56 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-12-15 22:24:14 +0300 |
commit | fe8e7acea2426dcd1130fd5c9710b74217c90dd0 (patch) | |
tree | 865a507d64c1ba033fe1d994bd1ee0552d77cb92 /drivers/tty/isicom.c | |
parent | be7e251d20e6c800b3b9ee79d1da6059438c34f8 (diff) | |
download | linux-fe8e7acea2426dcd1130fd5c9710b74217c90dd0.tar.xz |
tty/isicom: Fix a possible sleep-in-atomic bug in WaitTillCardIsFree
The driver may sleep under a spinlock.
The function call paths are:
isicom_activate (acquire the spinlock)
isicom_setup_board
drop_dtr_rts
WaitTillCardIsFree
msleep --> may sleep
isicom_set_termios
isicom_config_port
drop_dtr
WaitTillCardIsFree
msleep --> may sleep
isicom_tiocmset
drop_dtr
WaitTillCardIsFree
msleep --> may sleep
Though "in_atomic" is used to check atomic context,
but it is not recommended to use in driver code (see include/linux/preempt.h).
To fix it, only using mdelay instead.
This bug is found by my static analysis tool(DSAC) and checked by my code review.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/isicom.c')
-rw-r--r-- | drivers/tty/isicom.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/drivers/tty/isicom.c b/drivers/tty/isicom.c index 015686ff4825..bdd3027ef01b 100644 --- a/drivers/tty/isicom.c +++ b/drivers/tty/isicom.c @@ -219,13 +219,9 @@ static struct isi_port isi_ports[PORT_COUNT]; static int WaitTillCardIsFree(unsigned long base) { unsigned int count = 0; - unsigned int a = in_atomic(); /* do we run under spinlock? */ while (!(inw(base + 0xe) & 0x1) && count++ < 100) - if (a) - mdelay(1); - else - msleep(1); + mdelay(1); return !(inw(base + 0xe) & 0x1); } |