linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: Feng Tang <feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: "david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org"
	<david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>,
	"alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org"
	<alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	"spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org"
	<spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: [PATCH] spi: enable spi_board_info to be registered after spi_master
Date: Wed, 28 Jul 2010 10:22:29 +0800	[thread overview]
Message-ID: <20100728102229.68486f87@feng-i7> (raw)
In-Reply-To: <20100728092306.1168ab7c@feng-i7>

On Wed, 28 Jul 2010 09:23:06 +0800
Feng Tang <feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:

> > > @@ -537,6 +557,10 @@ int spi_register_master(struct spi_master
> > > *master) dev_dbg(dev, "registered master %s%s\n",
> > > dev_name(&master->dev), dynamic ? " (dynamic)" : "");
> > >
> > > +       mutex_lock(&master_lock);
> > > +       list_add_tail(&master->list, &master_list);
> > > +       mutex_unlock(&master_lock);
> > > +
> > 
> > There seems to be a race condition here.  If a boardinfo is
> > registered after this list add, but before scan_boardinfo(master),
> > then a boardinfo can get parsed twice for a single master.  I think
> > the proper thing to do is to hold the mutex over the whole
> > operation; from registering the list or master, until after the
> > scan is complete.
> > 
> 
> Good point. Maybe moving the list_add(master) after scan_boardinfo() 
> can fix this race condition.

My solution still has problem, it was:

	scan_boardinfo(master);

        mutex_lock(&spi_master_lock);
        list_add_tail(&master->list, &spi_master_list);
        mutex_unlock(&spi_master_lock);

If another boardinfo registering just after scan_boardinfo() but before
list_add(), it will still get ignored.

I will just follow Grant's suggestion.

Thanks,
Feng

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/

      reply	other threads:[~2010-07-28  2:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-27  9:42 [PATCH] spi: enable spi_board_info to be registered after spi_master Feng Tang
     [not found] ` <1280223769-19919-1-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2010-07-27 17:27   ` Grant Likely
     [not found]     ` <AANLkTi=C48+mnNjrxha8WqagCybF45f7aTn6nxt2qRuU-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-28  1:23       ` Feng Tang
2010-07-28  2:22         ` Feng Tang [this message]

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=20100728102229.68486f87@feng-i7 \
    --to=feng.tang-ral2jqcrhueavxtiumwx3w@public.gmane.org \
    --cc=alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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;
as well as URLs for NNTP newsgroup(s).