linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Rob Herring <robh@kernel.org>,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	David Lechner <david@lechnology.com>,
	Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>,
	Kevin Hilman <khilman@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sekhar Nori <nsekhar@ti.com>,
	Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Lukas Wunner <lukas@wunner.de>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	Florian Fainelli <f.fainelli@gmail.com>,
	linux-omap@vger.kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH 4/5] net: add support for nvmem to eth_platform_get_mac_address()
Date: Thu, 19 Jul 2018 17:22:22 +0200	[thread overview]
Message-ID: <20180719152222.GD9119@lunn.ch> (raw)
In-Reply-To: <20180718161035.7005-5-brgl@bgdev.pl>

On Wed, Jul 18, 2018 at 06:10:34PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> Many non-DT platforms read the MAC address from EEPROM. Usually it's
> either done with callbacks defined in board files or from SoC-specific
> ethernet drivers.
> 
> In order to generalize this, try to read the MAC from nvmem in
> eth_platform_get_mac_address() using a standard lookup name:
> "mac-address".
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  net/ethernet/eth.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
> index 6b64586fd2af..adf5bd03851f 100644
> --- a/net/ethernet/eth.c
> +++ b/net/ethernet/eth.c
> @@ -54,6 +54,7 @@
>  #include <linux/if_ether.h>
>  #include <linux/of_net.h>
>  #include <linux/pci.h>
> +#include <linux/nvmem-consumer.h>
>  #include <net/dst.h>
>  #include <net/arp.h>
>  #include <net/sock.h>
> @@ -530,7 +531,10 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
>  	struct device_node *dp = dev_is_pci(dev) ?
>  			pci_device_to_OF_node(to_pci_dev(dev)) : dev->of_node;
>  	const unsigned char *addr = NULL;
> +	unsigned char addrbuf[ETH_ALEN];
> +	struct nvmem_cell *nvmem;
>  	const char *from = NULL;
> +	size_t alen;
>  
>  	if (dp) {
>  		addr = of_get_mac_address(dp);
> @@ -544,6 +548,31 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
>  			from = "arch callback";
>  	}
>  
> +	if (!addr) {
> +		nvmem = nvmem_cell_get(dev, "mac-address");
> +		if (IS_ERR(nvmem) && PTR_ERR(nvmem) == -EPROBE_DEFER)

How does EPROBE_DEFER work here? You say the use case is
Non-DT. Without having DT, how do you know the cell should exist, but
does not yet exist? I might be looking at old code, but i only see
-EPROBE_DEFER inside the if (np) case.

> +			/* We may have a lookup registered for MAC address but
> +			 * the corresponding nvmem provider hasn't been
> +			 * registered yet.
> +			 */
> +			return -EPROBE_DEFER;

You really should return real errors. If i'm reading
__nvmem_device_get() right, it will return a NULL pointer when the
cell does not exist. NULL is not an error, so IS_ERR() will return
false. So you should return all errors from nvmem_cell_get().

       Andrew

  parent reply	other threads:[~2018-07-19 15:22 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-18 16:10 [PATCH 0/5] net: extend eth_platform_get_mac_address() Bartosz Golaszewski
2018-07-18 16:10 ` [PATCH 1/5] net: visually shrink eth_platform_get_mac_address() Bartosz Golaszewski
2018-07-18 16:28   ` Andrew Lunn
2018-07-18 16:31     ` Bartosz Golaszewski
2018-07-18 23:10   ` David Miller
2018-07-18 16:10 ` [PATCH 2/5] net: add an info message to eth_platform_get_mac_address() Bartosz Golaszewski
2018-07-18 16:31   ` Andrew Lunn
2018-07-18 16:33     ` Bartosz Golaszewski
2018-07-18 23:13   ` David Miller
2018-07-18 16:10 ` [PATCH 3/5] net: fortify eth_platform_get_mac_address() Bartosz Golaszewski
2018-07-18 16:35   ` Andrew Lunn
2018-07-18 16:10 ` [PATCH 4/5] net: add support for nvmem to eth_platform_get_mac_address() Bartosz Golaszewski
2018-07-18 16:42   ` Andrew Lunn
2018-07-19 15:22   ` Andrew Lunn [this message]
2018-07-19 15:25     ` Bartosz Golaszewski
2018-07-19 17:47   ` Russell King - ARM Linux
2018-07-19 21:24     ` Bartosz Golaszewski
2018-07-19 21:48       ` Andrew Lunn
2018-07-18 16:10 ` [PATCH 5/5] net: add MTD support " Bartosz Golaszewski
2018-07-18 16:47   ` Andrew Lunn
2018-07-18 16:54     ` Bartosz Golaszewski
2018-07-18 17:03       ` Andrew Lunn
2018-07-19  8:14         ` Bartosz Golaszewski
2018-07-19 15:01           ` Andrew Lunn
2018-07-19 15:07             ` Bartosz Golaszewski
2018-07-19 15:27               ` Andrew Lunn
2018-07-19 15:35                 ` Bartosz Golaszewski
2018-07-20  5:17                   ` Sekhar Nori
2018-07-20 14:15                     ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180719152222.GD9119@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=david@lechnology.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=grygorii.strashko@ti.com \
    --cc=ivan.khoronzhuk@linaro.org \
    --cc=khilman@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lukas@wunner.de \
    --cc=netdev@vger.kernel.org \
    --cc=nsekhar@ti.com \
    --cc=robh@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).