* [PATCH] gpiolib: fix lookup table matching
@ 2026-01-08 10:23 ` Bartosz Golaszewski
2026-01-08 10:31 ` Marek Szyprowski
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-01-08 10:23 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Marek Szyprowski, Konrad Dybcio
Cc: linux-kernel, linux-gpio, Bartosz Golaszewski
If on any iteration in gpiod_find(), gpio_desc_table_match() returns
NULL (which is normal and expected), we never reinitialize desc back to
ERR_PTR(-ENOENT) and if we don't find a match later on, we will return
NULL causing a NULL-pointer dereference in users not expecting it. Don't
initialize desc, but return ERR_PTR(-ENOENT) explicitly at the end of
the function.
Fixes: 9700b0fccf38 ("gpiolib: allow multiple lookup tables per consumer")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Closes: https://lore.kernel.org/all/00107523-7737-4b92-a785-14ce4e93b8cb@samsung.com/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index fc382f43f9fc..0a14085f3871 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4602,8 +4602,8 @@ static struct gpio_desc *gpio_desc_table_match(struct device *dev, const char *c
static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
unsigned int idx, unsigned long *flags)
{
- struct gpio_desc *desc = ERR_PTR(-ENOENT);
struct gpiod_lookup_table *table;
+ struct gpio_desc *desc;
guard(mutex)(&gpio_lookup_lock);
@@ -4619,7 +4619,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
return desc;
}
- return desc;
+ return ERR_PTR(-ENOENT);
}
static int platform_gpio_count(struct device *dev, const char *con_id)
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpiolib: fix lookup table matching
2026-01-08 10:23 ` [PATCH] gpiolib: fix lookup table matching Bartosz Golaszewski
@ 2026-01-08 10:31 ` Marek Szyprowski
2026-01-08 14:23 ` Bartosz Golaszewski
2026-01-09 4:42 ` Val Packett
2 siblings, 0 replies; 4+ messages in thread
From: Marek Szyprowski @ 2026-01-08 10:31 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski, Konrad Dybcio
Cc: linux-kernel, linux-gpio
On 08.01.2026 11:23, Bartosz Golaszewski wrote:
> If on any iteration in gpiod_find(), gpio_desc_table_match() returns
> NULL (which is normal and expected), we never reinitialize desc back to
> ERR_PTR(-ENOENT) and if we don't find a match later on, we will return
> NULL causing a NULL-pointer dereference in users not expecting it. Don't
> initialize desc, but return ERR_PTR(-ENOENT) explicitly at the end of
> the function.
>
> Fixes: 9700b0fccf38 ("gpiolib: allow multiple lookup tables per consumer")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Closes: https://lore.kernel.org/all/00107523-7737-4b92-a785-14ce4e93b8cb@samsung.com/
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
> drivers/gpio/gpiolib.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index fc382f43f9fc..0a14085f3871 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -4602,8 +4602,8 @@ static struct gpio_desc *gpio_desc_table_match(struct device *dev, const char *c
> static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
> unsigned int idx, unsigned long *flags)
> {
> - struct gpio_desc *desc = ERR_PTR(-ENOENT);
> struct gpiod_lookup_table *table;
> + struct gpio_desc *desc;
>
> guard(mutex)(&gpio_lookup_lock);
>
> @@ -4619,7 +4619,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
> return desc;
> }
>
> - return desc;
> + return ERR_PTR(-ENOENT);
> }
>
> static int platform_gpio_count(struct device *dev, const char *con_id)
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpiolib: fix lookup table matching
2026-01-08 10:23 ` [PATCH] gpiolib: fix lookup table matching Bartosz Golaszewski
2026-01-08 10:31 ` Marek Szyprowski
@ 2026-01-08 14:23 ` Bartosz Golaszewski
2026-01-09 4:42 ` Val Packett
2 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-01-08 14:23 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Marek Szyprowski,
Konrad Dybcio, Bartosz Golaszewski
Cc: linux-kernel, linux-gpio
On Thu, 08 Jan 2026 11:23:14 +0100, Bartosz Golaszewski wrote:
> If on any iteration in gpiod_find(), gpio_desc_table_match() returns
> NULL (which is normal and expected), we never reinitialize desc back to
> ERR_PTR(-ENOENT) and if we don't find a match later on, we will return
> NULL causing a NULL-pointer dereference in users not expecting it. Don't
> initialize desc, but return ERR_PTR(-ENOENT) explicitly at the end of
> the function.
>
> [...]
Applied, thanks!
[1/1] gpiolib: fix lookup table matching
commit: 36f597bba049928004a050c132ab787ba0eba524
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpiolib: fix lookup table matching
2026-01-08 10:23 ` [PATCH] gpiolib: fix lookup table matching Bartosz Golaszewski
2026-01-08 10:31 ` Marek Szyprowski
2026-01-08 14:23 ` Bartosz Golaszewski
@ 2026-01-09 4:42 ` Val Packett
2 siblings, 0 replies; 4+ messages in thread
From: Val Packett @ 2026-01-09 4:42 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski,
Marek Szyprowski, Konrad Dybcio
Cc: linux-kernel, linux-gpio
On 1/8/26 7:23 AM, Bartosz Golaszewski wrote:
> If on any iteration in gpiod_find(), gpio_desc_table_match() returns
> NULL (which is normal and expected), we never reinitialize desc back to
> ERR_PTR(-ENOENT) and if we don't find a match later on, we will return
> NULL causing a NULL-pointer dereference in users not expecting it. Don't
> initialize desc, but return ERR_PTR(-ENOENT) explicitly at the end of
> the function.
>
> Fixes: 9700b0fccf38 ("gpiolib: allow multiple lookup tables per consumer")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Closes: https://lore.kernel.org/all/00107523-7737-4b92-a785-14ce4e93b8cb@samsung.com/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Tested-by: Val Packett <val@packett.cool>
This also fixes things on Qualcomm x1e laptops (same NULL deref logged
from snd_soc_wcd938x wcd938x_probe, but as a consequence the display&gpu
subsystem also wouldn't work)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-09 4:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20260108102327eucas1p1441a46ec3d1be1e9eaee611959014de3@eucas1p1.samsung.com>
2026-01-08 10:23 ` [PATCH] gpiolib: fix lookup table matching Bartosz Golaszewski
2026-01-08 10:31 ` Marek Szyprowski
2026-01-08 14:23 ` Bartosz Golaszewski
2026-01-09 4:42 ` Val Packett
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®