From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Arjan van de Ven <arjan@linux.intel.com>,
Alan Cox <alan@linux.intel.com>,
Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 08/67] serial: fix wakup races in the mrst_max3110 driver
Date: Thu, 5 Aug 2010 15:22:35 -0700 [thread overview]
Message-ID: <1281047014-23429-8-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20100805213528.GA13794@kroah.com>
From: Arjan van de Ven <arjan@linux.intel.com>
The mrst_max3110 driver had a set of unsafe wakeup sequences
along the following line:
if (!atomic_read(&foo)) {
atomic_set(&foo, 1);
wake_up(worker_thread);
}
and the worker thread would do
if (atomic_read(&foo)) {
do_work();
atomic_set(&foo, 0);
}
which can result in various missed wakups due to test-then-set races,
as well as due to clear-after-work instead of clear-before-work.
This patch fixes these races by using the proper bit test-and-set operations,
and by doing clear-before-work.
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/serial/mrst_max3110.c | 46 ++++++++++++++++-------------------------
1 files changed, 18 insertions(+), 28 deletions(-)
diff --git a/drivers/serial/mrst_max3110.c b/drivers/serial/mrst_max3110.c
index 0341853..f6ad1ec 100644
--- a/drivers/serial/mrst_max3110.c
+++ b/drivers/serial/mrst_max3110.c
@@ -48,6 +48,10 @@
#define PR_FMT "mrst_max3110: "
+#define UART_TX_NEEDED 1
+#define CON_TX_NEEDED 2
+#define BIT_IRQ_PENDING 3
+
struct uart_max3110 {
struct uart_port port;
struct spi_device *spi;
@@ -63,15 +67,13 @@ struct uart_max3110 {
u8 clock;
u8 parity, word_7bits;
- atomic_t uart_tx_need;
+ unsigned long uart_flags;
/* console related */
struct circ_buf con_xmit;
- atomic_t con_tx_need;
/* irq related */
u16 irq;
- atomic_t irq_pending;
};
/* global data structure, may need be removed */
@@ -176,10 +178,9 @@ static void serial_m3110_con_putchar(struct uart_port *port, int ch)
xmit->head = (xmit->head + 1) & (PAGE_SIZE - 1);
}
- if (!atomic_read(&max->con_tx_need)) {
- atomic_set(&max->con_tx_need, 1);
+
+ if (!test_and_set_bit(CON_TX_NEEDED, &max->uart_flags))
wake_up_process(max->main_thread);
- }
}
/*
@@ -318,10 +319,8 @@ static void serial_m3110_start_tx(struct uart_port *port)
struct uart_max3110 *max =
container_of(port, struct uart_max3110, port);
- if (!atomic_read(&max->uart_tx_need)) {
- atomic_set(&max->uart_tx_need, 1);
+ if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags))
wake_up_process(max->main_thread);
- }
}
static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
@@ -392,32 +391,23 @@ static int max3110_main_thread(void *_max)
pr_info(PR_FMT "start main thread\n");
do {
- wait_event_interruptible(*wq, (atomic_read(&max->irq_pending) ||
- atomic_read(&max->con_tx_need) ||
- atomic_read(&max->uart_tx_need)) ||
- kthread_should_stop());
+ wait_event_interruptible(*wq, max->uart_flags || kthread_should_stop());
mutex_lock(&max->thread_mutex);
-#ifdef CONFIG_MRST_MAX3110_IRQ
- if (atomic_read(&max->irq_pending)) {
+ if (test_and_clear_bit(BIT_IRQ_PENDING, &max->uart_flags))
max3110_console_receive(max);
- atomic_set(&max->irq_pending, 0);
- }
-#endif
/* first handle console output */
- if (atomic_read(&max->con_tx_need)) {
+ if (test_and_clear_bit(CON_TX_NEEDED, &max->uart_flags))
send_circ_buf(max, xmit);
- atomic_set(&max->con_tx_need, 0);
- }
/* handle uart output */
- if (atomic_read(&max->uart_tx_need)) {
+ if (test_and_clear_bit(UART_TX_NEEDED, &max->uart_flags))
transmit_char(max);
- atomic_set(&max->uart_tx_need, 0);
- }
+
mutex_unlock(&max->thread_mutex);
+
} while (!kthread_should_stop());
return ret;
@@ -430,10 +420,9 @@ static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
/* max3110's irq is a falling edge, not level triggered,
* so no need to disable the irq */
- if (!atomic_read(&max->irq_pending)) {
- atomic_inc(&max->irq_pending);
+ if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags))
wake_up_process(max->main_thread);
- }
+
return IRQ_HANDLED;
}
#else
@@ -753,7 +742,8 @@ static int serial_m3110_probe(struct spi_device *spi)
max->baud = 0;
max->cur_conf = 0;
- atomic_set(&max->irq_pending, 0);
+ max->uart_flags = 0;
+
/* Check if reading configuration register returns something sane */
res = RC_TAG;
--
1.7.2
next prev parent reply other threads:[~2010-08-05 22:47 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-05 21:35 [GIT PATCH] TTY patches for 2.6.36 Greg KH
2010-08-05 22:22 ` [PATCH 01/67] n_gsm.c: removed duplicated #includes Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 02/67] serial: There's no config CONSOLE Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 03/67] vt: clean up the code - use kernel library Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 04/67] serial: add UART_CAP_EFR and UART_CAP_SLEEP flags to 16C950 UARTs definition Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 05/67] mrst_max3110: add UART driver for Max3110 on Moorestown Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 06/67] max3110 sanity check a register Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 07/67] serial: replace open coded mutex with a real mutex in mrst_max3110.c Greg Kroah-Hartman
2010-08-05 22:22 ` Greg Kroah-Hartman [this message]
2010-08-05 22:22 ` [PATCH 09/67] tty: Remove Hayes ESP ioctls Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 10/67] tty: remove remaining " Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 11/67] tty: Add EXTPROC support for LINEMODE Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 12/67] vt/console: try harder to print output when panicing Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 13/67] stallion: prune lock_kernel calls Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 14/67] istallion: use bit ops for the board flags Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 15/67] riscom8: kill use of lock_kernel Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 16/67] isicom: kill off the BKL Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 17/67] rocket: kill BKL Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 18/67] synclink: kill the big kernel lock Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 19/67] cyclades: Kill off BKL usage Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 20/67] epca: Kill the big kernel lock Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 21/67] specialix: Kill the BKL Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 22/67] tty: Fix the digi acceleport driver NULL checks Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 23/67] synclink: reworking locking a bit Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 24/67] tty: serial - fix various misuses/mishandlings of port->tty Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 25/67] tty: serial - fix tty back references in termios Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 26/67] tty: serial - fix tty referencing in set_ldisc Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 27/67] vc: Locking clean up Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 28/67] tty: Make vt's have a tty_port Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 29/67] tty: Move the vt_tty field from the vc_data into the standard tty_port Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 30/67] serial: Change the wait for carrier locking Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 31/67] serial: add port helpers Greg Kroah-Hartman
2010-08-05 22:22 ` [PATCH 32/67] serial: trim locking on the helpers Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 33/67] serial: Use block_til_ready helper Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 34/67] serial: fix termios settings in open Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 35/67] tty: replace BKL with a new tty_lock Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 36/67] tty: never hold BTM while getting tty_mutex Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 37/67] tty: fix console_sem lock order Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 38/67] cdc-acm: remove dead code Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 39/67] tty: introduce wait_event_interruptible_tty Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 40/67] tty: reorder ldisc locking Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 41/67] tty: untangle locking of wait_until_sent Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 42/67] tty: remove tty_lock_nested Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 43/67] tty: implement BTM as mutex instead of BKL Greg Kroah-Hartman
2010-08-06 19:40 ` [PATCH retry] " Arnd Bergmann
2010-08-05 22:23 ` [PATCH 44/67] tty: release BTM while sleeping in block_til_ready Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 45/67] 8250: fix set_ldisc operation Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 46/67] tty: avoid recursive BTM in pty_close Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 47/67] serial: max3107: introduce a max3107 driver Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 48/67] serial: max3107: Abstract out the platform specific bits Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 49/67] tty_io: remove casts from void* Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 50/67] vt: Fix warning: statement with no effect due to vt_kern.h Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 51/67] serial: crisv10: formatting of pointers in printk() Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 52/67] serial: "altera_uart: simplify altera_uart_console_putc()" checkpatch fixes Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 53/67] serial: fix missing bit coverage of ASYNC_FLAGS Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 54/67] serial: general fixes in the serial_rs485 structure Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 55/67] serial: mcf: don't take spinlocks in already protected functions Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 56/67] serial: MMIO32 support for 8250_early.c Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 57/67] timbuart: use __devinit and __devexit macros for probe and remove Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 58/67] serial: 68328serial.c: remove dead (ALMA_ANS | DRAGONIXVZ | M68EZ328ADS) Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 59/67] serial: add support for OX16PCI958 card Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 60/67] mxser: remove unnesesary NULL check Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 61/67] hsu: driver for Medfield High Speed UART device Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 62/67] hsu: add a periodic timer to check dma rx channel Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 63/67] hsu: some code cleanup Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 64/67] hsu: call PCI pm hooks in suspend/resume function Greg Kroah-Hartman
2010-08-05 22:23 ` [PATCH 65/67] serial: max3107: Fix gpiolib support Greg Kroah-Hartman
2010-08-06 18:40 ` [GIT PATCH] TTY patches for 2.6.36 Linus Torvalds
2010-08-06 18:51 ` Greg KH
2010-08-06 19:40 ` Arnd Bergmann
2010-08-06 19:45 ` Alan Cox
2010-08-06 19:37 ` Greg KH
2010-08-06 19:38 ` Linus Torvalds
2010-08-06 19:58 ` Arnd Bergmann
2010-08-06 20:11 ` Linus Torvalds
2010-08-06 20:19 ` Arnd Bergmann
2010-08-06 20:22 ` Greg KH
2010-08-09 16:06 ` Andy Whitcroft
2010-08-09 18:38 ` Arnd Bergmann
2010-08-09 19:24 ` Alan Cox
2010-08-10 7:31 ` Andy Whitcroft
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1281047014-23429-8-git-send-email-gregkh@suse.de \
--to=gregkh@suse.de \
--cc=alan@linux.intel.com \
--cc=arjan@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox