]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commit
spi: bugfix spi_add_device() with duplicate chipselects
authorDavid Brownell <dbrownell@users.sourceforge.net>
Fri, 15 Aug 2008 07:40:44 +0000 (00:40 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Aug 2008 15:35:44 +0000 (08:35 -0700)
commite48880e02e7e7ead9daa47fe3a20486f550668d3
treee46cb1788109caf59fcb77453dffd43fec6e305e
parent7d455e0030eeab820773e7786605be4d9e56a04b
spi: bugfix spi_add_device() with duplicate chipselects

When reviewing a recent patch I noticed a potential trouble spot in the
registration of new SPI devices.  The SPI master driver is told to set
the device up before adding it to the driver model, so that it's always
properly set up when probe() is called.  (This is important, because in
the case of inverted chipselects, this device can make the bus misbehave
until it's properly deselected.  It's got to be set up even if no driver
binds to the device.)

The trouble spot is that it doesn't first verify that no other device
has been added using that chipselect.  If such a device has been added,
its configuration gets trashed.  (Fortunately this has not been a common
error!)

The fix here adds an explicit check, and a mutex to protect the relevant
critical region.

[akpm@linux-foundation.org: make the lock local to spi_add_device()]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/spi/spi.c