]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
tty/isicom: Fix a possible sleep-in-atomic bug in WaitTillCardIsFree
authorJia-Ju Bai <baijiaju1990@gmail.com>
Tue, 12 Dec 2017 13:24:56 +0000 (21:24 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Dec 2017 19:24:14 +0000 (20:24 +0100)
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>
drivers/tty/isicom.c

index 015686ff48255fedbf0705111f9abc2afd99e63b..bdd3027ef01b6d4dbfdf9cd40f2923410cd82a8f 100644 (file)
@@ -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);
 }