Skip to content

Commit ef7a8c3

Browse files
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/[email protected] Cc: Manivannan Sadhasivam <[email protected]> Cc: Thomas Kopp <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 0084e29 commit ef7a8c3

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,31 @@ mcp251xfd_regmap_crc_write(void *context,
232232
count - data_offset);
233233
}
234234

235+
static int
236+
mcp251xfd_regmap_crc_read_check_crc(const struct mcp251xfd_map_buf_crc * const buf_rx,
237+
const struct mcp251xfd_map_buf_crc * const buf_tx,
238+
unsigned int data_len)
239+
{
240+
u16 crc_received, crc_calculated;
241+
242+
crc_received = get_unaligned_be16(buf_rx->data + data_len);
243+
crc_calculated = mcp251xfd_crc16_compute2(&buf_tx->cmd,
244+
sizeof(buf_tx->cmd),
245+
buf_rx->data,
246+
data_len);
247+
if (crc_received != crc_calculated)
248+
return -EBADMSG;
249+
250+
return 0;
251+
}
252+
253+
235254
static int
236255
mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv,
237256
struct spi_message *msg, unsigned int data_len)
238257
{
239258
const struct mcp251xfd_map_buf_crc *buf_rx = priv->map_buf_crc_rx;
240259
const struct mcp251xfd_map_buf_crc *buf_tx = priv->map_buf_crc_tx;
241-
u16 crc_received, crc_calculated;
242260
int err;
243261

244262
BUILD_BUG_ON(sizeof(buf_rx->cmd) != sizeof(__be16) + sizeof(u8));
@@ -248,15 +266,7 @@ mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv,
248266
if (err)
249267
return err;
250268

251-
crc_received = get_unaligned_be16(buf_rx->data + data_len);
252-
crc_calculated = mcp251xfd_crc16_compute2(&buf_tx->cmd,
253-
sizeof(buf_tx->cmd),
254-
buf_rx->data,
255-
data_len);
256-
if (crc_received != crc_calculated)
257-
return -EBADMSG;
258-
259-
return 0;
269+
return mcp251xfd_regmap_crc_read_check_crc(buf_rx, buf_tx, data_len);
260270
}
261271

262272
static int

0 commit comments

Comments
 (0)