net: mvneta: Use prepare/commit API to simplify MAC address setting
Use eth_prepare_mac_addr_change and eth_commit_mac_addr_change, instead of manually checking and storing the MAC address, which makes the code slightly more robust. This fixes the lack of valid MAC address check in the driver's .ndo_set_mac_address hook. Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
9672850be3
commit
e68de36072
|
@ -2473,22 +2473,19 @@ static void mvneta_get_mac_addr(struct mvneta_port *pp, unsigned char *addr)
|
||||||
static int mvneta_set_mac_addr(struct net_device *dev, void *addr)
|
static int mvneta_set_mac_addr(struct net_device *dev, void *addr)
|
||||||
{
|
{
|
||||||
struct mvneta_port *pp = netdev_priv(dev);
|
struct mvneta_port *pp = netdev_priv(dev);
|
||||||
u8 *mac = addr + 2;
|
struct sockaddr *sockaddr = addr;
|
||||||
int i;
|
int ret;
|
||||||
|
|
||||||
if (netif_running(dev))
|
|
||||||
return -EBUSY;
|
|
||||||
|
|
||||||
|
ret = eth_prepare_mac_addr_change(dev, addr);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
/* Remove previous address table entry */
|
/* Remove previous address table entry */
|
||||||
mvneta_mac_addr_set(pp, dev->dev_addr, -1);
|
mvneta_mac_addr_set(pp, dev->dev_addr, -1);
|
||||||
|
|
||||||
/* Set new addr in hw */
|
/* Set new addr in hw */
|
||||||
mvneta_mac_addr_set(pp, mac, rxq_def);
|
mvneta_mac_addr_set(pp, sockaddr->sa_data, rxq_def);
|
||||||
|
|
||||||
/* Set addr in the device */
|
|
||||||
for (i = 0; i < ETH_ALEN; i++)
|
|
||||||
dev->dev_addr[i] = mac[i];
|
|
||||||
|
|
||||||
|
eth_commit_mac_addr_change(dev, addr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2583,8 +2580,6 @@ static int mvneta_open(struct net_device *dev)
|
||||||
struct mvneta_port *pp = netdev_priv(dev);
|
struct mvneta_port *pp = netdev_priv(dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mvneta_mac_addr_set(pp, dev->dev_addr, rxq_def);
|
|
||||||
|
|
||||||
pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu);
|
pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu);
|
||||||
pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) +
|
pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) +
|
||||||
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
|
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
|
||||||
|
|
Loading…
Reference in New Issue