Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753290AbcD2QR2 (ORCPT ); Fri, 29 Apr 2016 12:17:28 -0400 Received: from avon.wwwdotorg.org ([70.85.31.133]:40278 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752964AbcD2QR0 (ORCPT ); Fri, 29 Apr 2016 12:17:26 -0400 Subject: Re: [PATCH] gpio: tegra: Implement gpio_get_direction callback To: Laxman Dewangan References: <1461933078-20366-1-git-send-email-ldewangan@nvidia.com> Cc: linus.walleij@linaro.org, thierry.reding@gmail.com, linux-gpio@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org From: Stephen Warren Message-ID: <57238913.4080905@wwwdotorg.org> Date: Fri, 29 Apr 2016 10:17:23 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1461933078-20366-1-git-send-email-ldewangan@nvidia.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1216 Lines: 40 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.