public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ryan Mallon <rmallon@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Grant Likely <grant.likely@secretlab.ca>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] gpiolib: Refactor gpio_export
Date: Sat, 20 Oct 2012 09:14:11 +1100	[thread overview]
Message-ID: <5081D0B3.2060204@gmail.com> (raw)
In-Reply-To: <CACRpkdbgrDZ+mzy4YaGtyHTm-P2nsEL6bwB7WS=OsZ1VF4crmQ@mail.gmail.com>

On 19/10/12 21:07, Linus Walleij wrote:

> On Wed, Oct 17, 2012 at 1:41 AM, Ryan Mallon <rmallon@gmail.com> wrote:
> 
>> The gpio_export function uses nested if statements and the status
>> variable to handle the failure cases. This makes the function logic
>> difficult to follow. Refactor the code to abort immediately on failure
>> using goto. This makes the code slightly longer, but significantly
>> reduces the nesting and number of split lines and makes the code easier
>> to read.
>>
>> Signed-off-by: Ryan Mallon
> 
> Very good initiative!
> 
>> +++ b/drivers/gpio/gpiolib.c
>> @@ -702,68 +702,74 @@ int gpio_export(unsigned gpio, bool direction_may_change)
>>  {
>>         unsigned long           flags;
>>         struct gpio_desc        *desc;
>> -       int                     status = -EINVAL;
>> +       int                     status;
>>         const char              *ioname = NULL;
>> +       struct device           *dev;
>>
>>         /* can't export until sysfs is available ... */
>>         if (!gpio_class.p) {
>>                 pr_debug("%s: called too early!\n", __func__);
>> -               return -ENOENT;
>> +               status = -ENOENT;
>> +               goto fail;
> 
> Why bother with all the goto:s here since there are no resources
> to clean up? Just pr_debug() and return -ENOENT; is good enough.
> 
> I don't quite see the point.

I did it this way just so that there would be a single exit point.
I don't mind either way, so I'll update the ones without any
clean up to simply return.

> Arguably this should be pr_err() or something BTW, just debug()
> may hide serious bugs.


Not sure about that. User-space can check the return code if it
wants to find out why the call failed. We shouldn't 
unconditionally spam the log with error messages on sysfs 
access since it makes an easy DoS vector on the syslog. The
pr_debug messages I think are really for people who are 
developing on gpiolib.

~Ryan

  reply	other threads:[~2012-10-19 22:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-16 23:41 [RFC PATCH] gpiolib: Refactor gpio_export Ryan Mallon
2012-10-19 10:07 ` Linus Walleij
2012-10-19 22:14   ` Ryan Mallon [this message]
2012-10-19 22:43     ` Grant Likely

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=5081D0B3.2060204@gmail.com \
    --to=rmallon@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.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