Received: by 10.192.165.148 with SMTP id m20csp692329imm; Fri, 27 Apr 2018 06:04:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpYchNYIh8Fv1JCHJ3A7SpZPE/syO1t3UKsVi04JSzb8jvTcHZd/OnnAflBYx6azfJztxuz X-Received: by 2002:a17:902:265:: with SMTP id 92-v6mr2207250plc.368.1524834268462; Fri, 27 Apr 2018 06:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524834268; cv=none; d=google.com; s=arc-20160816; b=Z0m8L2nUO6OBq1y1UqCQNvJfrnRdf6ucbcWKi7bvka1tWaWGof4WD63P9FqdH8ag3E dT3XO8jx58p0H4cTje5hkwTKNXHaZWlnG1YawRUI9CPkPnBGAANIGPekiIPmeuYb5L6X OtluBl2907K2xBFP+3+XbbgO/5D0FeaPDqBkN1LWrMUfSHTV5fD+RoXK9PbzFGKRLmuM FqwgYG0VXWN2gMo7pfO5sxpdbxJ3O+PPWZnKeMK4X1BhJl6XZswUPKs6wsxsCcr38Xqz JHXICDQvisVsKbmScdvKvGFqSiFZJleSfHpzWrgHLU6A7+QATX0hcX0nv9x3k5UMBg0r Hf2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=InviwTA61RrYQknFBxHkrnva0BOePyXJU34AaIN+xu4=; b=DpStogNXIZRauSG1aBdZGou98liX9u8jTDF0Md0qH5hu9jQ+542jien0OeGhzr6W+B 9BtdWMWtSX/qwNqz7R2boxV00h35lzB9XPctNkzqgFN4HH2CfQ34uPIMhiz6HjcAt/zz pi7t68AcHyYWf1gqbe5MKUko6Gs9v2XYLpFElGfLBhCqog6Ko6lgkEu5u3lS0Zr9YA3c 0zR8eO8oMWlXmBqzSd+CJPKJTxxA8RqSBdqCYPEYCWam3B8DejBt80Dz3r0+ODGfA3cs uyxC4/bM6JimRyJ73dN3qKH8S/a8CK+yAKC6WETQ1fdKN0XJ9CCojLnzbCWI5UdJs7fm jRwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JQAYxGem; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 188-v6si1186414pgg.546.2018.04.27.06.04.14; Fri, 27 Apr 2018 06:04:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JQAYxGem; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932323AbeD0NCx (ORCPT + 99 others); Fri, 27 Apr 2018 09:02:53 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:40710 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757982AbeD0NCw (ORCPT ); Fri, 27 Apr 2018 09:02:52 -0400 Received: by mail-qt0-f195.google.com with SMTP id h2-v6so2093426qtp.7 for ; Fri, 27 Apr 2018 06:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=InviwTA61RrYQknFBxHkrnva0BOePyXJU34AaIN+xu4=; b=JQAYxGemaKM8PCc8lU3fz140FkqcNFQHq9/lK5Y+/h8mjW7+GnYieQIpU+6dpoS8e6 zjHZlNzQEYVPfUvHe+BA7wQ0mqN4qfyepaI4fWgJ/xEnFzcbp3NNseu32ofUqZBa7y7N S0cBAvt3H+LuxbQTvSpAg8QO6zT4W+0CmDItQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=InviwTA61RrYQknFBxHkrnva0BOePyXJU34AaIN+xu4=; b=a75lXpiAqjk1Yw+3zkmdi4BXAx7KN9XQfPh8b2QsVYQtbhDPt9/sIQkDcwnaxkWYlh XmefZuSdRlPx/ZTJW209+/A3NsVPBqrdVMcvWmMsxkwZXstk3doVPAYpezUbxaIdSddA XrD0n5IgYdvc8KKQiNtvHET7SCThZWs4nvAjdHpkng5aOf+unL31JTDVHPEtY9NGYZrb eoXShf7hLEDJXdI2FtdlvPAGLpf7AlpmSpsDjj5zZ9TqNrgJX0v8L9pPvPG9VHtBK1MW 7RrgMdLjCQz2Au+hnI6Qm2NIgRTX+bj42VOFVxy5ee5cswULpc+dWkH8S2LV0JsTTPY+ 0Mlg== X-Gm-Message-State: ALQs6tCGBcmwfzgUyVFJVxj18uQSo5OklG0XuERU1K9tTqGkaY44Mq4c Jud4eftQw6LksWdBV7/ti5A75mQQ00g= X-Received: by 2002:a0c:f086:: with SMTP id g6-v6mr1893225qvk.54.1524834171296; Fri, 27 Apr 2018 06:02:51 -0700 (PDT) Received: from [172.22.22.26] (c-71-195-29-92.hsd1.mn.comcast.net. [71.195.29.92]) by smtp.googlemail.com with ESMTPSA id s3-v6sm952072qte.82.2018.04.27.06.02.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 06:02:50 -0700 (PDT) Subject: Re: [greybus-dev] [PATCH] staging: greybus: Use gpio_is_valid() To: Arvind Yadav , hvaibhav.linux@gmail.com, johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org Cc: devel@driverdev.osuosl.org, greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org References: <785eda4d65f396b353393e9538eba21095ce876e.1524825902.git.arvind.yadav.cs@gmail.com> <7ebee672-6413-6f1d-fe57-2e278c90cf9e@linaro.org> <3910023d-143e-7618-1fd4-f3bdffbfb3ec@gmail.com> From: Alex Elder Message-ID: Date: Fri, 27 Apr 2018 08:02:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <3910023d-143e-7618-1fd4-f3bdffbfb3ec@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/27/2018 07:50 AM, Arvind Yadav wrote: > > > On Friday 27 April 2018 05:47 PM, Alex Elder wrote: >> On 04/27/2018 05:52 AM, Arvind Yadav wrote: >>> Replace the manual validity checks for the GPIO with the >>> gpio_is_valid(). >> I haven't looked through the code paths very closely, but I >> think that get_named_gpio() might return -EPROBE_DEFER, which >> would be something we want to pass to the caller. > Yes of_get_name_gpio() can return other error value apart from > -EPROBE_DEFER. >> So rather than returning -ENODEV and hiding the reason the >> call to of_get_named_gpio() failed, you should continue >> returning the errno it supplies (if not a valid gpio number). >> >>                     -Alex > I have return -ENODEV because invalid gpio pin can be positive. > static inline bool gpio_is_valid(int number) > { >     return number >= 0 && number < ARCH_NR_GPIOS; > } > Here if number > ARCH_NR_GPIOS then it's invalid but return value > will be positive. Your reasoning is good. However in all three of these cases, the GPIO number you're checking is the value returned from of_get_named_gpio(). The return value is a "GPIO number to use with Linux generic GPIO API, or one of the errno value." So unless the API of of_get_named_gpio() changes, you can be sure that if the value returned is invalid, it is a negative errno. (And if the API did change, the person making that change would be responsible for fixing all callers to ensure the change didn't break them.) This distinction may be why the code you're changing was only testing for negative, rather than using gpio_is_valid() (you'll see it's used elsewhere in the Greybus code--even in the same source files.) Anyway, changing the code to use gpio_is_valid() is fine. But you should avoid obscuring the reason for the error that the return value from of_get_named_gpio() provides. -Alex > We can return like this >     " return (gpio > 0) ? -ENODEV: gpio;" > > But not sure this is worth to handle this. > > ~arvind >> >>> Signed-off-by: Arvind Yadav >>> --- >>>   drivers/staging/greybus/arche-platform.c | 12 ++++++------ >>>   1 file changed, 6 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c >>> index 83254a7..fc6bf60 100644 >>> --- a/drivers/staging/greybus/arche-platform.c >>> +++ b/drivers/staging/greybus/arche-platform.c >>> @@ -448,9 +448,9 @@ static int arche_platform_probe(struct platform_device *pdev) >>>       arche_pdata->svc_reset_gpio = of_get_named_gpio(np, >>>                               "svc,reset-gpio", >>>                               0); >>> -    if (arche_pdata->svc_reset_gpio < 0) { >>> +    if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) { >>>           dev_err(dev, "failed to get reset-gpio\n"); >>> -        return arche_pdata->svc_reset_gpio; >>> +        return -ENODEV; >>>       } >>>       ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset"); >>>       if (ret) { >>> @@ -468,9 +468,9 @@ static int arche_platform_probe(struct platform_device *pdev) >>>       arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np, >>>                                 "svc,sysboot-gpio", >>>                                 0); >>> -    if (arche_pdata->svc_sysboot_gpio < 0) { >>> +    if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) { >>>           dev_err(dev, "failed to get sysboot gpio\n"); >>> -        return arche_pdata->svc_sysboot_gpio; >>> +        return -ENODEV; >>>       } >>>       ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0"); >>>       if (ret) { >>> @@ -487,9 +487,9 @@ static int arche_platform_probe(struct platform_device *pdev) >>>       arche_pdata->svc_refclk_req = of_get_named_gpio(np, >>>                               "svc,refclk-req-gpio", >>>                               0); >>> -    if (arche_pdata->svc_refclk_req < 0) { >>> +    if (!gpio_is_valid(arche_pdata->svc_refclk_req)) { >>>           dev_err(dev, "failed to get svc clock-req gpio\n"); >>> -        return arche_pdata->svc_refclk_req; >>> +        return -ENODEV; >>>       } >>>       ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req, >>>                   "svc-clk-req"); >>> >