Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3009839pxj; Mon, 17 May 2021 15:29:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeJHhLGhWmsf0yTLclpSTWAhWNRzU3vrEORKGl7Jn4ftgh8M5JppRUVbLfKb0IjTxRQD+L X-Received: by 2002:a17:906:a51:: with SMTP id x17mr2292229ejf.25.1621290563559; Mon, 17 May 2021 15:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621290563; cv=none; d=google.com; s=arc-20160816; b=Pf8n7zFj1RbCx1Fr9qCgSWstyf47J9/StgkWzRvW06QAHeaPbAmarXdJlHP8xiVEkm TO+0p17FUwqR1yV5cdScjU9rZh6y4wTwqPqyyvbWljAqr+wk2Cjzso3obl4pBoZr7LOf ngey1Cx5Kc8IED6PgCtVOdKOOUgnmC5tgvk3qcZvQm2fxh9niZNKDz527fJmRgmYL2PO 85RzXrNyeWroxqijC61uEimRmUCtbRxBvhnwf3U8JUb1+8ZWjZiIjsEycWlxZvk1k0Y5 UMSUpHeS6AbY2FvZgSLkvcwlRMp5jTSnjDxM9UUYh/LWOOlTJb8t0yUZ9W7dNpBrQCgf ZftQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fm1+rNQVGBTPNoggmjmHjXqAqQFHlDN+oF02osEPxYY=; b=cn04JSlgcq1SpHwFLZASItqlIu8WEF53+fKz58ribiPgsPyPwt39R2WcvGXdZeHlXn ucJhtqL0OSDz+FpSW/hA6dW+xE9jMlHXlu6ZZVyX37g99p7ftMehztOgS4I1RXcE5wpK boLNqlRg0VYoCovVXHQxXEC9kNZzHTE8t/rARQuKbW9aMQbMlcGhqSXKmynrqLtf5jvx ebsxoJG/bAn4sKCPLRF+mVjzCoWgF0Yy8O2HuLuLWZ1nLA//Mb8t8lYqxECtWo24yLVK ilkCJsokxW5bJTidRBM+R1Mm2BaC19GxCsfk6bb0fN/S33LqNYoWdDEJZRPeQ6XNyakK lZ1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ubs1fhiD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si13238578edb.587.2021.05.17.15.28.59; Mon, 17 May 2021 15:29:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ubs1fhiD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238685AbhEQONs (ORCPT + 99 others); Mon, 17 May 2021 10:13:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:43504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238272AbhEQOLq (ORCPT ); Mon, 17 May 2021 10:11:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5298A613D9; Mon, 17 May 2021 14:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260471; bh=3cGMjJNrm/8gkL5HPAi2bxb+Bqm/8WeEaYkUYtNekV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ubs1fhiDWcuPDyG6BQd0zCWkJL27Pa0QtZVbFhii7QSO4vGzGvt7OwBHWj4k6Ys9J KfC7R2+GvO0rRi1Rft6r2FrJTUXGSe68zggxj88K5EXjvd+DKTxtqdOIRT6s0zUQWe lKCr9mWkkRFOnnUd6Am3Pv6ZtAQVlzNopTWcMZO4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Mosberger-Tang , Kalle Valo , Sasha Levin Subject: [PATCH 5.12 095/363] wilc1000: Bring MAC address setting in line with typical Linux behavior Date: Mon, 17 May 2021 15:59:21 +0200 Message-Id: <20210517140305.813692170@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Mosberger-Tang [ Upstream commit a381b78a1598dde34a6e40dae2842024308a6ef2 ] 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 Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20210303194846.1823596-1-davidm@egauge.net Signed-off-by: Sasha Levin --- .../net/wireless/microchip/wilc1000/netdev.c | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/microchip/wilc1000/netdev.c b/drivers/net/wireless/microchip/wilc1000/netdev.c index 1b205e7d97a8..37f40039e4ca 100644 --- a/drivers/net/wireless/microchip/wilc1000/netdev.c +++ b/drivers/net/wireless/microchip/wilc1000/netdev.c @@ -575,7 +575,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 = {}; @@ -598,9 +597,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"); @@ -639,7 +641,14 @@ 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) { @@ -647,7 +656,7 @@ static int wilc_set_mac_addr(struct net_device *dev, void *p) 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; @@ -659,9 +668,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; } -- 2.30.2