From: Andrew Lunn <andrew@lunn.ch>
To: "Petr Štetiar" <ynezz@true.cz>
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>,
netdev@vger.kernel.org, devicetree@vger.kernel.org,
Florian Fainelli <f.fainelli@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Maxime Ripard <maxime.ripard@bootlin.com>,
Alban Bedel <albeu@free.fr>, Felix Fietkau <nbd@nbd.name>,
John Crispin <john@phrozen.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 01/10] of_net: add NVMEM support to of_get_mac_address
Date: Fri, 3 May 2019 14:05:09 +0200 [thread overview]
Message-ID: <20190503120509.GA1941@lunn.ch> (raw)
In-Reply-To: <20190503091542.GE346@meh.true.cz>
On Fri, May 03, 2019 at 11:15:42AM +0200, Petr Štetiar wrote:
> Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> [2019-05-03 11:44:54]:
>
> Hi Sergei,
>
> > > diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> > > index d820f3e..258ceb8 100644
> > > --- a/drivers/of/of_net.c
> > > +++ b/drivers/of/of_net.c
> > [...]
> > > @@ -64,6 +113,9 @@ static const void *of_get_mac_addr(struct device_node *np, const char *name)
> > > * addresses. Some older U-Boots only initialized 'local-mac-address'. In
> > > * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
> > > * but is all zeros.
> > > + *
> > > + * Return: Will be a valid pointer on success, NULL in case there wasn't
> > > + * 'mac-address' nvmem cell node found, and ERR_PTR in case of error.
> >
> > Returning both NULL and error codes on failure is usually a sign of a
> > misdesigned API.
>
> well, then there's a lot of misdesigned APIs in the tree already, as I've just
> grepped for IS_ERR_OR_NULL usage and found this pointer/NULL/ERR_PTR usage
> pretty legit.
>
> > Why not always return an error code?
>
> I've received following comment[1] from Andrew:
>
> "What you have to be careful of, is the return value from your new code
> looking in NVMEM. It should only return EPROBE_DEFER, or another error
> if there really is expected to be a value in NVMEM, or getting it from
> NVMEM resulted in an error."
>
> So in order to fullfil this remark, I can't simply use ENOENT instead of
> current NULL, as the caller couldn't distinguish between ENOENT from
> of_get_mac_address or ENOENT from NVMEM subsystem.
ENOENT and its like have to be handled special by of_get_mac_address()
for all the different ways you can find the MAC address. It means that
method does not have a MAC address, try the next. And if at the end
you have not found a MAC address, ENOENT is a good return code, it
indicates none of the methods found a MAC address.
If you are using of_get_mac_address() you don't really care where the
MAC address came from, except you expect the documented search order.
So you don't need to know that NVMEM returned ENOENT. If you do care
about that, you would not use of_get_mac_address(), but directly go to
the NVMEM.
Andrew
next prev parent reply other threads:[~2019-05-03 12:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-03 7:55 [PATCH v3 00/10] of_net: Add NVMEM support to of_get_mac_address Petr Štetiar
2019-05-03 7:55 ` [PATCH v3 01/10] of_net: add " Petr Štetiar
2019-05-03 8:44 ` Sergei Shtylyov
2019-05-03 9:15 ` Petr Štetiar
2019-05-03 9:36 ` Maxime Ripard
2019-05-03 12:05 ` Andrew Lunn [this message]
[not found] ` <1556870168-26864-1-git-send-email-ynezz-knWk7/PSn+s@public.gmane.org>
2019-05-03 7:55 ` [PATCH v3 02/10] dt-bindings: doc: reflect new NVMEM of_get_mac_address behaviour Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 03/10] net: macb: support of_get_mac_address new ERR_PTR error Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 04/10] net: davinci: " Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 05/10] net: ethernet: " Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 06/10] net: usb: " Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 07/10] net: wireless: " Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 08/10] staging: octeon-ethernet: " Petr Štetiar
2019-05-03 10:34 ` Dan Carpenter
2019-05-03 19:07 ` Petr Štetiar
2019-05-03 19:40 ` Dan Carpenter
2019-05-03 7:56 ` [PATCH v3 09/10] ARM: Kirkwood: " Petr Štetiar
2019-05-03 7:56 ` [PATCH v3 10/10] powerpc: tsi108: " Petr Štetiar
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=20190503120509.GA1941@lunn.ch \
--to=andrew@lunn.ch \
--cc=albeu@free.fr \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=frowand.list@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=john@phrozen.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.ripard@bootlin.com \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sergei.shtylyov@cogentembedded.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=ynezz@true.cz \
/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).