netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: netdev@vger.kernel.org
Subject: [PATCH v2 6/7] alx: fix MAC address alignment problem
Date: Tue, 25 Jun 2013 20:38:22 +0200	[thread overview]
Message-ID: <1372185503-24705-7-git-send-email-johannes@sipsolutions.net> (raw)
In-Reply-To: <1372185503-24705-1-git-send-email-johannes@sipsolutions.net>

In two places, parts of MAC addresses are used as u32/u16
values. This can cause alignment problems, use put_unaligned
and get_unaligned to fix this.

Reported-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
 drivers/net/ethernet/atheros/alx/hw.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/atheros/alx/hw.c b/drivers/net/ethernet/atheros/alx/hw.c
index 2a2bbe9..6b34855 100644
--- a/drivers/net/ethernet/atheros/alx/hw.c
+++ b/drivers/net/ethernet/atheros/alx/hw.c
@@ -282,8 +282,8 @@ static bool alx_read_macaddr(struct alx_hw *hw, u8 *addr)
 	mac1 = alx_read_mem32(hw, ALX_STAD1);
 
 	/* addr should be big-endian */
-	*(__be32 *)(addr + 2) = cpu_to_be32(mac0);
-	*(__be16 *)addr = cpu_to_be16(mac1);
+	put_unaligned(cpu_to_be32(mac0), (__be32 *)(addr + 2));
+	put_unaligned(cpu_to_be16(mac1), (__be16 *)addr);
 
 	return is_valid_ether_addr(addr);
 }
@@ -326,9 +326,9 @@ void alx_set_macaddr(struct alx_hw *hw, const u8 *addr)
 	u32 val;
 
 	/* for example: 00-0B-6A-F6-00-DC * STAD0=6AF600DC, STAD1=000B */
-	val = be32_to_cpu(*(__be32 *)(addr + 2));
+	val = be32_to_cpu(get_unaligned((__be32 *)(addr + 2)));
 	alx_write_mem32(hw, ALX_STAD0, val);
-	val = be16_to_cpu(*(__be16 *)addr);
+	val = be16_to_cpu(get_unaligned((__be16 *)addr));
 	alx_write_mem32(hw, ALX_STAD1, val);
 }
 
-- 
1.8.0

  parent reply	other threads:[~2013-06-25 18:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-25 18:38 [PATCH v2 0/7] alx: small fixes/cleanups Johannes Berg
2013-06-25 18:38 ` [PATCH v2 1/7] alx: treat flow control correctly in alx_set_pauseparam() Johannes Berg
2013-06-25 18:38 ` [PATCH v2 2/7] alx: fix 100mbit/full duplex speed translation Johannes Berg
2013-06-25 19:32   ` Joe Perches
2013-06-25 18:38 ` [PATCH v2 3/7] alx: remove NET_CORE Kconfig select Johannes Berg
2013-06-25 18:38 ` [PATCH v2 4/7] alx: make sizes unsigned Johannes Berg
2013-06-25 18:38 ` [PATCH v2 5/7] alx: separate link speed/duplex fields Johannes Berg
2013-06-25 18:38 ` Johannes Berg [this message]
2013-06-25 18:38 ` [PATCH v2 7/7] alx: fix ethtool support code Johannes Berg
2013-06-25 21:01 ` [PATCH v2 0/7] alx: small fixes/cleanups Johannes Stezenbach
2013-06-29 17:20   ` Johannes Berg
2013-06-29 18:56     ` Johannes Stezenbach
2013-06-26  0:11 ` David Miller
2013-06-29 16:53   ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1372185503-24705-7-git-send-email-johannes@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).