Skip to contentSkip to conversation

at91_emac: fix compile warning

PATCH New Andreas Bießmann 2 participants 6 messages Jun 9, 2011 – Jun 12, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 at91_emac: fix compile warning

This patch removes the warning

---8<---
at91_emac.c: In function 'at91emac_write_hwaddr':
at91_emac.c:487:2: warning: dereferencing type-punned pointer will break strict-aliasing rules --->8---

---
BEWARE! This patch is only compile tested!

It is possible, that there is an endianess problem. It would be great, if one could test it on real hardware!

Reinhard, you could adopt the macb driver also to get the warning there fixed. If it works on at91sam this way it would also work on at91rm9200 cause they have the same endianess.

 drivers/net/at91_emac.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/at91_emac.c +7 -5
index b09ff8c..97d2739 100644
@@ -481,11 +481,13 @@ static int at91emac_write_hwaddr(struct eth_device *netdev)
 	dev = (emac_device *) netdev->priv;
 
 	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
-		cpu_to_le32(*((u32 *)netdev->enetaddr)));
-	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
-	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
+	DEBUG_AT91EMAC("init MAC-ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
+		netdev->enetaddr[5], netdev->enetaddr[4], netdev->enetaddr[3],
+		netdev->enetaddr[2], netdev->enetaddr[1], netdev->enetaddr[0]);
+	writel( (netdev->enetaddr[0] | netdev->enetaddr[1] << 8 |
+			netdev->enetaddr[2] << 16 | netdev->enetaddr[3] << 24),
+			&emac->sa2l);
+	writel((netdev->enetaddr[4] | netdev->enetaddr[5] << 8), &emac->sa2h);
 	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
 		readl(&emac->sa2h), readl(&emac->sa2l));
 	return 0;
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 1/1 at91_emac: fix compile warning

Dear Andreas Bie?mann,

Quoted 7 lines

This patch removes the warning

---8<---
at91_emac.c: In function 'at91emac_write_hwaddr':
at91_emac.c:487:2: warning: dereferencing type-punned pointer will break strict-aliasing rules --->8---

Quoted 6 lines

---
BEWARE! This patch is only compile tested!

It is possible, that there is an endianess problem. It would be great, if one could test it on real hardware!

If you have the time, can you make the same patch for macb? I can test it later on our hardware.

Quoted 4 lines

Reinhard, you could adopt the macb driver also to get the warning there fixed. If it works on at91sam this way it would also work on at91rm9200 cause they have the same endianess.

See above ;)

Quoted 13 lines
 drivers/net/at91_emac.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/at91_emac.c +0 -1
index b09ff8c..97d2739 100644
@@ -481,11 +481,13 @@ static int at91emac_write_hwaddr(struct eth_device *netdev)
 	dev = (emac_device *) netdev->priv;
 
 	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",

drivers/net/at91_emac.c static int at91emac_write_hwaddr(struct eth_device *netdev) · line 489

Quoted 10 lines
drivers/net/at91_emac.c +6 -4
-		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
-		cpu_to_le32(*((u32 *)netdev->enetaddr)));
-	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
-	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
+	DEBUG_AT91EMAC("init MAC-ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
+		netdev->enetaddr[5], netdev->enetaddr[4], netdev->enetaddr[3],
+		netdev->enetaddr[2], netdev->enetaddr[1], netdev->enetaddr[0]);
+	writel( (netdev->enetaddr[0] | netdev->enetaddr[1] << 8 |
+			netdev->enetaddr[2] << 16 | netdev->enetaddr[3] << 24),
+			&emac->sa2l);

OUCH, I would think by precedence rules, | comes before << !?!?! Can you verify and supply a new patch if that holds true?

drivers/net/at91_emac.c static int at91emac_write_hwaddr(struct eth_device *netdev) · line 491

Quoted 2 lines
drivers/net/at91_emac.c +1 -0
+	writel((netdev->enetaddr[4] | netdev->enetaddr[5] << 8), &emac->sa2h);
 	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",

If you touch the file next time, can you remove that space before the \n ?

drivers/net/at91_emac.c static int at91emac_write_hwaddr(struct eth_device *netdev) · line 493

Quoted 2 lines
drivers/net/at91_emac.c +0 -0
 		readl(&emac->sa2h), readl(&emac->sa2l));
 	return 0;

Already applied to u-boot-atmel/master,
Thanks,
Reinhard

#2 lore raw

PATCH 1/1 at91_emac: fix compile warning

Dear Reinahrd Meyer,

Am 09.06.2011 13:08, schrieb Reinhard Meyer:

