diff mbox series

[net-next,v2] net: enetc: use get/put_unaligned helpers for MAC address handling

Message ID 20210604134212.6982-1-michael@walle.cc (mailing list archive)
State Accepted
Commit ecb0605810f395961ea70c34e8946198bacd2f2d
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] net: enetc: use get/put_unaligned helpers for MAC address handling | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Michael Walle June 4, 2021, 1:42 p.m. UTC
The supplied buffer for the MAC address might not be aligned. Thus
doing a 32bit (or 16bit) access could be on an unaligned address. For
now, enetc is only used on aarch64 which can do unaligned accesses, thus
there is no error. In any case, be correct and use the get/put_unaligned
helpers.

Signed-off-by: Michael Walle <michael@walle.cc>
---
changes since v1:
 - explicitly use the little endian variant of the helpers

 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Claudiu Manoil June 4, 2021, 1:47 p.m. UTC | #1
> -----Original Message-----
> From: Michael Walle <michael@walle.cc>
> Sent: Friday, June 4, 2021 4:42 PM
[...]
> Subject: [PATCH net-next v2] net: enetc: use get/put_unaligned helpers for
> MAC address handling
> 
> The supplied buffer for the MAC address might not be aligned. Thus
> doing a 32bit (or 16bit) access could be on an unaligned address. For
> now, enetc is only used on aarch64 which can do unaligned accesses, thus
> there is no error. In any case, be correct and use the get/put_unaligned
> helpers.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>

Reviewed-by: Claudiu Manoil <claudiu.manoil@nxp.com>
patchwork-bot+netdevbpf@kernel.org June 4, 2021, 9:40 p.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Fri,  4 Jun 2021 15:42:12 +0200 you wrote:
> The supplied buffer for the MAC address might not be aligned. Thus
> doing a 32bit (or 16bit) access could be on an unaligned address. For
> now, enetc is only used on aarch64 which can do unaligned accesses, thus
> there is no error. In any case, be correct and use the get/put_unaligned
> helpers.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> 
> [...]

Here is the summary with links:
  - [net-next,v2] net: enetc: use get/put_unaligned helpers for MAC address handling
    https://git.kernel.org/netdev/net-next/c/ecb0605810f3

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 31274325159a..c84f6c226743 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -1,6 +1,7 @@ 
 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
 /* Copyright 2017-2019 NXP */
 
+#include <asm/unaligned.h>
 #include <linux/mdio.h>
 #include <linux/module.h>
 #include <linux/fsl/enetc_mdio.h>
@@ -17,15 +18,15 @@  static void enetc_pf_get_primary_mac_addr(struct enetc_hw *hw, int si, u8 *addr)
 	u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
 	u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si));
 
-	*(u32 *)addr = upper;
-	*(u16 *)(addr + 4) = lower;
+	put_unaligned_le32(upper, addr);
+	put_unaligned_le16(lower, addr + 4);
 }
 
 static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
 					  const u8 *addr)
 {
-	u32 upper = *(const u32 *)addr;
-	u16 lower = *(const u16 *)(addr + 4);
+	u32 upper = get_unaligned_le32(addr);
+	u16 lower = get_unaligned_le16(addr + 4);
 
 	__raw_writel(upper, hw->port + ENETC_PSIPMAR0(si));
 	__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));