Skip to content

Commit 1c0e78a

Browse files
can: mcp251xfd: mcp251xfd_register_get_dev_id(): fix endianness conversion
In mcp251xfd_register_get_dev_id() the device ID register is read with handcrafted SPI transfers. As all registers, this register is in little endian. Further it is not naturally aligned in struct mcp251xfd_map_buf_nocrc::data. However after the transfer the register content is converted from big endian to CPU endianness not taking care of being unaligned. Fix the conversion by converting from little endian to CPU endianness taking the unaligned source into account. Side note: So far the register content is 0x0 on all mcp251xfd compatible chips, and is only used for an informative printk. Link: https://lore.kernel.org/all/[email protected] Fixes: 55e5b97 ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN") Reviewed-by: Rasmus Villemoes <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 0ff32bf commit 1c0e78a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// Copyright (c) 2019 Martin Sperl <[email protected]>
1313
//
1414

15+
#include <asm/unaligned.h>
1516
#include <linux/bitfield.h>
1617
#include <linux/clk.h>
1718
#include <linux/device.h>
@@ -1787,7 +1788,7 @@ mcp251xfd_register_get_dev_id(const struct mcp251xfd_priv *priv, u32 *dev_id,
17871788
if (err)
17881789
goto out_kfree_buf_tx;
17891790

1790-
*dev_id = be32_to_cpup((__be32 *)buf_rx->data);
1791+
*dev_id = get_unaligned_le32(buf_rx->data);
17911792
*effective_speed_hz_slow = xfer[0].effective_speed_hz;
17921793
*effective_speed_hz_fast = xfer[1].effective_speed_hz;
17931794

0 commit comments

Comments
 (0)