linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Feng Tang <feng.tang@intel.com>
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: Wed, 24 Feb 2010 15:18:32 -0800	[thread overview]
Message-ID: <20100224151832.42c699f2.akpm@linux-foundation.org> (raw)
In-Reply-To: <20100224131130.61530b62@feng-i7>

On Wed, 24 Feb 2010 13:11:30 +0800 Feng Tang <feng.tang@intel.com> wrote:

> Hi All,
> 
> Here is a driver for Maxim 3110 SPI-UART device, please help to review.
> 
> It has been validated with Designware SPI controller (drivers/spi: dw_spi.c &
> dw_spi_pci.c). It supports polling and IRQ mode, supports batch read, and
> provides a console.
> 
> change log:
>  since v2:
> 	* Address comments from Andrew Morton
> 	* Use test/set_bit to avoid race condition for SMP/preempt case
> 	* Fix bug related with endian order
> 
>  since v1:
>         * Address comments from Alan Cox
>         * Use a "use_irq" module parameter to runtime check whether
>           to use IRQ mode
>         * Add the suspend/resume implementation
> 
> Thanks!
> Feng
> 
> >From 93455ea6fbf0bfb6494b88ea83296f26f29f7eee Mon Sep 17 00:00:00 2001
> From: Feng Tang <feng.tang@intel.com>
> Date: Tue, 23 Feb 2010 17:52:00 +0800
> Subject: [PATCH] serial: spi: add spi-uart driver for Maxim 3110
> 
> This is the driver for Max3110 SPI-UART device, which connect
> to host with SPI interface. It supports baud rates from 300 to
> 230400, and supports both polling and IRQ mode, as well as
> providing a console for system use
> 
> Its datasheet could be found here:
> http://datasheets.maxim-ic.com/en/ds/MAX3110E-MAX3111E.pdf
> 
> ...
>
> +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.

> +/* If don't use RX IRQ, then need a thread to polling read */
> +static int max3110_read_thread(void *_max)
> +{
> +	struct uart_max3110 *max = _max;
> +
> +	pr_info(PR_FMT "start read thread\n");
> +	do {
> +		if (!test_bit(0, &max->mthread_up))
> +			max3110_con_receive(max);
> +
> +		set_current_state(TASK_INTERRUPTIBLE);
> +		schedule_timeout_interruptible(HZ / 20);

The set_current_state(TASK_INTERRUPTIBLE) is unneeded.

> +	} while (!kthread_should_stop());
> +
> +	return 0;
> +}


  parent reply	other threads:[~2010-02-24 23:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20091229222006.1ddb28a4@feng-desktop>
2009-12-29 14:59 ` [spi-devel-general] [RFC][PATCH] serial: spi: add spi-uart driver for Maxim 3110 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
     [not found] ` <20100208165946.0e4dde83@feng-i7>
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 [this message]
2010-02-25  6:39               ` Feng Tang
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
     [not found]             ` <20100226114729.679bb933@feng-i7>
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=20100224151832.42c699f2.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dbrownell@users.sourceforge.net \
    --cc=feng.tang@intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).