net/fec: "u32" is more explicit than "unsigned long"
PATCH 1/1 net/fec: "u32" is more explicit than "unsigned long"
tmpaddr[] is a six byte array. We want to set the first four bytes on the first line and the remaining two on the next line. The code assumes that "unsigned long" is 32 bits and obviously that's not true on 64 bit arches. It's better to just use u32 instead.
---
This is a static checker thing and I can't compile this file.
drivers/net/ethernet/freescale/fec_main.c +0 -2
@@ -1100,9 +1100,9 @@ static void fec_get_mac(struct net_device *ndev)* 4) FEC mac registers set by bootloader */ if (!is_valid_ether_addr (iap)) { - *((unsigned long *) &tmpaddr[0]) + *((u32 *) &tmpaddr[0]) be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW)); - *((unsigned short *) &tmpaddr[4]) + *((u16 *) &tmpaddr[4]) be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16); iap = &tmpaddr[0 ]; }
Quoted 14 lines · Dan Carpenter
tmpaddr[] is a six byte array. We want to set the first four bytes on the first line and the remaining two on the next line. The code assumes that "unsigned long" is 32 bits and obviously that's not true on 64 bit arches. It's better to just use u32 instead.
Signed-off-by Dan Carpenter <[email protected]>---
This is a static checker thing and I can't compile this file.drivers/net/ethernet/freescale/fec_main.c +0
-0
drivers/net/ethernet/freescale/fec_main.c static void fec_get_mac(struct net_device *ndev) · line 1104
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-2@@ -1100,9 +1100,9 @@ static void fec_get_mac(struct net_device *ndev)* 4) FEC mac registers set by bootloader */ if (!is_valid_ether_addr (iap)) { - *((unsigned long *) &tmpaddr[0 ]) > + *((u32 *) &tmpaddr[0 ]) >be32_to_cpu (readl (fep->hwp +FEC_ADDR_LOW )); - *((unsigned short *) &tmpaddr[4 ]) > + *((u16 *) &tmpaddr[4 ]) >be16_to_cpu (readl (fep->hwp +FEC_ADDR_HIGH ) >>16 ); iap = &tmpaddr[0 ]; }
This code also seems to have CPU vs big-endian byte order the wrong way round. readl() returns bytes in native order whereas we always store MAC addresses in network (big-endian) order. So I think it should be doing:
*((__be32 *) &tmpaddr[0]) cpu_to_be32(readl(fep->hwp + FEC_ADDR_LOW)); *((__be16 *) &tmpaddr[4]) cpu_to_be16(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
David Miller
maintainerFrom: Ben Hutchings <[email protected]>
Date: Fri, 23 Aug 2013 13:44:29 +0100
Quoted 28 lines · Dan Carpenter
Quoted 14 lines
tmpaddr[] is a six byte array. We want to set the first four bytes on the first line and the remaining two on the next line. The code assumes that "unsigned long" is 32 bits and obviously that's not true on 64 bit arches. It's better to just use u32 instead.
Signed-off-by Dan Carpenter <[email protected]>---
This is a static checker thing and I can't compile this file.drivers/net/ethernet/freescale/fec_main.c +0
-0drivers/net/ethernet/freescale/fec_main.c static void fec_get_mac(struct net_device *ndev) · line 1104
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +0
-2@@ -1100,9 +1100,9 @@ static void fec_get_mac(struct net_device *ndev)* 4) FEC mac registers set by bootloader */ if (!is_valid_ether_addr (iap)) { - *((unsigned long *) &tmpaddr[0 ]) >> + *((u32 *) &tmpaddr[0 ]) >>be32_to_cpu (readl (fep->hwp +FEC_ADDR_LOW )); - *((unsigned short *) &tmpaddr[4 ]) >> + *((u16 *) &tmpaddr[4 ]) >>be16_to_cpu (readl (fep->hwp +FEC_ADDR_HIGH ) >>16 ); iap = &tmpaddr[0 ]; }This code also seems to have CPU vs big-endian byte order the wrong way round.
readl()returns bytes in native order whereas we always store MAC addresses in network (big-endian) order. So I think it should be doing:
Quoted 2 lines
*((__be32 *) &tmpaddr[0]) > cpu_to_be32(readl(fep->hwp + FEC_ADDR_LOW)); *((__be16 *) &tmpaddr[4]) > cpu_to_be16(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
Dan please resubmit with Ben's suggested changes, thanks.
Quoted 2 lines · David Miller
Dan please resubmit with Ben's suggested changes, thanks.
Yes. Of course. Sorry for that, I'll resend tomorrow.
regards,
dan carpenter
PATCH v2 1/1 net/fec: cleanup types in fec_get_mac()
In reply to Ben HutchingsMy static checker complains that on some arches unsigned longs can be 8 characters which is larger than the buffer is only 6 chars. Additionally, Ben Hutchings points out that the buffer actually holds big endian data and the buffer we are reading from is CPU endian.
---
v2: fix endian annotations and reverse the beXX_to_cpu() calls so that
they say cpu_to_beXX().
drivers/net/ethernet/freescale/fec_main.c +2 -2
@@ -1100,10 +1100,10 @@ static void fec_get_mac(struct net_device *ndev)* 4) FEC mac registers set by bootloader */ if (!is_valid_ether_addr (iap)) { - *((unsigned long *) &tmpaddr[0 ]) -be32_to_cpu (readl (fep->hwp +FEC_ADDR_LOW )); - *((unsigned short *) &tmpaddr[4 ]) -be16_to_cpu (readl (fep->hwp +FEC_ADDR_HIGH ) >>16 ); + *((__be32 *) &tmpaddr[0 ]) +cpu_to_be32 (readl (fep->hwp +FEC_ADDR_LOW )); + *((__be16 *) &tmpaddr[4 ]) +cpu_to_be16 (readl (fep->hwp +FEC_ADDR_HIGH ) >>16 ); iap = &tmpaddr[0 ]; }
Re: [patch v2] net/fec: cleanup types in fec_get_mac()
Quoted 4 lines · Dan Carpenter
My static checker complains that on some arches unsigned longs can be 8 characters which is larger than the buffer is only 6 chars. Additionally, Ben Hutchings points out that the buffer actually holds big endian data and the buffer we are reading from is CPU endian.
It's not really as clear-cut as that. :-) But I think it's slightly more logical this way.
Quoted 1 line
Signed-off-by Dan Carpenter <[email protected]>
Quoted 19 lines
---
v2: fix endian annotations and reverse thebeXX_to_cpu()calls so that
they saycpu_to_beXX().drivers/net/ethernet/freescale/fec_main.c +2
-2@@ -1100,10 +1100,10 @@ static void fec_get_mac(struct net_device *ndev)* 4) FEC mac registers set by bootloader */ if (!is_valid_ether_addr (iap)) { - *((unsigned long *) &tmpaddr[0 ]) > -be32_to_cpu (readl (fep->hwp +FEC_ADDR_LOW )); - *((unsigned short *) &tmpaddr[4 ]) > -be16_to_cpu (readl (fep->hwp +FEC_ADDR_HIGH ) >>16 ); + *((__be32 *) &tmpaddr[0 ]) > +cpu_to_be32 (readl (fep->hwp +FEC_ADDR_LOW )); + *((__be16 *) &tmpaddr[4 ]) > +cpu_to_be16 (readl (fep->hwp +FEC_ADDR_HIGH ) >>16 ); iap = &tmpaddr[0 ]; }
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
RE: [patch v2] net/fec: cleanup types in fec_get_mac()
RnJvbTogQmVuIEh1dGNoaW5ncyBbbWFpbHRvOmJodXRjaGluZ3NAc29sYXJmbGFyZS5jb21dDQpE YXRhOiBGcmlkYXksIEF1Z3VzdCAzMCwgMjAxMyAyOjQ5IEFNDQoNCj4gVG86IERhbiBDYXJwZW50 ZXINCj4gQ2M6IEdyYW50IExpa2VseTsgUm9iIEhlcnJpbmc7IERhdmlkIFMuIE1pbGxlcjsgRXN0 ZXZhbSBGYWJpby1SNDk0OTY7IExpDQo+IEZyYW5rLUIyMDU5NjsgSmltIEJheHRlcjsgRHVhbiBG dWdhbmctQjM4NjExOyBuZXRkZXZAdmdlci5rZXJuZWwub3JnOw0KPiBkZXZpY2V0cmVlQHZnZXIu a2VybmVsLm9yZzsga2VybmVsLWphbml0b3JzQHZnZXIua2VybmVsLm9yZw0KPiBTdWJqZWN0OiBS ZTogW3BhdGNoIHYyXSBuZXQvZmVjOiBjbGVhbnVwIHR5cGVzIGluIGZlY19nZXRfbWFjKCkNCj4g DQo+IE9uIFRodSwgMjAxMy0wOC0yOSBhdCAxMToyNSArMDMwMCwgRGFuIENhcnBlbnRlciB3cm90 ZToNCj4gPiBNeSBzdGF0aWMgY2hlY2tlciBjb21wbGFpbnMgdGhhdCBvbiBzb21lIGFyY2hlcyB1 bnNpZ25lZCBsb25ncyBjYW4gYmUNCj4gPiA4IGNoYXJhY3RlcnMgd2hpY2ggaXMgbGFyZ2VyIHRo YW4gdGhlIGJ1Zm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Qo+IFRo ZXkgYXNrZWQgdXMgdG8gbm90ZSB0aGF0IFNvbGFyZmxhcmUgcHJvZHVjdCBuYW1lcyBhcmUgdHJh ZGVtYXJrZWQuDQo+IA0KDQoNCg0K
Re: [patch v2] net/fec: cleanup types in fec_get_mac()
Quoted 15 lines · On Fri, Aug 30, 2013 at 02:02:00AM +0000, Duan Fugang-B38611 wrote:
From: Ben Hutchings [mailto:[email protected]]
Data: Friday, August 30, 2013 2:49 AMQuoted 12 lines
To: Dan Carpenter
Cc: Grant Likely; Rob Herring; David S. Miller; Estevam Fabio-R49496; Li Frank-B20596; Jim Baxter; Duan Fugang-B38611; [email protected]; [email protected]; [email protected]
Subject: Re: [patch v2] net/fec: cleanup types infec_get_mac()Quoted 4 lines · Dan Carpenter
My static checker complains that on some arches unsigned longs can be 8 characters which is larger than the buffer is only 6 chars. Additionally, Ben Hutchings points out that the buffer actually holds big endian data and the buffer we are reading from is CPU endian.
Quoted 4 lines
Quoted 3 lines
It's not really as clear-cut as that. :-) But I think it's slightly more logical this way.
Yes, it is not clear, pls remove somebody's name from the commit log.
Huh? No, I'm going to leave Ben's name as is. It's weird that you would ask for that.
regards,
dan carpenter
Re: [patch v2] net/fec: cleanup types in fec_get_mac()
In reply to Dan CarpenterFrom: Dan Carpenter <[email protected]>
Date: Thu, 29 Aug 2013 11:25:14 +0300
Quoted 9 lines
My static checker complains that on some arches unsigned longs can be 8 characters which is larger than the buffer is only 6 chars. Additionally, Ben Hutchings points out that the buffer actually holds big endian data and the buffer we are reading from is CPU endian.
Signed-off-by Dan Carpenter <[email protected]>---
v2: fix endian annotations and reverse thebeXX_to_cpu()calls so that
they saycpu_to_beXX().
Applied, thanks.