netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Claudiu Manoil <claudiu.manoil@freescale.com>
To: <netdev@vger.kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Xiubo Li <Li.Xiubo@freescale.com>,
	Shruti Kanetkar <Shruti@freescale.com>
Subject: [net 6/8] gianfar: Make MAC addr setup endian safe, cleanup
Date: Fri, 3 Oct 2014 19:02:47 +0300	[thread overview]
Message-ID: <1412352169-14414-7-git-send-email-claudiu.manoil@freescale.com> (raw)
In-Reply-To: <1412352169-14414-1-git-send-email-claudiu.manoil@freescale.com>

Fix the 32-bit memory access that is not endian safe,
i.e. not giving the desired byte layout for a LE CPU:
tempval = *((u32 *) (tmpbuf + 4)), where 'char tmpbuf[]'.

Get rid of rendundant local vars (tmpbuf[] and idx) and
forced casts.  Cleanup comments.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
---
 drivers/net/ethernet/freescale/gianfar.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index 37e0604..961198a 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -3248,22 +3248,21 @@ static void gfar_set_mac_for_addr(struct net_device *dev, int num,
 {
 	struct gfar_private *priv = netdev_priv(dev);
 	struct gfar __iomem *regs = priv->gfargrp[0].regs;
-	int idx;
-	char tmpbuf[ETH_ALEN];
 	u32 tempval;
 	u32 __iomem *macptr = &regs->macstnaddr1;
 
 	macptr += num*2;
 
-	/* Now copy it into the mac registers backwards, cuz
-	 * little endian is silly
+	/* For a station address of 0x12345678ABCD in transmission
+	 * order (BE), MACnADDR1 is set to 0xCDAB7856 and
+	 * MACnADDR2 is set to 0x34120000.
 	 */
-	for (idx = 0; idx < ETH_ALEN; idx++)
-		tmpbuf[ETH_ALEN - 1 - idx] = addr[idx];
+	tempval = (addr[5] << 24) | (addr[4] << 16) |
+		  (addr[3] << 8)  |  addr[2];
 
-	gfar_write(macptr, *((u32 *) (tmpbuf)));
+	gfar_write(macptr, tempval);
 
-	tempval = *((u32 *) (tmpbuf + 4));
+	tempval = (addr[1] << 24) | (addr[0] << 16);
 
 	gfar_write(macptr+1, tempval);
 }
-- 
1.7.11.7

  parent reply	other threads:[~2014-10-03 16:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-03 16:02 [net 0/8] gianfar: ARM port driver updates (1/2) Claudiu Manoil
2014-10-03 16:02 ` [net 1/8] net/fsl_pq_mdio: Fix asm/ucc.h compile error for ARM Claudiu Manoil
2014-10-03 18:39   ` Sergei Shtylyov
2014-10-03 16:02 ` [net 2/8] net/fsl_pq_mdio: Use ioread/iowrite32be() portable accessors Claudiu Manoil
2014-10-03 16:02 ` [net 3/8] net/fsl_pq_mdio: Replace spin_event_timeout() with arch independent Claudiu Manoil
2014-10-03 16:02 ` [net 4/8] gianfar: Include missing headers for ARM builds Claudiu Manoil
2014-10-03 16:02 ` [net 5/8] gianfar: Exclude PPC specific errata handling from " Claudiu Manoil
2014-10-03 16:02 ` Claudiu Manoil [this message]
2014-10-03 16:02 ` [net 7/8] gianfar: Replace spin_event_timeout() with arch independent Claudiu Manoil
2014-10-03 16:02 ` [net 8/8] gianfar: Replace eieio with wmb for non-PPC archs Claudiu Manoil
2014-10-03 21:20 ` [net 0/8] gianfar: ARM port driver updates (1/2) Kim Phillips
2014-10-06  1:27 ` David Miller
2014-10-06  7:55   ` Claudiu Manoil
2014-10-06 19:07     ` David Miller

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=1412352169-14414-7-git-send-email-claudiu.manoil@freescale.com \
    --to=claudiu.manoil@freescale.com \
    --cc=Li.Xiubo@freescale.com \
    --cc=Shruti@freescale.com \
    --cc=davem@davemloft.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).