Skip to content

Commit

Permalink
spi: consolidate setting message->spi
Browse files Browse the repository at this point in the history
Previously, __spi_sync() and __spi_async() set message->spi to the spi
device independently after calling __spi_validate(). __spi_validate()
also would conditionally set this if it needed to split the message
since it wasn't set yet.

Since both __spi_sync() and __spi_async() call __spi_validate(), we can
consolidate this into only setting message->spi once (unconditionally)
in __spi_validate(). This will also save any future callers of
__spi_validate() from also needing to set message->spi.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://msgid.link/r/20240123214946.2616786-1-dlechner@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
David Lechner authored and Mark Brown committed Jan 24, 2024
1 parent 18ab9e9 commit b204aa0
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4059,6 +4059,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
if (list_empty(&message->transfers))
return -EINVAL;

message->spi = spi;

/*
* If an SPI controller does not support toggling the CS line on each
* transfer (indicated by the SPI_CS_WORD flag) or we are using a GPIO
Expand All @@ -4071,9 +4073,6 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
size_t maxsize = BITS_TO_BYTES(spi->bits_per_word);
int ret;

/* spi_split_transfers_maxsize() requires message->spi */
message->spi = spi;

ret = spi_split_transfers_maxsize(ctlr, message, maxsize,
GFP_KERNEL);
if (ret)
Expand Down Expand Up @@ -4210,8 +4209,6 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
if (!ctlr->transfer)
return -ENOTSUPP;

message->spi = spi;

SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, spi_async);
SPI_STATISTICS_INCREMENT_FIELD(spi->pcpu_statistics, spi_async);

Expand Down Expand Up @@ -4391,8 +4388,6 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message)
if (status != 0)
return status;

message->spi = spi;

SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, spi_sync);
SPI_STATISTICS_INCREMENT_FIELD(spi->pcpu_statistics, spi_sync);

Expand Down

0 comments on commit b204aa0

Please sign in to comment.