Skip to content

Commit 9080873

Browse files
committed
spi: Factor validation and initialisation of messages outside lock
Currently we do a bunch of per-message validation and initialisation in __spi_async() which is called with the bus lock held. Since none of this validation depends on the current bus status there's no need to hold the lock to do it so split it out into a separate __spi_validate() function which is called prior to taking the bus lock. This could be slightly neater but keep things simple for now to show the code motion clearly. Based on observations from Martin Sperl. Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent 6ce4eac commit 9080873

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

‎drivers/spi/spi.c‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,15 +1596,11 @@ int spi_setup(struct spi_device *spi)
15961596
}
15971597
EXPORT_SYMBOL_GPL(spi_setup);
15981598

1599-
static int __spi_async(struct spi_device *spi, struct spi_message *message)
1599+
static int __spi_validate(struct spi_device *spi, struct spi_message *message)
16001600
{
16011601
struct spi_master *master = spi->master;
16021602
struct spi_transfer *xfer;
16031603

1604-
message->spi = spi;
1605-
1606-
trace_spi_message_submit(message);
1607-
16081604
if (list_empty(&message->transfers))
16091605
return -EINVAL;
16101606
if (!message->complete)
@@ -1705,6 +1701,18 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
17051701
}
17061702

17071703
message->status = -EINPROGRESS;
1704+
1705+
return 0;
1706+
}
1707+
1708+
static int __spi_async(struct spi_device *spi, struct spi_message *message)
1709+
{
1710+
struct spi_master *master = spi->master;
1711+
1712+
message->spi = spi;
1713+
1714+
trace_spi_message_submit(message);
1715+
17081716
return master->transfer(spi, message);
17091717
}
17101718

@@ -1743,6 +1751,10 @@ int spi_async(struct spi_device *spi, struct spi_message *message)
17431751
int ret;
17441752
unsigned long flags;
17451753

1754+
ret = __spi_validate(spi, message);
1755+
if (ret != 0)
1756+
return ret;
1757+
17461758
spin_lock_irqsave(&master->bus_lock_spinlock, flags);
17471759

17481760
if (master->bus_lock_flag)
@@ -1791,6 +1803,10 @@ int spi_async_locked(struct spi_device *spi, struct spi_message *message)
17911803
int ret;
17921804
unsigned long flags;
17931805

1806+
ret = __spi_validate(spi, message);
1807+
if (ret != 0)
1808+
return ret;
1809+
17941810
spin_lock_irqsave(&master->bus_lock_spinlock, flags);
17951811

17961812
ret = __spi_async(spi, message);

0 commit comments

Comments
 (0)