All of lore.kernel.org
 help / color / mirror / Atom feed
From: Genes Lists <lists@sapience.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>,
	Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH] gpiolib: don't check the retval of get_direction() when registering a chip
Date: Tue, 11 Mar 2025 16:53:14 -0400	[thread overview]
Message-ID: <bb1d612b61d572cf678e416d3a2cfabd5ccdc07a.camel@sapience.com> (raw)
In-Reply-To: <20250311175631.83779-1-brgl@bgdev.pl>


[-- Attachment #1.1: Type: text/plain, Size: 3609 bytes --]

On Tue, 2025-03-11 at 18:56 +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> During chip registration we should neither check the return value of
> gc->get_direction() nor hold the SRCU lock when calling it. The
> former
> is because pin controllers may have pins set to alternate functions
> and
> return errors from their get_direction() callbacks. That's alright -
> we
> should default to the safe INPUT state and not bail-out. The latter
> is
> not needed because we haven't registered the chip yet so there's
> nothing
> to protect against dynamic removal. In fact: we currently hit a
> lockdep
> splat. Revert to calling the gc->get_direction() callback directly
> and
> *not* checking its value.


Tested-by: Gene C <arch@sapience.com>


> 
> Fixes: 9d846b1aebbe ("gpiolib: check the return value of
> gpio_chip::get_direction()")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Closes:
> https://lore.kernel.org/all/81f890fc-6688-42f0-9756-567efc8bb97a@samsung.com/
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Link:
> https://lore.kernel.org/r/20250226-retval-fixes-v2-1-c8dc57182441@linaro.org
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> This commit is in linux-next as 9becde08f1bc ("gpiolib: don't use
> gpiochip_get_direction() when registering a chip") and was applied as
> a fix to commits e623c4303ed1 ("gpiolib: sanitize the return value of
> gpio_chip::get_direction()") and 9d846b1aebbe ("gpiolib: check the
> return
> value of gpio_chip::get_direction()"). Becuase the former is queued
> for
> v6.15-rc1, this fix was never applied to v6.14 and sent upstream.
> 
> However, the warning it addresses is now queued for v6.14. I've
> rebased
> this commit on top of v6.14-rc6 and would like to send it upstream.
> Once
> merged, I'll pull v6.14-rc7 back into my for-next branch and fix the
> conflicts.
> 
>  drivers/gpio/gpiolib.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 8741600af7ef..de708d081858 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1056,24 +1056,19 @@ int gpiochip_add_data_with_key(struct
> gpio_chip *gc, void *data,
>  
>   desc->gdev = gdev;
>  
> - if (gc->get_direction && gpiochip_line_is_valid(gc,
> desc_index)) {
> - ret = gc->get_direction(gc, desc_index);
> - if (ret < 0)
> - /*
> - * FIXME: Bail-out here once all GPIO
> drivers
> - * are updated to not return errors in
> - * situations that can be considered
> normal
> - * operation.
> - */
> - dev_warn(&gdev->dev,
> - "%s: get_direction failed:
> %d\n",
> - __func__, ret);
> -
> - assign_bit(FLAG_IS_OUT, &desc->flags, !ret);
> - } else {
> + /*
> + * We would typically want to check the return value
> of
> + * get_direction() here but we must not check the
> return value
> + * and bail-out as pin controllers can have pins
> configured to
> + * alternate functions and return -EINVAL. Also:
> there's no
> + * need to take the SRCU lock here.
> + */
> + if (gc->get_direction && gpiochip_line_is_valid(gc,
> desc_index))
> + assign_bit(FLAG_IS_OUT, &desc->flags,
> +    !gc->get_direction(gc,
> desc_index));
> + else
>   assign_bit(FLAG_IS_OUT,
>      &desc->flags, !gc-
> >direction_input);
> - }
>   }
>  
>   ret = of_gpiochip_add(gc);

-- 
Gene


[-- Attachment #1.2: Type: text/html, Size: 11095 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2025-03-11 20:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 17:56 [PATCH] gpiolib: don't check the retval of get_direction() when registering a chip Bartosz Golaszewski
2025-03-11 20:53 ` Genes Lists [this message]
2025-03-13  8:20 ` Bartosz Golaszewski

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=bb1d612b61d572cf678e416d3a2cfabd5ccdc07a.camel@sapience.com \
    --to=lists@sapience.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.