[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <867b81680fdf3076e8ce3fbc2dc36247d8e724a8.camel@svanheule.net>
Date: Mon, 24 May 2021 17:30:30 +0200
From: Sander Vanheule <sander@...nheule.net>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: Pavel Machek <pavel@....cz>, Rob Herring <robh+dt@...nel.org>,
Lee Jones <lee.jones@...aro.org>,
Mark Brown <broonie@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Michael Walle <michael@...le.cc>,
Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski <bgolaszewski@...libre.com>,
Linux LED Subsystem <linux-leds@...r.kernel.org>,
devicetree <devicetree@...r.kernel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
Andrew Lunn <andrew@...n.ch>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 6/6] leds: Add support for RTL8231 LED scan matrix
On Mon, 2021-05-24 at 15:47 +0300, Andy Shevchenko wrote:
> On Mon, May 24, 2021 at 3:04 PM Sander Vanheule <sander@...nheule.net> wrote:
> > On Mon, 2021-05-24 at 13:24 +0300, Andy Shevchenko wrote:
> > > On Mon, May 24, 2021 at 1:34 AM Sander Vanheule <sander@...nheule.net>
> > > wrote:
>
> ...
>
> > > > + if (ret != 2)
> > > > + return -ENODEV;
> > >
> > > I would say -EINVAL, but -ENODEV is similarly okay.
> >
> > Any specific reason you think EINVAL is more appropriate than ENODEV?
>
> My logic is that the initial values (from resource provider) are incorrect.
> But as I said, I'm fine with either.
Ok, that makes sense. Actually, I'm already using "address invalid" in the error
messages when reading the address fails, so I'll change to EINVAL for
consistency.
>
> > > > + int err;
> > >
> > > ret or err? Be consistent across a single driver.
> >
> > I had first used 'err' for both fwnode_property_count_u32() and
> > fwnode_property_read_u32_array(). The former returns "actual count or error
> > code", while the latter is only "error code". And I found it weird to read
> > the
> > code as "does error code equal 2", if I used 'err' as variable name.
> >
> > I've split this up:
> > * addr_count for fwnode_property_count_u32's result
> > * err for fwnode_property_read_u32_array's result
> >
> > Since addr_count is only used before err is touched, I guess the compiler
> > will
> > optimize this out anyway?
>
> Usually we do this pattern (and it seems you missed the point, name of
> variable is ret in some functions and err in the rest):
>
> err /* ret */ = foo();
> if (err < 0)
> return err;
> count = err;
I had only used 'ret' specifically in this one function, because I didn't like
"if (err != 2)" (and I apparently decided that I disliked that more than the
inconsistency introduced by using 'ret'). I'll stick to calling the variable
'err', and change the clause to (err != ARRAY_SIZE(addr)) to make it more
obvious that 2 isn't just some random return value.
Best,
Sander
Powered by blists - more mailing lists