From: Grygorii Strashko <grygorii.strashko@ti.com>
To: Linus Walleij <linus.walleij@linaro.org>,
linux-gpio@vger.kernel.org,
Alexandre Courbot <acourbot@nvidia.com>
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] gpio: make library immune to error pointers
Date: Thu, 16 Jun 2016 13:19:17 +0300 [thread overview]
Message-ID: <57627D25.9060702@ti.com> (raw)
In-Reply-To: <1466071160-16722-1-git-send-email-linus.walleij@linaro.org>
On 06/16/2016 12:59 PM, Linus Walleij wrote:
> Most functions that take a GPIO descriptor in need to check the
> descriptor for IS_ERR(). We do this mostly in the VALIDATE_DESC()
> macro except for the gpiod_to_irq() function which needs special
> handling.
>
> Cc: stable@vger.kernel.org
> Reported-by: Grygorii Strashko <grygorii.strashko@ti.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> drivers/gpio/gpiolib.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index f39bf05993e7..1a8dbc791892 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1371,7 +1371,7 @@ done:
> * optional GPIO and calls should just bail out.
> */
> #define VALIDATE_DESC(desc) do { \
> - if (!desc) \
> + if (!desc || IS_ERR(desc)) \
> return 0; \
i do not think this right thing to return 0 here :(
if IS_ERR(desc) this is bug and drivers must handle this properly.
For example, -EPROBE_DEFER
> if (!desc->gdev) { \
> pr_warn("%s: invalid GPIO\n", __func__); \
> @@ -1384,7 +1384,7 @@ done:
> } } while (0)
>
> #define VALIDATE_DESC_VOID(desc) do { \
> - if (!desc) \
> + if (!desc || IS_ERR(desc)) \
> return; \
> if (!desc->gdev) { \
> pr_warn("%s: invalid GPIO\n", __func__); \
> @@ -2061,7 +2061,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
> * requires this function to not return zero on an invalid descriptor
> * but rather a negative error number.
> */
> - if (!desc || !desc->gdev || !desc->gdev->chip)
> + if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip)
> return -EINVAL;
>
> chip = desc->gdev->chip;
>
--
regards,
-grygorii
prev parent reply other threads:[~2016-06-16 10:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 9:59 [PATCH] gpio: make library immune to error pointers Linus Walleij
2016-06-16 10:19 ` Grygorii Strashko [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=57627D25.9060702@ti.com \
--to=grygorii.strashko@ti.com \
--cc=acourbot@nvidia.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=stable@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;
as well as URLs for NNTP newsgroup(s).