* [PATCH] soc: mediatek: Handle return of of_match_device function
@ 2018-02-01 11:00 Himanshu Jha
2018-02-01 11:04 ` Geert Uytterhoeven
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Himanshu Jha @ 2018-02-01 11:00 UTC (permalink / raw)
To: matthias.bgg
Cc: mars.cheng, weiyi.lu, ulf.hansson, kevin-cw.chen, sean.wang,
geert+renesas, linux-arm-kernel, linux-mediatek, linux-kernel,
Himanshu Jha
In scpsys_probe function, return value of of_match_device function which
returns null is dereferenced without checking. Therefore, add a check for
potential null dereference.
Detected by CoverityScan, CID#1424087 "Dereference null return value"
Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of scpsys_probe across all SoCs")
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
---
drivers/soc/mediatek/mtk-scpsys.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
index 435ce5e..6e7f196 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev)
int i, ret;
match = of_match_device(of_scpsys_match_tbl, &pdev->dev);
+ if (!match)
+ return -EINVAL;
+
soc = (const struct scp_soc_data *)match->data;
scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs,
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] soc: mediatek: Handle return of of_match_device function 2018-02-01 11:00 [PATCH] soc: mediatek: Handle return of of_match_device function Himanshu Jha @ 2018-02-01 11:04 ` Geert Uytterhoeven 2018-02-01 11:59 ` Alexandre Belloni 2018-02-01 15:02 ` Robin Murphy 2 siblings, 0 replies; 6+ messages in thread From: Geert Uytterhoeven @ 2018-02-01 11:04 UTC (permalink / raw) To: Himanshu Jha Cc: Matthias Brugger, mars.cheng, weiyi.lu, Ulf Hansson, kevin-cw.chen, sean.wang, Geert Uytterhoeven, linux-arm-kernel, linux-mediatek, Linux Kernel Mailing List Hi Himanshu, On Thu, Feb 1, 2018 at 12:00 PM, Himanshu Jha <himanshujha199640@gmail.com> wrote: > In scpsys_probe function, return value of of_match_device function which > returns null is dereferenced without checking. Therefore, add a check for > potential null dereference. > > Detected by CoverityScan, CID#1424087 "Dereference null return value" > > Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of scpsys_probe across all SoCs") > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> This is a false positive: as this is a pure-OF driver, scpsys_probe() is called if and only if a match was found in of_scpsys_match_tbl[]. > --- > drivers/soc/mediatek/mtk-scpsys.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c > index 435ce5e..6e7f196 100644 > --- a/drivers/soc/mediatek/mtk-scpsys.c > +++ b/drivers/soc/mediatek/mtk-scpsys.c > @@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev) > int i, ret; > > match = of_match_device(of_scpsys_match_tbl, &pdev->dev); > + if (!match) > + return -EINVAL; > + > soc = (const struct scp_soc_data *)match->data; > > scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] soc: mediatek: Handle return of of_match_device function 2018-02-01 11:00 [PATCH] soc: mediatek: Handle return of of_match_device function Himanshu Jha 2018-02-01 11:04 ` Geert Uytterhoeven @ 2018-02-01 11:59 ` Alexandre Belloni 2018-02-01 15:02 ` Robin Murphy 2 siblings, 0 replies; 6+ messages in thread From: Alexandre Belloni @ 2018-02-01 11:59 UTC (permalink / raw) To: Himanshu Jha Cc: matthias.bgg, ulf.hansson, weiyi.lu, geert+renesas, sean.wang, linux-kernel, kevin-cw.chen, mars.cheng, linux-mediatek, linux-arm-kernel On 01/02/2018 at 16:30:22 +0530, Himanshu Jha wrote: > In scpsys_probe function, return value of of_match_device function which > returns null is dereferenced without checking. Therefore, add a check for > potential null dereference. > > Detected by CoverityScan, CID#1424087 "Dereference null return value" > No, this will never happen as the only way to probe this device is to use device tree. > Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of scpsys_probe across all SoCs") > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> > --- > drivers/soc/mediatek/mtk-scpsys.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c > index 435ce5e..6e7f196 100644 > --- a/drivers/soc/mediatek/mtk-scpsys.c > +++ b/drivers/soc/mediatek/mtk-scpsys.c > @@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev) > int i, ret; > > match = of_match_device(of_scpsys_match_tbl, &pdev->dev); > + if (!match) > + return -EINVAL; > + > soc = (const struct scp_soc_data *)match->data; > > scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, > -- > 2.7.4 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel -- Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] soc: mediatek: Handle return of of_match_device function 2018-02-01 11:00 [PATCH] soc: mediatek: Handle return of of_match_device function Himanshu Jha 2018-02-01 11:04 ` Geert Uytterhoeven 2018-02-01 11:59 ` Alexandre Belloni @ 2018-02-01 15:02 ` Robin Murphy [not found] ` <b8265d37-0ef0-9d24-8ace-8fae7f67477d-5wv7dgnIgG8@public.gmane.org> 2 siblings, 1 reply; 6+ messages in thread From: Robin Murphy @ 2018-02-01 15:02 UTC (permalink / raw) To: Himanshu Jha, matthias.bgg Cc: ulf.hansson, weiyi.lu, geert+renesas, sean.wang, linux-kernel, kevin-cw.chen, mars.cheng, linux-mediatek, linux-arm-kernel On 01/02/18 11:00, Himanshu Jha wrote: > In scpsys_probe function, return value of of_match_device function which > returns null is dereferenced without checking. Therefore, add a check for > potential null dereference. > > Detected by CoverityScan, CID#1424087 "Dereference null return value" > > Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of scpsys_probe across all SoCs") > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> > --- > drivers/soc/mediatek/mtk-scpsys.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c > index 435ce5e..6e7f196 100644 > --- a/drivers/soc/mediatek/mtk-scpsys.c > +++ b/drivers/soc/mediatek/mtk-scpsys.c > @@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev) > int i, ret; > > match = of_match_device(of_scpsys_match_tbl, &pdev->dev); > + if (!match) > + return -EINVAL; > + > soc = (const struct scp_soc_data *)match->data; You could of course replace the whole sequence with an of_device_get_match_data() call, which happens to be inherently safe against the no-match case even when that *is* impossible by design. Robin. > > scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, > ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <b8265d37-0ef0-9d24-8ace-8fae7f67477d-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH] soc: mediatek: Handle return of of_match_device function [not found] ` <b8265d37-0ef0-9d24-8ace-8fae7f67477d-5wv7dgnIgG8@public.gmane.org> @ 2018-02-01 15:09 ` Geert Uytterhoeven 2018-02-01 15:16 ` Robin Murphy 0 siblings, 1 reply; 6+ messages in thread From: Geert Uytterhoeven @ 2018-02-01 15:09 UTC (permalink / raw) To: Robin Murphy Cc: Ulf Hansson, Weiyi Lu, Geert Uytterhoeven, sean.wang-NuS5LvNUpcJWk0Htik3J/w, Linux Kernel Mailing List, kevin-cw.chen-NuS5LvNUpcJWk0Htik3J/w, Cheng Mars, Himanshu Jha, Matthias Brugger, linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r On Thu, Feb 1, 2018 at 4:02 PM, Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> wrote: > On 01/02/18 11:00, Himanshu Jha wrote: >> In scpsys_probe function, return value of of_match_device function which >> returns null is dereferenced without checking. Therefore, add a check for >> potential null dereference. >> >> Detected by CoverityScan, CID#1424087 "Dereference null return value" >> >> Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of >> scpsys_probe across all SoCs") >> Signed-off-by: Himanshu Jha <himanshujha199640-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> --- >> drivers/soc/mediatek/mtk-scpsys.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/drivers/soc/mediatek/mtk-scpsys.c >> b/drivers/soc/mediatek/mtk-scpsys.c >> index 435ce5e..6e7f196 100644 >> --- a/drivers/soc/mediatek/mtk-scpsys.c >> +++ b/drivers/soc/mediatek/mtk-scpsys.c >> @@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev) >> int i, ret; >> match = of_match_device(of_scpsys_match_tbl, &pdev->dev); >> + if (!match) >> + return -EINVAL; >> + >> soc = (const struct scp_soc_data *)match->data; > > You could of course replace the whole sequence with an > of_device_get_match_data() call, which happens to be inherently safe against > the no-match case even when that *is* impossible by design. +1 >> scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, ... followed by the static analyser gang complaining we may dereference NULL pointer soc... Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] soc: mediatek: Handle return of of_match_device function 2018-02-01 15:09 ` Geert Uytterhoeven @ 2018-02-01 15:16 ` Robin Murphy 0 siblings, 0 replies; 6+ messages in thread From: Robin Murphy @ 2018-02-01 15:16 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Ulf Hansson, Weiyi Lu, Geert Uytterhoeven, sean.wang, Linux Kernel Mailing List, kevin-cw.chen, Cheng Mars, Himanshu Jha, Matthias Brugger, linux-mediatek, linux-arm-kernel On 01/02/18 15:09, Geert Uytterhoeven wrote: > On Thu, Feb 1, 2018 at 4:02 PM, Robin Murphy <robin.murphy@arm.com> wrote: >> On 01/02/18 11:00, Himanshu Jha wrote: >>> In scpsys_probe function, return value of of_match_device function which >>> returns null is dereferenced without checking. Therefore, add a check for >>> potential null dereference. >>> >>> Detected by CoverityScan, CID#1424087 "Dereference null return value" >>> >>> Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of >>> scpsys_probe across all SoCs") >>> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com> >>> --- >>> drivers/soc/mediatek/mtk-scpsys.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/drivers/soc/mediatek/mtk-scpsys.c >>> b/drivers/soc/mediatek/mtk-scpsys.c >>> index 435ce5e..6e7f196 100644 >>> --- a/drivers/soc/mediatek/mtk-scpsys.c >>> +++ b/drivers/soc/mediatek/mtk-scpsys.c >>> @@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev) >>> int i, ret; >>> match = of_match_device(of_scpsys_match_tbl, &pdev->dev); >>> + if (!match) >>> + return -EINVAL; >>> + >>> soc = (const struct scp_soc_data *)match->data; >> >> You could of course replace the whole sequence with an >> of_device_get_match_data() call, which happens to be inherently safe against >> the no-match case even when that *is* impossible by design. > > +1 > >>> scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, > > ... followed by the static analyser gang complaining we may dereference > NULL pointer soc... Well, if the static analysers can't track the provenance of dev->driver->of_match_table, let's keep ignoring them until they get cleverer :P Robin. > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-02-01 15:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-01 11:00 [PATCH] soc: mediatek: Handle return of of_match_device function Himanshu Jha
2018-02-01 11:04 ` Geert Uytterhoeven
2018-02-01 11:59 ` Alexandre Belloni
2018-02-01 15:02 ` Robin Murphy
[not found] ` <b8265d37-0ef0-9d24-8ace-8fae7f67477d-5wv7dgnIgG8@public.gmane.org>
2018-02-01 15:09 ` Geert Uytterhoeven
2018-02-01 15:16 ` Robin Murphy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox