Message ID | 1559326545-28825-10-git-send-email-hancock@sedsystems.ca |
---|---|
State | Superseded |
Delegated to: | David Miller |
Headers | show |
Series | Xilinx axienet driver updates | expand |
On Fri, May 31, 2019 at 12:15:41PM -0600, Robert Hancock wrote: > Failing initialization on a missing MAC address property is excessive. > We can just fall back to using a random MAC instead, which at least > leaves the interface in a functioning state. > > Signed-off-by: Robert Hancock <hancock@sedsystems.ca> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
From: Robert Hancock > Sent: 31 May 2019 19:16 > Failing initialization on a missing MAC address property is excessive. > We can just fall back to using a random MAC instead, which at least > leaves the interface in a functioning state. > > Signed-off-by: Robert Hancock <hancock@sedsystems.ca> > --- > drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > index 9949e67..947fa5d 100644 > --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > @@ -308,7 +308,7 @@ static void axienet_set_mac_address(struct net_device *ndev, > { > struct axienet_local *lp = netdev_priv(ndev); > > - if (address) > + if (!IS_ERR(address)) > memcpy(ndev->dev_addr, address, ETH_ALEN); > if (!is_valid_ether_addr(ndev->dev_addr)) > eth_hw_addr_random(ndev); > @@ -1730,8 +1730,7 @@ static int axienet_probe(struct platform_device *pdev) > /* Retrieve the MAC address */ > mac_addr = of_get_mac_address(pdev->dev.of_node); > if (IS_ERR(mac_addr)) { > - dev_err(&pdev->dev, "could not find MAC address\n"); > - goto free_netdev; > + dev_warn(&pdev->dev, "could not find MAC address property\n"); > } > axienet_set_mac_address(ndev, mac_addr); Isn't that going to read from an invalid address on error? Seems you didn't test of_get_mac_address() failing :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On 2019-06-03 7:22 a.m., David Laight wrote: > From: Robert Hancock >> Sent: 31 May 2019 19:16 >> Failing initialization on a missing MAC address property is excessive. >> We can just fall back to using a random MAC instead, which at least >> leaves the interface in a functioning state. >> >> Signed-off-by: Robert Hancock <hancock@sedsystems.ca> >> --- >> drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 ++--- >> 1 file changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c >> b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c >> index 9949e67..947fa5d 100644 >> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c >> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c >> @@ -308,7 +308,7 @@ static void axienet_set_mac_address(struct net_device *ndev, >> { >> struct axienet_local *lp = netdev_priv(ndev); >> >> - if (address) >> + if (!IS_ERR(address)) >> memcpy(ndev->dev_addr, address, ETH_ALEN); >> if (!is_valid_ether_addr(ndev->dev_addr)) >> eth_hw_addr_random(ndev); >> @@ -1730,8 +1730,7 @@ static int axienet_probe(struct platform_device *pdev) >> /* Retrieve the MAC address */ >> mac_addr = of_get_mac_address(pdev->dev.of_node); >> if (IS_ERR(mac_addr)) { >> - dev_err(&pdev->dev, "could not find MAC address\n"); >> - goto free_netdev; >> + dev_warn(&pdev->dev, "could not find MAC address property\n"); >> } >> axienet_set_mac_address(ndev, mac_addr); > > Isn't that going to read from an invalid address on error? > Seems you didn't test of_get_mac_address() failing :-) axienet_set_mac_address checks IS_ERR(mac_addr) as well before reading from it, so the invalid address should not be accessed.
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 9949e67..947fa5d 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -308,7 +308,7 @@ static void axienet_set_mac_address(struct net_device *ndev, { struct axienet_local *lp = netdev_priv(ndev); - if (address) + if (!IS_ERR(address)) memcpy(ndev->dev_addr, address, ETH_ALEN); if (!is_valid_ether_addr(ndev->dev_addr)) eth_hw_addr_random(ndev); @@ -1730,8 +1730,7 @@ static int axienet_probe(struct platform_device *pdev) /* Retrieve the MAC address */ mac_addr = of_get_mac_address(pdev->dev.of_node); if (IS_ERR(mac_addr)) { - dev_err(&pdev->dev, "could not find MAC address\n"); - goto free_netdev; + dev_warn(&pdev->dev, "could not find MAC address property\n"); } axienet_set_mac_address(ndev, mac_addr);
Failing initialization on a missing MAC address property is excessive. We can just fall back to using a random MAC instead, which at least leaves the interface in a functioning state. Signed-off-by: Robert Hancock <hancock@sedsystems.ca> --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)