lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Fri, 3 May 2019 14:05:09 +0200
From:   Andrew Lunn <andrew@...n.ch>
To:     Petr Štetiar <ynezz@...e.cz>
Cc:     Sergei Shtylyov <sergei.shtylyov@...entembedded.com>,
        netdev@...r.kernel.org, devicetree@...r.kernel.org,
        Florian Fainelli <f.fainelli@...il.com>,
        Rob Herring <robh+dt@...nel.org>,
        Frank Rowand <frowand.list@...il.com>,
        Heiner Kallweit <hkallweit1@...il.com>,
        Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
        Maxime Ripard <maxime.ripard@...tlin.com>,
        Alban Bedel <albeu@...e.fr>, Felix Fietkau <nbd@....name>,
        John Crispin <john@...ozen.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 01/10] of_net: add NVMEM support to of_get_mac_address

On Fri, May 03, 2019 at 11:15:42AM +0200, Petr Štetiar wrote:
> Sergei Shtylyov <sergei.shtylyov@...entembedded.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

Powered by blists - more mailing lists