Skip to content

Commit 52267fe

Browse files
dlechbroonie
authored andcommitted
spi: use spi_valid_{tx,rx}buf() in stats function
There are macros spi_valid_txbuf() and spi_valid_rxbuf() for determining if an xfer actually intended to send or receive data. These checks were hard-coded in spi_statistics_add_transfer_stats(). We can make use of the macros instead to make the code more readable and more robust against potential future changes in case the definition of what valid means changes. The macro takes the spi_message as an argument, so we need to change spi_statistics_add_transfer_stats() to take the spi_message as an argument instead of the controller. Signed-off-by: David Lechner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 4776679 commit 52267fe

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

drivers/spi/spi.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static const struct attribute_group *spi_master_groups[] = {
312312

313313
static void spi_statistics_add_transfer_stats(struct spi_statistics __percpu *pcpu_stats,
314314
struct spi_transfer *xfer,
315-
struct spi_controller *ctlr)
315+
struct spi_message *msg)
316316
{
317317
int l2len = min(fls(xfer->len), SPI_STATISTICS_HISTO_SIZE) - 1;
318318
struct spi_statistics *stats;
@@ -328,11 +328,9 @@ static void spi_statistics_add_transfer_stats(struct spi_statistics __percpu *pc
328328
u64_stats_inc(&stats->transfer_bytes_histo[l2len]);
329329

330330
u64_stats_add(&stats->bytes, xfer->len);
331-
if ((xfer->tx_buf) &&
332-
(xfer->tx_buf != ctlr->dummy_tx))
331+
if (spi_valid_txbuf(msg, xfer))
333332
u64_stats_add(&stats->bytes_tx, xfer->len);
334-
if ((xfer->rx_buf) &&
335-
(xfer->rx_buf != ctlr->dummy_rx))
333+
if (spi_valid_rxbuf(msg, xfer))
336334
u64_stats_add(&stats->bytes_rx, xfer->len);
337335

338336
u64_stats_update_end(&stats->syncp);
@@ -1618,8 +1616,8 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
16181616
list_for_each_entry(xfer, &msg->transfers, transfer_list) {
16191617
trace_spi_transfer_start(msg, xfer);
16201618

1621-
spi_statistics_add_transfer_stats(statm, xfer, ctlr);
1622-
spi_statistics_add_transfer_stats(stats, xfer, ctlr);
1619+
spi_statistics_add_transfer_stats(statm, xfer, msg);
1620+
spi_statistics_add_transfer_stats(stats, xfer, msg);
16231621

16241622
if (!ctlr->ptp_sts_supported) {
16251623
xfer->ptp_sts_word_pre = 0;

0 commit comments

Comments
 (0)