Quoted 12 lines

Dear Andreas Bie?mann,

Quoted 11 lines

This patch removes the warning

---8<---
at91_emac.c: In function 'at91emac_write_hwaddr':
at91_emac.c:487:2: warning: dereferencing type-punned pointer will break strict-aliasing rules --->8---

---
BEWARE! This patch is only compile tested!

Quoted 5 lines
Quoted 2 lines

It is possible, that there is an endianess problem. It would be great, if one could test it on real hardware!

If you have the time, can you make the same patch for macb? I can test it later on our hardware.

will do ..

Quoted 6 lines
Quoted 4 lines

Reinhard, you could adopt the macb driver also to get the warning there fixed. If it works on at91sam this way it would also work on at91rm9200 cause they have the same endianess.

See above ;)

great ...

Quoted 6 lines
Quoted 6 lines
drivers/net/at91_emac.c +0 -5
 	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
-		cpu_to_le32(*((u32 *)netdev->enetaddr)));
-	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
-	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
Quoted 8 lines

drivers/net/at91_emac.c static int at91emac_write_hwaddr(struct eth_device *netdev) · line 489

Quoted 6 lines
drivers/net/at91_emac.c +6 -0
+	DEBUG_AT91EMAC("init MAC-ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
+		netdev->enetaddr[5], netdev->enetaddr[4], netdev->enetaddr[3],
+		netdev->enetaddr[2], netdev->enetaddr[1], netdev->enetaddr[0]);
+	writel( (netdev->enetaddr[0] | netdev->enetaddr[1] << 8 |
+			netdev->enetaddr[2] << 16 | netdev->enetaddr[3] << 24),
+			&emac->sa2l);

OUCH, I would think by precedence rules, | comes before << !?!?!

You are wrong, try the following:

---8<---

# cat main.c
#include <stdio.h>

int main(void)

{
    unsigned int test1 = (1 << 8 | 1);
    unsigned int test2 = ((1 << 8) | 1);
    printf("test1 = %x\ntest2 = %x\n", test1, test2);
}
# gcc main.c
# ./a.out
test1 = 101
test2 = 101
--->8---
Quoted 1 line

Can you verify and supply a new patch if that holds true?

Is the test ok?

Quoted 1 line

Already applied to u-boot-atmel/master,

But why do you apply the patch, if there are questions?

regards

Andreas Bie?mann

#3 lore raw

PATCH 1/1 at91_emac: fix compile warning

Dear Andreas Bie?mann,

Quoted 7 lines
Quoted 5 lines

drivers/net/at91_emac.c static int at91emac_write_hwaddr(struct eth_device *netdev) · line 489

Quoted 3 lines
drivers/net/at91_emac.c +3 -0
+	writel( (netdev->enetaddr[0] | netdev->enetaddr[1] << 8 |
+			netdev->enetaddr[2] << 16 | netdev->enetaddr[3] << 24),
+			&emac->sa2l);

OUCH, I would think by precedence rules, | comes before << !?!?!

You are wrong, try the following:

Yep, just checked the table ;) -
+ comes before <<, but << comes before |, hence the mixup :)

Quoted 3 lines
Quoted 1 line

Already applied to u-boot-atmel/master,

But why do you apply the patch, if there are questions?

At first, the << | seemed ok to me, so I applied ;)

Regards,
Reinhard

#4 lore raw

PATCH 1/1 at91_emac: fix compile warning

Dear Reinhard Meyer,

Am 09.06.2011 14:06, schrieb Reinhard Meyer:

Quoted 7 lines

Dear Andreas Bie?mann,

Quoted 3 lines
Quoted 1 line

Already applied to u-boot-atmel/master,

But why do you apply the patch, if there are questions?

At first, the << | seemed ok to me, so I applied ;)

Well that is ok, but this have never run on real hardware. Therefore it would be great if one (Jens or Eric) could add their tested-by ..

So please test the v2 for macb and I'm fine with that.

regards

Andreas Bie?mann

#5 lore raw

PATCH 1/1 at91_emac: fix compile warning

In reply to Andreas Bießmann

Dear Andreas Bie?mann,

Am 09.06.2011 um 12:22 schrieb Andreas Bie?mann:

Quoted 10 lines

This patch removes the warning

---8<---
at91_emac.c: In function 'at91emac_write_hwaddr':
at91_emac.c:487:2: warning: dereferencing type-punned pointer will break strict-aliasing rules --->8---

---
BEWARE! This patch is only compile tested!

The patch was tested on real hardware and it works.

regards

Andreas Bie?mann