From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
To: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Cc: linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] gpio: tegra: Implement gpio_get_direction callback
Date: Fri, 29 Apr 2016 10:17:23 -0600 [thread overview]
Message-ID: <57238913.4080905@wwwdotorg.org> (raw)
In-Reply-To: <1461933078-20366-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
On 04/29/2016 06:31 AM, Laxman Dewangan wrote:
> Implement gpio_get_direction() callback for Tegra GPIO.
> The direction is only valid if the pin is configured as
> GPIO. If pin is not configured in GPIO mode then this
> function return error.
>
> This makes debugfs and initial reading of the state of
> the lines more accurate.
> +static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
> +{
> + struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
> + u32 pin_mask = BIT(GPIO_BIT(offset));
> + u32 cnf, oe;
> +
> + cnf = tegra_gpio_readl(tgi, GPIO_CNF(tgi, offset));
> + oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset));
> + if (cnf & pin_mask) {
> + if (oe & pin_mask)
> + return GPIOF_DIR_OUT;
> +
> + return GPIOF_DIR_IN;
> + }
> +
> + return -EINVAL;
> +}
Conceptually looks fine, but I have similar comments to Jon; whenever
there's an error condition, just fail immediately. That way you avoid
the entire rest of the function being indented:
cnf = ...
if (!(cnf ...)
return -EINVAL;
oe = ...
return ...
The only indented code there is the error handling. At least to me, this
makes the code a lot more readable since there are far fewer
combinations of conditionals.
prev parent reply other threads:[~2016-04-29 16:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-29 12:31 [PATCH] gpio: tegra: Implement gpio_get_direction callback Laxman Dewangan
2016-04-29 15:30 ` Jon Hunter
[not found] ` <1461933078-20366-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-04-29 16:17 ` Stephen Warren [this message]
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=57238913.4080905@wwwdotorg.org \
--to=swarren-3lzwwm7+weoh9zmkesr00q@public.gmane.org \
--cc=ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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