* [PATCH] pinctrl: fix Null pointer dereference
@ 2024-10-03 2:33 clingfei
2024-10-03 2:56 ` Drew Fustini
2024-10-03 14:08 ` Linus Walleij
0 siblings, 2 replies; 4+ messages in thread
From: clingfei @ 2024-10-03 2:33 UTC (permalink / raw)
To: drew, guoren, wefu, linus.walleij
Cc: linux-riscv, linux-gpio, linux-kernel, clf700383
pinmux_generic_get_function may returns NULL, and its retval is
dereferenced without check, which will cause a null pointer dereference.
Signed-off-by: clingfei <clf700383@gmail.com>
---
drivers/pinctrl/pinctrl-th1520.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
index 1bb78b212fd5..9331f4462480 100644
--- a/drivers/pinctrl/pinctrl-th1520.c
+++ b/drivers/pinctrl/pinctrl-th1520.c
@@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
+ if (!func)
+ return -EINVAL;
return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
(uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA,
(uintptr_t)func->data);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] pinctrl: fix Null pointer dereference
2024-10-03 2:33 [PATCH] pinctrl: fix Null pointer dereference clingfei
@ 2024-10-03 2:56 ` Drew Fustini
2024-10-03 14:08 ` Linus Walleij
1 sibling, 0 replies; 4+ messages in thread
From: Drew Fustini @ 2024-10-03 2:56 UTC (permalink / raw)
To: clingfei
Cc: drew, guoren, wefu, linus.walleij, linux-riscv, linux-gpio,
linux-kernel
On Thu, Oct 03, 2024 at 10:33:07AM +0800, clingfei wrote:
> pinmux_generic_get_function may returns NULL, and its retval is
> dereferenced without check, which will cause a null pointer dereference.
>
> Signed-off-by: clingfei <clf700383@gmail.com>
> ---
> drivers/pinctrl/pinctrl-th1520.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
> index 1bb78b212fd5..9331f4462480 100644
> --- a/drivers/pinctrl/pinctrl-th1520.c
> +++ b/drivers/pinctrl/pinctrl-th1520.c
> @@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
> struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
> const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
>
> + if (!func)
> + return -EINVAL;
> return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
> (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA,
> (uintptr_t)func->data);
> --
> 2.34.1
Thanks for fixing the formating in the previous attempt.
As Kees Bakker noted [1], I failed to have this check in my v3 patch
series. This fix makes pinctrl-th1520 behave the same as other drivers
that call pinmux_generic_get_function() like pinctrl-single. I have
applied your patch and the driver still works as expected on my LPi4a.
Hopefully Linus can apply this fix on top of my v3 series.
Reviewed-by: Drew Fustini <dfustini@tenstorrent.com>
-Drew
[1] https://lore.kernel.org/lkml/87770518-5f63-4adf-b6ea-c7f92b58ce22@ijzerbout.nl/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] pinctrl: fix Null pointer dereference
2024-10-03 2:33 [PATCH] pinctrl: fix Null pointer dereference clingfei
2024-10-03 2:56 ` Drew Fustini
@ 2024-10-03 14:08 ` Linus Walleij
1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-10-03 14:08 UTC (permalink / raw)
To: clingfei; +Cc: drew, guoren, wefu, linux-riscv, linux-gpio, linux-kernel
On Thu, Oct 3, 2024 at 4:33 AM clingfei <clf700383@gmail.com> wrote:
> pinmux_generic_get_function may returns NULL, and its retval is
> dereferenced without check, which will cause a null pointer dereference.
>
> Signed-off-by: clingfei <clf700383@gmail.com>
Fixed up topic, added Drew's tag and applied, thanks!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] pinctrl: fix Null pointer dereference
@ 2024-10-03 1:52 xi xi
0 siblings, 0 replies; 4+ messages in thread
From: xi xi @ 2024-10-03 1:52 UTC (permalink / raw)
To: Drew Fustini, Guo Ren, Fu Wei, Linus Walleij
Cc: linux-riscv, linux-gpio, linux-kernel
From b673ea2897c5efc60b4ad8f9b4a4327ddce0737e Mon Sep 17 00:00:00 2001
From: clingfei <clf700383@gmail.com>
Date: Wed, 2 Oct 2024 23:33:47 +0800
Subject: [PATCH] pinctrl: fix Null pointer dereference
pinmux_generic_get_function may returns NULL, and its retval is
dereferenced without check, which will cause a null pointer dereference.
Signed-off-by: clingfei <clf700383@gmail.com>
---
drivers/pinctrl/pinctrl-th1520.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
index 1bb78b212fd5..9331f4462480 100644
--- a/drivers/pinctrl/pinctrl-th1520.c
+++ b/drivers/pinctrl/pinctrl-th1520.c
@@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct
pinctrl_dev *pctldev,
struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
const struct function_desc *func =
pinmux_generic_get_function(pctldev, fsel);
+ if (!func)
+ return -EINVAL;
return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
(uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA,
(uintptr_t)func->data);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-03 14:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-03 2:33 [PATCH] pinctrl: fix Null pointer dereference clingfei
2024-10-03 2:56 ` Drew Fustini
2024-10-03 14:08 ` Linus Walleij
-- strict thread matches above, loose matches on Subject: below --
2024-10-03 1:52 xi xi
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).