[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z-1QzesPs7A3_FQY@black.fi.intel.com>
Date: Wed, 2 Apr 2025 17:59:25 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: Florian Fainelli <florian.fainelli@...adcom.com>,
linux-kernel@...r.kernel.org, Mark Brown <broonie@...nel.org>,
Ray Jui <rjui@...adcom.com>, Scott Branden <sbranden@...adcom.com>,
Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>,
"open list:SPI SUBSYSTEM" <linux-spi@...r.kernel.org>,
"moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" <linux-rpi-kernel@...ts.infradead.org>,
"moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH] spi: bcm2835: Do not call gpiod_put() on invalid
descriptor
On Wed, Apr 02, 2025 at 01:36:28PM +0200, Bartosz Golaszewski wrote:
> On Wed, Apr 2, 2025 at 12:43 AM Florian Fainelli
> <florian.fainelli@...adcom.com> wrote:
> >
> > If we are unable to lookup the chip-select GPIO, the error path will
> > call bcm2835_spi_cleanup() which unconditionally calls gpiod_put() on
> > the cs->gpio variable which we just determined was invalid.
...
> > - gpiod_put(bs->cs_gpio);
> > + if (!IS_ERR(bs->cs_gpio))
> > + gpiod_put(bs->cs_gpio);
> We could also just set it to NULL on error in bcm2835_spi_setup() but
> I'm fine either way.
I think this patch papers over the real issue:
1) the cleanup call does everything and not split to have the exact reversed order of the setup;
2) the GPIO here as far as I understand is not optional and on errors may contain an error pointer
but gpiod_put() ignores that.
TL;DR: I think the proper fix is to make gpio_put() to accept an error pointer as NULL. I.o.w.
if (desc) --> if (!IS_ERR_OR_NULL(desc)) in all conditionals related to gpiod*put*() calls.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists