diff options
author | David S. Miller <davem@davemloft.net> | 2014-10-05 21:15:23 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-10-05 21:15:23 -0400 |
commit | f408c3d956c987844dcb7c6837abfbb0331fb7f6 (patch) | |
tree | 64d8c2369c8e0587796d0148afe1a9b0e91efa42 | |
parent | 3a67c9ccad926a168d8b7891537a452018368a5b (diff) | |
parent | 96aacededcc601f5af894ead6b481e76cc8db2cd (diff) |
Merge branch 'spider_net'
Antoine Tenart says:
====================
net: spider_net: fix possible bitops errors
Dan reported a possible signedness issue on the pxa168_eth driver. While
having a look at it, I came across a similar problem in the spider_net
driver.
Here is one proposal to fix it. The first patch rework the
spider_net_set_mac() function by removing the spider_net_get_mac_address()
call and using memcpy() to set netdev->dev_addr (which is what's done in
lots of Ethernet drivers) and the second one fix the actual signedness
issue.
If for any reason you really want to keep a call to
spider_net_get_mac_address() because the memcpy() is somehow not good
enough here, we can also come up with a solution involving a temporary
unsigned char variable.
I couldn't test these changes, so please do.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ethernet/toshiba/spider_net.c | 42 |
1 files changed, 5 insertions, 37 deletions
diff --git a/drivers/net/ethernet/toshiba/spider_net.c b/drivers/net/ethernet/toshiba/spider_net.c index 3e38f67c6011..8e9371a3388a 100644 --- a/drivers/net/ethernet/toshiba/spider_net.c +++ b/drivers/net/ethernet/toshiba/spider_net.c | |||
@@ -267,34 +267,6 @@ spider_net_set_promisc(struct spider_net_card *card) | |||
267 | } | 267 | } |
268 | 268 | ||
269 | /** | 269 | /** |
270 | * spider_net_get_mac_address - read mac address from spider card | ||
271 | * @card: device structure | ||
272 | * | ||
273 | * reads MAC address from GMACUNIMACU and GMACUNIMACL registers | ||
274 | */ | ||
275 | static int | ||
276 | spider_net_get_mac_address(struct net_device *netdev) | ||
277 | { | ||
278 | struct spider_net_card *card = netdev_priv(netdev); | ||
279 | u32 macl, macu; | ||
280 | |||
281 | macl = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACL); | ||
282 | macu = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACU); | ||
283 | |||
284 | netdev->dev_addr[0] = (macu >> 24) & 0xff; | ||
285 | netdev->dev_addr[1] = (macu >> 16) & 0xff; | ||
286 | netdev->dev_addr[2] = (macu >> 8) & 0xff; | ||
287 | netdev->dev_addr[3] = macu & 0xff; | ||
288 | netdev->dev_addr[4] = (macl >> 8) & 0xff; | ||
289 | netdev->dev_addr[5] = macl & 0xff; | ||
290 | |||
291 | if (!is_valid_ether_addr(&netdev->dev_addr[0])) | ||
292 | return -EINVAL; | ||
293 | |||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * spider_net_get_descr_status -- returns the status of a descriptor | 270 | * spider_net_get_descr_status -- returns the status of a descriptor |
299 | * @descr: descriptor to look at | 271 | * @descr: descriptor to look at |
300 | * | 272 | * |
@@ -1345,15 +1317,17 @@ spider_net_set_mac(struct net_device *netdev, void *p) | |||
1345 | if (!is_valid_ether_addr(addr->sa_data)) | 1317 | if (!is_valid_ether_addr(addr->sa_data)) |
1346 | return -EADDRNOTAVAIL; | 1318 | return -EADDRNOTAVAIL; |
1347 | 1319 | ||
1320 | memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN); | ||
1321 | |||
1348 | /* switch off GMACTPE and GMACRPE */ | 1322 | /* switch off GMACTPE and GMACRPE */ |
1349 | regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); | 1323 | regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); |
1350 | regvalue &= ~((1 << 5) | (1 << 6)); | 1324 | regvalue &= ~((1 << 5) | (1 << 6)); |
1351 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); | 1325 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); |
1352 | 1326 | ||
1353 | /* write mac */ | 1327 | /* write mac */ |
1354 | macu = (addr->sa_data[0]<<24) + (addr->sa_data[1]<<16) + | 1328 | macu = (netdev->dev_addr[0]<<24) + (netdev->dev_addr[1]<<16) + |
1355 | (addr->sa_data[2]<<8) + (addr->sa_data[3]); | 1329 | (netdev->dev_addr[2]<<8) + (netdev->dev_addr[3]); |
1356 | macl = (addr->sa_data[4]<<8) + (addr->sa_data[5]); | 1330 | macl = (netdev->dev_addr[4]<<8) + (netdev->dev_addr[5]); |
1357 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu); | 1331 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu); |
1358 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl); | 1332 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl); |
1359 | 1333 | ||
@@ -1364,12 +1338,6 @@ spider_net_set_mac(struct net_device *netdev, void *p) | |||
1364 | 1338 | ||
1365 | spider_net_set_promisc(card); | 1339 | spider_net_set_promisc(card); |
1366 | 1340 | ||
1367 | /* look up, whether we have been successful */ | ||
1368 | if (spider_net_get_mac_address(netdev)) | ||
1369 | return -EADDRNOTAVAIL; | ||
1370 | if (memcmp(netdev->dev_addr,addr->sa_data,netdev->addr_len)) | ||
1371 | return -EADDRNOTAVAIL; | ||
1372 | |||
1373 | return 0; | 1341 | return 0; |
1374 | } | 1342 | } |
1375 | 1343 | ||