From: Antonio Borneo <antonio.borneo@foss.st.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
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>,
<stable@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH 1/8] gpiolib: check the return value of gpio_chip::get_direction()
Date: Tue, 25 Feb 2025 14:19:46 +0100 [thread overview]
Message-ID: <ca48a3e6586ca5b1afd6e1bd81c612545df60e52.camel@foss.st.com> (raw)
In-Reply-To: <dfe03f88-407e-4ef1-ad30-42db53bbd4e4@samsung.com>
On Wed, 2025-02-19 at 09:38 +0100, Marek Szyprowski wrote:
> Hi Bartosz,
>
> On 10.02.2025 11:51, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > As per the API contract - gpio_chip::get_direction() may fail and return
> > a negative error number. However, we treat it as if it always returned 0
> > or 1. Check the return value of the callback and propagate the error
> > number up the stack.
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > ---
> > drivers/gpio/gpiolib.c | 44 +++++++++++++++++++++++++++++---------------
> > 1 file changed, 29 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index 679ed764cb14..5d3774dc748b 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -1057,8 +1057,11 @@ 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)) {
> > - assign_bit(FLAG_IS_OUT,
> > - &desc->flags, !gc->get_direction(gc, desc_index));
> > + ret = gc->get_direction(gc, desc_index);
> > + if (ret < 0)
> > + goto err_cleanup_desc_srcu;
> > +
> > + assign_bit(FLAG_IS_OUT, &desc->flags, !ret);
> > } else {
> > assign_bit(FLAG_IS_OUT,
> > &desc->flags, !gc->direction_input);
>
> This change breaks bcm2835 pincontrol/gpio driver (and probably others)
> in next-20250218. The problem is that some gpio lines are initially
> configured as alternate function (i.e. uart) and .get_direction returns
> -EINVAL for them, what in turn causes the whole gpio chip fail to
> register. Here is the log with WARN_ON() added to line
> drivers/pinctrl/bcm/pinctrl-bcm2835.c:350 from Raspberry Pi 4B:
Same issue with STM32 pinctrl.
I will send out shortly a patch, similar to
https://lore.kernel.org/all/20250219102750.38519-1-brgl@bgdev.pl/
Regards,
Antonio
next prev parent reply other threads:[~2025-02-25 14:49 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 10:51 [PATCH 0/8] gpiolib: sanitize return values of callbacks Bartosz Golaszewski
2025-02-10 10:51 ` [PATCH 1/8] gpiolib: check the return value of gpio_chip::get_direction() Bartosz Golaszewski
2025-02-19 2:42 ` Mark Brown
[not found] ` <CGME20250219083836eucas1p1b7ecc6e5fdc34d66ef7565bfcf399254@eucas1p1.samsung.com>
2025-02-19 8:38 ` Marek Szyprowski
2025-02-19 8:50 ` Bartosz Golaszewski
2025-02-19 9:13 ` Marek Szyprowski
2025-02-19 9:22 ` Bartosz Golaszewski
2025-02-25 13:19 ` Antonio Borneo [this message]
2025-02-10 10:51 ` [PATCH 2/8] gpiolib: sanitize the return value of gpio_chip::request() Bartosz Golaszewski
2025-02-10 10:51 ` [PATCH 3/8] gpiolib: sanitize the return value of gpio_chip::set_config() Bartosz Golaszewski
2025-02-10 10:51 ` [PATCH 4/8] gpiolib: sanitize the return value of gpio_chip::get() Bartosz Golaszewski
2025-02-24 16:30 ` Andy Shevchenko
2025-02-25 10:35 ` Bartosz Golaszewski
2025-02-10 10:51 ` [PATCH 5/8] gpiolib: sanitize the return value of gpio_chip::get_multiple() Bartosz Golaszewski
2025-02-10 10:52 ` [PATCH 6/8] gpiolib: sanitize the return value of gpio_chip::direction_output() Bartosz Golaszewski
2025-02-10 10:52 ` [PATCH 7/8] gpiolib: sanitize the return value of gpio_chip::direction_input() Bartosz Golaszewski
2025-02-10 10:52 ` [PATCH 8/8] gpiolib: sanitize the return value of gpio_chip::get_direction() Bartosz Golaszewski
2025-02-24 16:33 ` Andy Shevchenko
2025-02-24 19:55 ` Bartosz Golaszewski
2025-02-24 20:25 ` Andy Shevchenko
[not found] ` <CGME20250225101340eucas1p13c0c9cbc62ee7c9bfe964941c901bd1b@eucas1p1.samsung.com>
2025-02-25 10:13 ` Marek Szyprowski
2025-02-25 10:17 ` Bartosz Golaszewski
2025-02-14 9:21 ` [PATCH 0/8] gpiolib: sanitize return values of callbacks Linus Walleij
2025-02-17 10:51 ` (subset) " Bartosz Golaszewski
2025-02-24 9:05 ` 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=ca48a3e6586ca5b1afd6e1bd81c612545df60e52.camel@foss.st.com \
--to=antonio.borneo@foss.st.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=linux-stm32@st-md-mailman.stormreply.com \
--cc=m.szyprowski@samsung.com \
--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).