Skip to content

Commit

Permalink
wilc1000: Bring MAC address setting in line with typical Linux behavior
Browse files Browse the repository at this point in the history
Linux network drivers normally disallow changing the MAC address when
the interface is up.  This driver has been different in that it allows
to change the MAC address *only* when it's up.  This patch brings
wilc1000 behavior more in line with other network drivers.  We could
have replaced wilc_set_mac_addr() with eth_mac_addr() but that would
break existing documentation on how to change the MAC address.
Likewise, return -EADDRNOTAVAIL (not -EINVAL) when the specified MAC
address is invalid or unavailable.

Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210303194846.1823596-1-davidm@egauge.net
  • Loading branch information
David Mosberger-Tang authored and Kalle Valo committed Apr 17, 2021
1 parent c872e7a commit a381b78
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions drivers/net/wireless/microchip/wilc1000/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ static int wilc_mac_open(struct net_device *ndev)
{
struct wilc_vif *vif = netdev_priv(ndev);
struct wilc *wl = vif->wilc;
unsigned char mac_add[ETH_ALEN] = {0};
int ret = 0;
struct mgmt_frame_regs mgmt_regs = {};

Expand All @@ -594,9 +593,12 @@ static int wilc_mac_open(struct net_device *ndev)

wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype,
vif->idx);
wilc_get_mac_address(vif, mac_add);
netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
ether_addr_copy(ndev->dev_addr, mac_add);

if (is_valid_ether_addr(ndev->dev_addr))
wilc_set_mac_address(vif, ndev->dev_addr);
else
wilc_get_mac_address(vif, ndev->dev_addr);
netdev_dbg(ndev, "Mac address: %pM\n", ndev->dev_addr);

if (!is_valid_ether_addr(ndev->dev_addr)) {
netdev_err(ndev, "Wrong MAC address\n");
Expand Down Expand Up @@ -635,15 +637,22 @@ static int wilc_set_mac_addr(struct net_device *dev, void *p)
int srcu_idx;

if (!is_valid_ether_addr(addr->sa_data))
return -EINVAL;
return -EADDRNOTAVAIL;

if (!vif->mac_opened) {
eth_commit_mac_addr_change(dev, p);
return 0;
}

/* Verify MAC Address is not already in use: */

srcu_idx = srcu_read_lock(&wilc->srcu);
list_for_each_entry_rcu(tmp_vif, &wilc->vif_list, list) {
wilc_get_mac_address(tmp_vif, mac_addr);
if (ether_addr_equal(addr->sa_data, mac_addr)) {
if (vif != tmp_vif) {
srcu_read_unlock(&wilc->srcu, srcu_idx);
return -EINVAL;
return -EADDRNOTAVAIL;
}
srcu_read_unlock(&wilc->srcu, srcu_idx);
return 0;
Expand All @@ -655,9 +664,7 @@ static int wilc_set_mac_addr(struct net_device *dev, void *p)
if (result)
return result;

ether_addr_copy(vif->bssid, addr->sa_data);
ether_addr_copy(vif->ndev->dev_addr, addr->sa_data);

eth_commit_mac_addr_change(dev, p);
return result;
}

Expand Down

0 comments on commit a381b78

Please sign in to comment.