Skip to content

Commit eb5adc7

Browse files
stonezdmjcmvbkbc
authored andcommitted
arch: xtensa: platforms: Fix deadlock in rs_close()
There is a deadlock in rs_close(), which is shown below: (Thread 1) | (Thread 2) | rs_open() rs_close() | mod_timer() spin_lock_bh() //(1) | (wait a time) ... | rs_poll() del_timer_sync() | spin_lock() //(2) (wait timer to stop) | ... We hold timer_lock in position (1) of thread 1 and use del_timer_sync() to wait timer to stop, but timer handler also need timer_lock in position (2) of thread 2. As a result, rs_close() will block forever. This patch deletes the redundant timer_lock in order to prevent the deadlock. Because there is no race condition between rs_close, rs_open and rs_poll. Signed-off-by: Duoming Zhou <[email protected]> Message-Id: <[email protected]> Signed-off-by: Max Filippov <[email protected]>
1 parent ee69d4b commit eb5adc7

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

arch/xtensa/platforms/iss/console.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,19 @@ static void rs_poll(struct timer_list *);
3636
static struct tty_driver *serial_driver;
3737
static struct tty_port serial_port;
3838
static DEFINE_TIMER(serial_timer, rs_poll);
39-
static DEFINE_SPINLOCK(timer_lock);
4039

4140
static int rs_open(struct tty_struct *tty, struct file * filp)
4241
{
43-
spin_lock_bh(&timer_lock);
4442
if (tty->count == 1)
4543
mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
46-
spin_unlock_bh(&timer_lock);
4744

4845
return 0;
4946
}
5047

5148
static void rs_close(struct tty_struct *tty, struct file * filp)
5249
{
53-
spin_lock_bh(&timer_lock);
5450
if (tty->count == 1)
5551
del_timer_sync(&serial_timer);
56-
spin_unlock_bh(&timer_lock);
5752
}
5853

5954

@@ -73,8 +68,6 @@ static void rs_poll(struct timer_list *unused)
7368
int rd = 1;
7469
unsigned char c;
7570

76-
spin_lock(&timer_lock);
77-
7871
while (simc_poll(0)) {
7972
rd = simc_read(0, &c, 1);
8073
if (rd <= 0)
@@ -87,7 +80,6 @@ static void rs_poll(struct timer_list *unused)
8780
tty_flip_buffer_push(port);
8881
if (rd)
8982
mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
90-
spin_unlock(&timer_lock);
9183
}
9284

9385

0 commit comments

Comments
 (0)