Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1822093imm; Thu, 19 Jul 2018 08:23:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcx9CSgiZkrah5/f8r994zJHhI2c0hE8KiF9oiy52wfIuzpvdwSzO7FJz8giZ5cLn7yg80l X-Received: by 2002:a17:902:8bc6:: with SMTP id r6-v6mr10362811plo.257.1532013822766; Thu, 19 Jul 2018 08:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532013822; cv=none; d=google.com; s=arc-20160816; b=Kvlc3NUbul2g53r9oBB67130DF40IevQed95RqCL4l0Nr1cjrEQ8TjXJQomiq7JJh5 x2o+g4Z8CAtRI39i1w/hTlqSJFo23TPcytQWNLx+qYPDjVAZ0po04SAMqlFGFQIDXENT TUXZOiuMZUyVYZN/rMz4KKf5nh0bO+COeVeCDjbhpa3fOBHFlua5v2LnlgITuNee4att zGEcveAz1VQoHi9P6JxOFaZgP28C8Xuu+GqOQ3EeMZN9pgBufN8q9cxhW9oGp03BNics toWRt7ggGIacwaspaXLLrS+JYo/9qQAL/IZnCWKErx9YBaPYDXr6Q7WNi/+adUJranrI XI3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=YCaJxcZSU5hdv4YnUh3DQ1JUXLcIOJU8T1V161rc0R4=; b=MJ26rEDQ1Nskx9FXpHTmUW+ZwW6qaVsytGrv9B1tXjifjQUbbXz8cGoPgiWiSF/5Iv tBaYp/EL68UGAxKSLaj5FcwrGFNy8CgFqigpbZu36y0k7q6HHTeZNHASVfYMaF1pAWa4 NS5xkGaLDNU6pFo2mhMk1YBecb24uwGL3PxaYxZiKdUWI8FSf6N+ByhH53QauXc1vbFt EE4LyxC41Slvodkjmtb70spjoMqCQre4zCr4FANxy2OCEBfJsj2APuHdWeIqEAttBInU LDbpCCWneh5jzLhd7BWlGsPDhU1iaxSCsrBK88+MvvyRfoccf8h6ISzHvP5ohyRvMSj4 prpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=TPuhdqAy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s126-v6si6550129pfc.222.2018.07.19.08.23.27; Thu, 19 Jul 2018 08:23:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=TPuhdqAy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731969AbeGSQGa (ORCPT + 99 others); Thu, 19 Jul 2018 12:06:30 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:40198 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731369AbeGSQG3 (ORCPT ); Thu, 19 Jul 2018 12:06:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=YCaJxcZSU5hdv4YnUh3DQ1JUXLcIOJU8T1V161rc0R4=; b=TPuhdqAyZmdEaoDgJaJ1bFuL9nv1n7RPn8AQh0xnn1EIrV8PcoNos0NlRcB3wb/1A9WMAmJxnXq8cZMSiqgzQ9MNObRTARJWnHpq0GL5Qht21KGgojj1ygPo4sl7jUVycckSpDUwMlKr6QdncbXgV5hCZy6xpIVkpTksY1EilNQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1fgAl4-0002ln-J8; Thu, 19 Jul 2018 17:22:22 +0200 Date: Thu, 19 Jul 2018 17:22:22 +0200 From: Andrew Lunn To: Bartosz Golaszewski Cc: Sekhar Nori , Kevin Hilman , Russell King , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Lukas Wunner , Rob Herring , Florian Fainelli , Dan Carpenter , Ivan Khoronzhuk , David Lechner , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH 4/5] net: add support for nvmem to eth_platform_get_mac_address() Message-ID: <20180719152222.GD9119@lunn.ch> References: <20180718161035.7005-1-brgl@bgdev.pl> <20180718161035.7005-5-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180718161035.7005-5-brgl@bgdev.pl> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 06:10:34PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > 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 > --- > 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 > #include > #include > +#include > #include > #include > #include > @@ -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