From ef7a8c3e75994f2bdaa27b481de39ea000119d11 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Mon, 15 Mar 2021 08:59:15 +0100 Subject: [PATCH] can: mcp251xfd: mcp251xfd_regmap_crc_read_one(): Factor out crc check into separate function This patch factors out the crc check into a separate function. This is preparation for the next patch. Link: https://lore.kernel.org/r/20210406110617.1865592-4-mkl@pengutronix.de Cc: Manivannan Sadhasivam Cc: Thomas Kopp Signed-off-by: Marc Kleine-Budde --- .../net/can/spi/mcp251xfd/mcp251xfd-regmap.c | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c index 314f868b3465..35557ac43c03 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c @@ -233,20 +233,11 @@ mcp251xfd_regmap_crc_write(void *context, } static int -mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv, - struct spi_message *msg, unsigned int data_len) +mcp251xfd_regmap_crc_read_check_crc(const struct mcp251xfd_map_buf_crc * const buf_rx, + const struct mcp251xfd_map_buf_crc * const buf_tx, + unsigned int data_len) { - const struct mcp251xfd_map_buf_crc *buf_rx = priv->map_buf_crc_rx; - const struct mcp251xfd_map_buf_crc *buf_tx = priv->map_buf_crc_tx; u16 crc_received, crc_calculated; - int err; - - BUILD_BUG_ON(sizeof(buf_rx->cmd) != sizeof(__be16) + sizeof(u8)); - BUILD_BUG_ON(sizeof(buf_tx->cmd) != sizeof(__be16) + sizeof(u8)); - - err = spi_sync(priv->spi, msg); - if (err) - return err; crc_received = get_unaligned_be16(buf_rx->data + data_len); crc_calculated = mcp251xfd_crc16_compute2(&buf_tx->cmd, @@ -259,6 +250,25 @@ mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv, return 0; } + +static int +mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv, + struct spi_message *msg, unsigned int data_len) +{ + const struct mcp251xfd_map_buf_crc *buf_rx = priv->map_buf_crc_rx; + const struct mcp251xfd_map_buf_crc *buf_tx = priv->map_buf_crc_tx; + int err; + + BUILD_BUG_ON(sizeof(buf_rx->cmd) != sizeof(__be16) + sizeof(u8)); + BUILD_BUG_ON(sizeof(buf_tx->cmd) != sizeof(__be16) + sizeof(u8)); + + err = spi_sync(priv->spi, msg); + if (err) + return err; + + return mcp251xfd_regmap_crc_read_check_crc(buf_rx, buf_tx, data_len); +} + static int mcp251xfd_regmap_crc_read(void *context, const void *reg_p, size_t reg_len,