* [PATCH][next] pinctrl: th1520: Dereference pointer only after NULL check
@ 2024-10-16 13:42 Everest K.C.
2024-10-16 21:00 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: Everest K.C. @ 2024-10-16 13:42 UTC (permalink / raw)
To: drew, guoren, wefu, linus.walleij
Cc: Everest K.C., skhan, linux-riscv, linux-gpio, kernel-janitors,
linux-kernel
The pointer `func` is dereferenced before NULL check.
Move the dereference after the NULL check.
This issue was reported by Coverity Scan.
Report:
CID 1600802: (#1 of 1): Dereference before null check
(REVERSE_INULL)
check_after_deref: Null-checking func suggests that it
may be null, but it has already been dereferenced on all
paths leading to the check.
Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
---
drivers/pinctrl/pinctrl-th1520.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
index 7474d8da32f9..07f8b51fb294 100644
--- a/drivers/pinctrl/pinctrl-th1520.c
+++ b/drivers/pinctrl/pinctrl-th1520.c
@@ -803,11 +803,13 @@ 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);
- enum th1520_muxtype muxtype = (uintptr_t)func->data;
+ enum th1520_muxtype muxtype;
if (!func)
return -EINVAL;
+ muxtype = (uintptr_t)func->data;
+
return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
th1520_pad_muxdata(thp->desc.pins[gsel].drv_data),
muxtype);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] pinctrl: th1520: Dereference pointer only after NULL check
2024-10-16 13:42 [PATCH][next] pinctrl: th1520: Dereference pointer only after NULL check Everest K.C.
@ 2024-10-16 21:00 ` Shuah Khan
2024-10-17 2:54 ` Everest K.C.
0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2024-10-16 21:00 UTC (permalink / raw)
To: Everest K.C., drew, guoren, wefu, linus.walleij
Cc: linux-riscv, linux-gpio, kernel-janitors, linux-kernel,
Shuah Khan
On 10/16/24 07:42, Everest K.C. wrote:
> The pointer `func` is dereferenced before NULL check.
> Move the dereference after the NULL check.
Change log looks fine.
Short log that clearly says it is a fix would be better:
Fix potential null pointer defereference
>
> This issue was reported by Coverity Scan.
> Report:
> CID 1600802: (#1 of 1): Dereference before null check
> (REVERSE_INULL)
> check_after_deref: Null-checking func suggests that it
> may be null, but it has already been dereferenced on all
> paths leading to the check.
>
> Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
> Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> ---
> drivers/pinctrl/pinctrl-th1520.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
> index 7474d8da32f9..07f8b51fb294 100644
> --- a/drivers/pinctrl/pinctrl-th1520.c
> +++ b/drivers/pinctrl/pinctrl-th1520.c
> @@ -803,11 +803,13 @@ 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);
> - enum th1520_muxtype muxtype = (uintptr_t)func->data;
> + enum th1520_muxtype muxtype;
>
> if (!func)
> return -EINVAL;
>
> + muxtype = (uintptr_t)func->data;
> +
> return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
> th1520_pad_muxdata(thp->desc.pins[gsel].drv_data),
> muxtype);
Otherwise looks good to me. With the change to short log:
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] pinctrl: th1520: Dereference pointer only after NULL check
2024-10-16 21:00 ` Shuah Khan
@ 2024-10-17 2:54 ` Everest K.C.
0 siblings, 0 replies; 3+ messages in thread
From: Everest K.C. @ 2024-10-17 2:54 UTC (permalink / raw)
To: Shuah Khan
Cc: drew, guoren, wefu, linus.walleij, linux-riscv, linux-gpio,
kernel-janitors, linux-kernel
On Wed, Oct 16, 2024 at 3:00 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>
> On 10/16/24 07:42, Everest K.C. wrote:
> > The pointer `func` is dereferenced before NULL check.
> > Move the dereference after the NULL check.
>
> Change log looks fine.
>
> Short log that clearly says it is a fix would be better:
>
> Fix potential null pointer defereference
>
> >
> > This issue was reported by Coverity Scan.
> > Report:
> > CID 1600802: (#1 of 1): Dereference before null check
> > (REVERSE_INULL)
> > check_after_deref: Null-checking func suggests that it
> > may be null, but it has already been dereferenced on all
> > paths leading to the check.
> >
> > Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
> > Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> > ---
> > drivers/pinctrl/pinctrl-th1520.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
> > index 7474d8da32f9..07f8b51fb294 100644
> > --- a/drivers/pinctrl/pinctrl-th1520.c
> > +++ b/drivers/pinctrl/pinctrl-th1520.c
> > @@ -803,11 +803,13 @@ 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);
> > - enum th1520_muxtype muxtype = (uintptr_t)func->data;
> > + enum th1520_muxtype muxtype;
> >
> > if (!func)
> > return -EINVAL;
> >
> > + muxtype = (uintptr_t)func->data;
> > +
> > return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
> > th1520_pad_muxdata(thp->desc.pins[gsel].drv_data),
> > muxtype);
>
> Otherwise looks good to me. With the change to short log:
>
> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
The patch sent by another patch submitter has already been
applied for this issue.
https://lore.kernel.org/all/20241016155655.334518-1-colin.i.king@gmail.com/
> thanks,
> -- Shuah
>
Thanks,
Everest K.C.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-17 2:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-16 13:42 [PATCH][next] pinctrl: th1520: Dereference pointer only after NULL check Everest K.C.
2024-10-16 21:00 ` Shuah Khan
2024-10-17 2:54 ` Everest K.C.
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).