Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+5 -37
+5 -37
drivers/net/ethernet/toshiba/spider_net.c
··· 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 270 * spider_net_get_descr_status -- returns the status of a descriptor 299 271 * @descr: descriptor to look at 300 272 * ··· 1317 1345 if (!is_valid_ether_addr(addr->sa_data)) 1318 1346 return -EADDRNOTAVAIL; 1319 1347 1348 + memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN); 1349 + 1320 1350 /* switch off GMACTPE and GMACRPE */ 1321 1351 regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); 1322 1352 regvalue &= ~((1 << 5) | (1 << 6)); 1323 1353 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); 1324 1354 1325 1355 /* write mac */ 1326 - macu = (addr->sa_data[0]<<24) + (addr->sa_data[1]<<16) + 1327 - (addr->sa_data[2]<<8) + (addr->sa_data[3]); 1328 - macl = (addr->sa_data[4]<<8) + (addr->sa_data[5]); 1356 + macu = (netdev->dev_addr[0]<<24) + (netdev->dev_addr[1]<<16) + 1357 + (netdev->dev_addr[2]<<8) + (netdev->dev_addr[3]); 1358 + macl = (netdev->dev_addr[4]<<8) + (netdev->dev_addr[5]); 1329 1359 spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu); 1330 1360 spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl); 1331 1361 ··· 1337 1363 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); 1338 1364 1339 1365 spider_net_set_promisc(card); 1340 - 1341 - /* look up, whether we have been successful */ 1342 - if (spider_net_get_mac_address(netdev)) 1343 - return -EADDRNOTAVAIL; 1344 - if (memcmp(netdev->dev_addr,addr->sa_data,netdev->addr_len)) 1345 - return -EADDRNOTAVAIL; 1346 1366 1347 1367 return 0; 1348 1368 }