Skip to content

Commit

Permalink
SPI: use mutex not semaphore
Browse files Browse the repository at this point in the history
Make spi_write_then_read() use a mutex not a binary semaphore.

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>
  • Loading branch information
David Brownell authored and Linus Torvalds committed Dec 5, 2007
1 parent f8fcc93 commit 068f407
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ int spi_write_then_read(struct spi_device *spi,
const u8 *txbuf, unsigned n_tx,
u8 *rxbuf, unsigned n_rx)
{
static DECLARE_MUTEX(lock);
static DEFINE_MUTEX(lock);

int status;
struct spi_message message;
Expand All @@ -615,7 +615,7 @@ int spi_write_then_read(struct spi_device *spi,
}

/* ... unless someone else is using the pre-allocated buffer */
if (down_trylock(&lock)) {
if (!mutex_trylock(&lock)) {
local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
if (!local_buf)
return -ENOMEM;
Expand All @@ -634,7 +634,7 @@ int spi_write_then_read(struct spi_device *spi,
}

if (x[0].tx_buf == buf)
up(&lock);
mutex_unlock(&lock);
else
kfree(local_buf);

Expand Down

0 comments on commit 068f407

Please sign in to comment.