All of lore.kernel.org
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg KH <greg@kroah.com>,
	Grant Likely <grant.likely@secretlab.ca>,
	"Greg Kroah-Hartman" <gregkh@suse.de>,
	David Brownell <dbrownell@users.sourceforge.net>,
	spi-devel-list <spi-devel-general@lists.sourceforge.net>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	"alan@lxorguk.ukuu.org.uk" <alan@lxorguk.ukuu.org.uk>
Subject: Re: [RFC][PATCH v3] serial: spi: add spi-uart driver for Maxim 3110
Date: Thu, 25 Feb 2010 14:39:40 +0800	[thread overview]
Message-ID: <20100225143940.40e21ff7@feng-i7> (raw)
In-Reply-To: <20100224151832.42c699f2.akpm@linux-foundation.org>

On Thu, 25 Feb 2010 07:18:32 +0800
Andrew Morton <akpm@linux-foundation.org> wrote:

> > ...
> >
> > +static int max3110_main_thread(void *_max)
> > +{
> > +	struct uart_max3110 *max = _max;
> > +	wait_queue_head_t *wq = &max->wq;
> > +	int ret = 0;
> > +	struct circ_buf *xmit = &max->con_xmit;
> > +
> > +	init_waitqueue_head(wq);
> > +	pr_info(PR_FMT "start main thread\n");
> > +
> > +	do {
> > +		wait_event_interruptible(*wq,
> > +				max->flags ||
> > kthread_should_stop());
> > +		set_bit(0, &max->mthread_up);
> > +
> > +		if (use_irq && test_bit(M3110_IRQ_PENDING,
> > &max->flags)) {
> > +			max3110_con_receive(max);
> > +			clear_bit(M3110_IRQ_PENDING, &max->flags);
> > +		}
> > +
> > +		/* First handle console output */
> > +		if (test_bit(M3110_CON_TX_NEED, &max->flags)) {
> > +			send_circ_buf(max, xmit);
> > +			clear_bit(M3110_CON_TX_NEED, &max->flags);
> > +		}
> > +
> > +		/* Handle uart output */
> > +		if (test_bit(M3110_UART_TX_NEED, &max->flags)) {
> > +			transmit_char(max);
> > +			clear_bit(M3110_UART_TX_NEED, &max->flags);
> > +		}
> > +		clear_bit(0, &max->mthread_up);
> > +	} while (!kthread_should_stop());
> > +
> > +	return ret;
> > +}
> > +
> > +static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
> > +{
> > +	struct uart_max3110 *max = dev_id;
> > +
> > +	/* max3110's irq is a falling edge, not level triggered,
> > +	 * so no need to disable the irq */
> > +	set_bit(M3110_IRQ_PENDING, &max->flags);
> > +
> > +	if (!test_bit(0, &max->mthread_up))
> > +		wake_up_process(max->main_thread);
> > +
> > +	return IRQ_HANDLED;
> > +}
> 
> The manipulation of mthread_up here (and in several other places) is
> clearly quite racy.  If you hit that race, the thread will not wake up
> and the driver will sit there not doing anything until some other
> event happens.
> 
> This is perhaps fixable with test_and_set_bit() and
> test_and_clear_bit() (need to think about that) or, of course, by
> adding locking.
> 
> But a simpler fix is just to delete mthread_up altogether.
> wake_up_process() on a running process is an OK thing to do and
> hopefully isn't terribly slow.

Yes, wake_up_process won't harm a running process, our driver's case
is a little special, the console's write() func may call
wake_up_process() for every character in the buffer, thus we will
try to avoid to call it. mthread_up can't be removed as it is also
referenced in read_thread.

I prefer to use the test_and_set/clear_bit for "mthread_up".

Thanks,
Feng

diff --git a/drivers/serial/max3110.c b/drivers/serial/max3110.c
index e8c44fa..d5bd71f 100644
--- a/drivers/serial/max3110.c
+++ b/drivers/serial/max3110.c
@@ -400,7 +400,7 @@ static int max3110_main_thread(void *_max)
 	do {
 		wait_event_interruptible(*wq,
 				max->flags || kthread_should_stop());
-		set_bit(0, &max->mthread_up);
+		test_and_set_bit(0, &max->mthread_up);
 
 		if (use_irq && test_bit(M3110_IRQ_PENDING, &max->flags)) {
 			max3110_con_receive(max);
@@ -418,7 +418,7 @@ static int max3110_main_thread(void *_max)
 			transmit_char(max);
 			clear_bit(M3110_UART_TX_NEED, &max->flags);
 		}
-		clear_bit(0, &max->mthread_up);
+		test_and_clear_bit(0, &max->mthread_up);
 	} while (!kthread_should_stop());
 
 	return ret;


  reply	other threads:[~2010-02-25  6:39 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-29 14:20 [RFC][PATCH] serial: spi: add spi-uart driver for Maxim 3110 Feng Tang
2009-12-29 14:59 ` [spi-devel-general] " Baruch Siach
2009-12-29 16:05   ` Tang, Feng
2009-12-29 18:43     ` Erwin Authried
2009-12-30  1:54       ` Feng Tang
2010-02-25  4:47       ` David Brownell
2010-02-25  7:49         ` Feng Tang
2009-12-29 15:02 ` Alan Cox
2010-02-08  8:59 ` [RFC][PATCH v2] " Feng Tang
2010-02-08  8:59 ` Feng Tang
2010-02-09  0:20   ` Andrew Morton
2010-02-09  0:26     ` Grant Likely
2010-02-09  1:36       ` Feng Tang
2010-02-17 22:58         ` Greg KH
2010-02-24  5:11           ` [RFC][PATCH v3] " Feng Tang
2010-02-24 10:44             ` Alan Cox
2010-02-24 14:25               ` Grant Likely
2010-02-24 23:18             ` Andrew Morton
2010-02-25  6:39               ` Feng Tang [this message]
2010-02-25  4:43             ` David Brownell
2010-02-25  7:44               ` Feng Tang
2010-02-25  8:11                 ` David Brownell
2010-02-26  3:47             ` [PATCH v4] " Feng Tang
2010-02-26  3:47             ` Feng Tang
2010-02-26  9:59               ` Masakazu Mokuno
2010-02-26 19:41                 ` David Brownell
2010-03-01  2:30                   ` Feng Tang
2010-03-02  3:38                 ` Feng Tang
2010-02-09  9:25     ` [RFC][PATCH v2] " Alan Cox
2010-03-03  2:57   ` [PATCH v5] " Feng Tang
2010-03-03  3:59     ` Grant Likely
2010-03-03  4:51     ` David Brownell
2010-03-03  5:52       ` Feng Tang
2010-03-03  6:16         ` David Brownell
2010-03-03  6:37           ` Feng Tang
2010-03-03  7:25             ` David Brownell
2010-03-03  7:42               ` Feng Tang

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=20100225143940.40e21ff7@feng-i7 \
    --to=feng.tang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dbrownell@users.sourceforge.net \
    --cc=grant.likely@secretlab.ca \
    --cc=greg@kroah.com \
    --cc=gregkh@suse.de \
    --cc=linux-serial@vger.kernel.org \
    --cc=spi-devel-general@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.