diff mbox series

[v2] net: moxa: MAC address reading, generating, validity checking

Message ID 20220818092317.529557-1-saproj@gmail.com (mailing list archive)
State Accepted
Commit f4693b81ea3802d2c28c868e1639e580d0da2d1f
Delegated to: Netdev Maintainers
Headers show
Series [v2] net: moxa: MAC address reading, generating, validity checking | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 4 maintainers not CCed: edumazet@google.com pabeni@redhat.com Julia.Lawall@inria.fr davem@davemloft.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sergei Antonov Aug. 18, 2022, 9:23 a.m. UTC
This device does not remember its MAC address, so add a possibility
to get it from the platform. If it fails, generate a random address.
This will provide a MAC address early during boot without user space
being involved.

Also remove extra calls to is_valid_ether_addr().

Made after suggestions by Andrew Lunn:
1) Use eth_hw_addr_random() to assign a random MAC address during probe.
2) Remove is_valid_ether_addr() from moxart_mac_open()
3) Add a call to platform_get_ethdev_address() during probe
4) Remove is_valid_ether_addr() from moxart_set_mac_address(). The core does this

v1 -> v2:
Handle EPROBE_DEFER returned from platform_get_ethdev_address().
Move MAC reading code to the beginning of the probe function.

Signed-off-by: Sergei Antonov <saproj@gmail.com>
Suggested-by: Andrew Lunn <andrew@lunn.ch>
CC: Jakub Kicinski <kuba@kernel.org>
CC: Vladimir Oltean <olteanv@gmail.com>
CC: Yang Yingliang <yangyingliang@huawei.com>
CC: Pavel Skripkin <paskripkin@gmail.com>
CC: Guobin Huang <huangguobin4@huawei.com>
CC: Yang Wei <yang.wei9@zte.com.cn>
CC: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Andrew Lunn Aug. 18, 2022, 12:20 p.m. UTC | #1
On Thu, Aug 18, 2022 at 12:23:17PM +0300, Sergei Antonov wrote:
> This device does not remember its MAC address, so add a possibility
> to get it from the platform. If it fails, generate a random address.
> This will provide a MAC address early during boot without user space
> being involved.
> 
> Also remove extra calls to is_valid_ether_addr().
> 
> Made after suggestions by Andrew Lunn:
> 1) Use eth_hw_addr_random() to assign a random MAC address during probe.
> 2) Remove is_valid_ether_addr() from moxart_mac_open()
> 3) Add a call to platform_get_ethdev_address() during probe
> 4) Remove is_valid_ether_addr() from moxart_set_mac_address(). The core does this
> 
> v1 -> v2:
> Handle EPROBE_DEFER returned from platform_get_ethdev_address().
> Move MAC reading code to the beginning of the probe function.
> 
> Signed-off-by: Sergei Antonov <saproj@gmail.com>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Vladimir Oltean Aug. 18, 2022, 2:10 p.m. UTC | #2
On Thu, Aug 18, 2022 at 12:23:17PM +0300, Sergei Antonov wrote:
> This device does not remember its MAC address, so add a possibility
> to get it from the platform. If it fails, generate a random address.
> This will provide a MAC address early during boot without user space
> being involved.
> 
> Also remove extra calls to is_valid_ether_addr().
> 
> Made after suggestions by Andrew Lunn:
> 1) Use eth_hw_addr_random() to assign a random MAC address during probe.
> 2) Remove is_valid_ether_addr() from moxart_mac_open()
> 3) Add a call to platform_get_ethdev_address() during probe
> 4) Remove is_valid_ether_addr() from moxart_set_mac_address(). The core does this
> 
> v1 -> v2:
> Handle EPROBE_DEFER returned from platform_get_ethdev_address().
> Move MAC reading code to the beginning of the probe function.
> 
> Signed-off-by: Sergei Antonov <saproj@gmail.com>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> CC: Jakub Kicinski <kuba@kernel.org>
> CC: Vladimir Oltean <olteanv@gmail.com>
> CC: Yang Yingliang <yangyingliang@huawei.com>
> CC: Pavel Skripkin <paskripkin@gmail.com>
> CC: Guobin Huang <huangguobin4@huawei.com>
> CC: Yang Wei <yang.wei9@zte.com.cn>
> CC: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/net/ethernet/moxa/moxart_ether.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
> index f11f1cb92025..402fea7505e6 100644
> --- a/drivers/net/ethernet/moxa/moxart_ether.c
> +++ b/drivers/net/ethernet/moxa/moxart_ether.c
> @@ -62,9 +62,6 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr)
>  {
>  	struct sockaddr *address = addr;
>  
> -	if (!is_valid_ether_addr(address->sa_data))
> -		return -EADDRNOTAVAIL;
> -
>  	eth_hw_addr_set(ndev, address->sa_data);
>  	moxart_update_mac_address(ndev);
>  
> @@ -172,9 +169,6 @@ static int moxart_mac_open(struct net_device *ndev)
>  {
>  	struct moxart_mac_priv_t *priv = netdev_priv(ndev);
>  
> -	if (!is_valid_ether_addr(ndev->dev_addr))
> -		return -EADDRNOTAVAIL;
> -
>  	napi_enable(&priv->napi);
>  
>  	moxart_mac_reset(ndev);
> @@ -488,6 +482,14 @@ static int moxart_mac_probe(struct platform_device *pdev)
>  	}
>  	ndev->base_addr = res->start;
>  
> +	// MAC address
> +	ret = platform_get_ethdev_address(p_dev, ndev);
> +	if (ret == -EPROBE_DEFER) // EEPROM has not probed yet?
> +		goto init_fail;

The comments are not very useful, and the kernel coding style is to use
the C-style comments /* */ rather than the C++ style //.
Anyway this is a minor remark, I don't think you have to resend for this.

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

> +	if (ret)
> +		eth_hw_addr_random(ndev);
> +	moxart_update_mac_address(ndev);
> +
>  	spin_lock_init(&priv->txlock);
>  
>  	priv->tx_buf_size = TX_BUF_SIZE;
> -- 
> 2.32.0
>
patchwork-bot+netdevbpf@kernel.org Aug. 18, 2022, 6:30 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 18 Aug 2022 12:23:17 +0300 you wrote:
> This device does not remember its MAC address, so add a possibility
> to get it from the platform. If it fails, generate a random address.
> This will provide a MAC address early during boot without user space
> being involved.
> 
> Also remove extra calls to is_valid_ether_addr().
> 
> [...]

Here is the summary with links:
  - [v2] net: moxa: MAC address reading, generating, validity checking
    https://git.kernel.org/netdev/net/c/f4693b81ea38

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
index f11f1cb92025..402fea7505e6 100644
--- a/drivers/net/ethernet/moxa/moxart_ether.c
+++ b/drivers/net/ethernet/moxa/moxart_ether.c
@@ -62,9 +62,6 @@  static int moxart_set_mac_address(struct net_device *ndev, void *addr)
 {
 	struct sockaddr *address = addr;
 
-	if (!is_valid_ether_addr(address->sa_data))
-		return -EADDRNOTAVAIL;
-
 	eth_hw_addr_set(ndev, address->sa_data);
 	moxart_update_mac_address(ndev);
 
@@ -172,9 +169,6 @@  static int moxart_mac_open(struct net_device *ndev)
 {
 	struct moxart_mac_priv_t *priv = netdev_priv(ndev);
 
-	if (!is_valid_ether_addr(ndev->dev_addr))
-		return -EADDRNOTAVAIL;
-
 	napi_enable(&priv->napi);
 
 	moxart_mac_reset(ndev);
@@ -488,6 +482,14 @@  static int moxart_mac_probe(struct platform_device *pdev)
 	}
 	ndev->base_addr = res->start;
 
+	// MAC address
+	ret = platform_get_ethdev_address(p_dev, ndev);
+	if (ret == -EPROBE_DEFER) // EEPROM has not probed yet?
+		goto init_fail;
+	if (ret)
+		eth_hw_addr_random(ndev);
+	moxart_update_mac_address(ndev);
+
 	spin_lock_init(&priv->txlock);
 
 	priv->tx_buf_size = TX_BUF_SIZE;