Linux-Clk Archive on lore.kernel.org
 help / Atom feed
* [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe()
@ 2018-12-18  6:43 Wei Yongjun
  2018-12-18  9:48 ` Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Wei Yongjun @ 2018-12-18  6:43 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Michael Turquette, Stephen Boyd, Aisheng Dong
  Cc: Wei Yongjun, linux-arm-kernel, linux-clk, kernel-janitors

platform_get_resource() may fail and return NULL, so we should
better check it's return value to avoid a NULL pointer dereference
a bit later in the code.

This is detected by Coccinelle semantic patch.

@@
expression pdev, res, n, t, e, e1, e2;
@@

res = platform_get_resource(pdev, t, n);
+ if (!res)
+   return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);

Fixes: 1e3121bfe51a ("clk: imx: add imx8qxp lpcg driver")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/clk/imx/clk-imx8qxp-lpcg.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clk/imx/clk-imx8qxp-lpcg.c b/drivers/clk/imx/clk-imx8qxp-lpcg.c
index dcae1dd..8f241a4 100644
--- a/drivers/clk/imx/clk-imx8qxp-lpcg.c
+++ b/drivers/clk/imx/clk-imx8qxp-lpcg.c
@@ -169,6 +169,8 @@ static int imx8qxp_lpcg_clk_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!base)
 		return -ENOMEM;




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe()
  2018-12-18  6:43 [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe() Wei Yongjun
@ 2018-12-18  9:48 ` Fabio Estevam
  2018-12-18 14:16   ` Aisheng Dong
  2018-12-18 14:12 ` Aisheng Dong
  2019-01-09 18:35 ` Stephen Boyd
  2 siblings, 1 reply; 5+ messages in thread
From: Fabio Estevam @ 2018-12-18  9:48 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Michael Turquette, Stephen Boyd, Aisheng Dong,
	kernel-janitors, linux-clk,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

Hi Wei,

On Tue, Dec 18, 2018 at 4:36 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:

>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +       if (!res)
> +               return -EINVAL;
>         base = devm_ioremap(dev, res->start, resource_size(res));

Wouldn't it be better to use devm_ioremap_resource(), which does the NULL check?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe()
  2018-12-18  6:43 [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe() Wei Yongjun
  2018-12-18  9:48 ` Fabio Estevam
@ 2018-12-18 14:12 ` Aisheng Dong
  2019-01-09 18:35 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Aisheng Dong @ 2018-12-18 14:12 UTC (permalink / raw)
  To: Wei Yongjun, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, dl-linux-imx, Michael Turquette, Stephen Boyd
  Cc: linux-arm-kernel, linux-clk, kernel-janitors

> -----Original Message-----
> From: Wei Yongjun [mailto:weiyongjun1@huawei.com]
> Sent: Tuesday, December 18, 2018 2:43 PM
[...]
> platform_get_resource() may fail and return NULL, so we should better check
> it's return value to avoid a NULL pointer dereference a bit later in the code.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = platform_get_resource(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Fixes: 1e3121bfe51a ("clk: imx: add imx8qxp lpcg driver")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>

Thanks for reporting this.

Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

Regards
Dong Aisheng

> ---
>  drivers/clk/imx/clk-imx8qxp-lpcg.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/clk/imx/clk-imx8qxp-lpcg.c
> b/drivers/clk/imx/clk-imx8qxp-lpcg.c
> index dcae1dd..8f241a4 100644
> --- a/drivers/clk/imx/clk-imx8qxp-lpcg.c
> +++ b/drivers/clk/imx/clk-imx8qxp-lpcg.c
> @@ -169,6 +169,8 @@ static int imx8qxp_lpcg_clk_probe(struct
> platform_device *pdev)
>  		return -ENODEV;
> 
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
>  	base = devm_ioremap(dev, res->start, resource_size(res));
>  	if (!base)
>  		return -ENOMEM;
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe()
  2018-12-18  9:48 ` Fabio Estevam
@ 2018-12-18 14:16   ` Aisheng Dong
  0 siblings, 0 replies; 5+ messages in thread
From: Aisheng Dong @ 2018-12-18 14:16 UTC (permalink / raw)
  To: Fabio Estevam, Wei Yongjun
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, Michael Turquette, Stephen Boyd, kernel-janitors,
	linux-clk,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

> -----Original Message-----
> From: Fabio Estevam [mailto:festevam@gmail.com]
> Hi Wei,
> 
> On Tue, Dec 18, 2018 at 4:36 AM Wei Yongjun <weiyongjun1@huawei.com>
> wrote:
> 
> >         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > +       if (!res)
> > +               return -EINVAL;
> >         base = devm_ioremap(dev, res->start, resource_size(res));
> 
> Wouldn't it be better to use devm_ioremap_resource(), which does the NULL
> check?

No, devm_ioremap_resource will call request_mem_region which we don't want
as LPCG memory space may overlap with other modules within the same SS.

This is something like the syscon device does:
drivers/mfd/syscon.c.

Regards
Dong Aisheng

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe()
  2018-12-18  6:43 [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe() Wei Yongjun
  2018-12-18  9:48 ` Fabio Estevam
  2018-12-18 14:12 ` Aisheng Dong
@ 2019-01-09 18:35 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2019-01-09 18:35 UTC (permalink / raw)
  To: Aisheng Dong, Fabio Estevam, Michael Turquette, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Wei Yongjun
  Cc: Wei Yongjun, linux-arm-kernel, linux-clk, kernel-janitors

Quoting Wei Yongjun (2018-12-17 22:43:09)
> platform_get_resource() may fail and return NULL, so we should
> better check it's return value to avoid a NULL pointer dereference
> a bit later in the code.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = platform_get_resource(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Fixes: 1e3121bfe51a ("clk: imx: add imx8qxp lpcg driver")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---

Applied to clk-fixes


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-18  6:43 [PATCH -next] clk: imx: fix potential NULL dereference in imx8qxp_lpcg_clk_probe() Wei Yongjun
2018-12-18  9:48 ` Fabio Estevam
2018-12-18 14:16   ` Aisheng Dong
2018-12-18 14:12 ` Aisheng Dong
2019-01-09 18:35 ` Stephen Boyd

Linux-Clk Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-clk/0 linux-clk/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-clk linux-clk/ https://lore.kernel.org/linux-clk \
		linux-clk@vger.kernel.org linux-clk@archiver.kernel.org
	public-inbox-index linux-clk


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-clk


AGPL code for this site: git clone https://public-inbox.org/ public-inbox