linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe()
@ 2020-12-04  8:31 Zhang Changzhong
  2020-12-04 10:09 ` Paul Cercueil
  2020-12-05 14:00 ` Krzysztof Kozlowski
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Changzhong @ 2020-12-04  8:31 UTC (permalink / raw)
  To: Paul Cercueil, Krzysztof Kozlowski, Zubair Lutfullah Kakakhel,
	Greg Kroah-Hartman, Alex Smith
  Cc: Zhang Changzhong, linux-kernel

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\|platform_get_resource_byname\)(pdev, t,
n);
+ if (!res)
+   return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);

Fixes: 911a88829725 ("memory: jz4780-nemc: driver for the NEMC on JZ4780 SoCs")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
 drivers/memory/jz4780-nemc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/memory/jz4780-nemc.c b/drivers/memory/jz4780-nemc.c
index 3ec5cb0..465ea92 100644
--- a/drivers/memory/jz4780-nemc.c
+++ b/drivers/memory/jz4780-nemc.c
@@ -291,6 +291,8 @@ static int jz4780_nemc_probe(struct platform_device *pdev)
 	nemc->dev = dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 
 	/*
 	 * The driver currently only uses the registers up to offset
-- 
2.9.5


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

* Re: [PATCH] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe()
  2020-12-04  8:31 [PATCH] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe() Zhang Changzhong
@ 2020-12-04 10:09 ` Paul Cercueil
  2020-12-05 14:00 ` Krzysztof Kozlowski
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Cercueil @ 2020-12-04 10:09 UTC (permalink / raw)
  To: Zhang Changzhong
  Cc: Krzysztof Kozlowski, Zubair Lutfullah Kakakhel,
	Greg Kroah-Hartman, Alex Smith, linux-kernel

Hi Zhang,

Le ven. 4 déc. 2020 à 16:31, Zhang Changzhong 
<zhangchangzhong@huawei.com> a écrit :
> 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\|platform_get_resource_byname\)(pdev, t,
> n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
> 
> Fixes: 911a88829725 ("memory: jz4780-nemc: driver for the NEMC on 
> JZ4780 SoCs")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>

Acked-by: Paul Cercueil <paul@crapouillou.net>

Cheers,
-Paul

> ---
>  drivers/memory/jz4780-nemc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/memory/jz4780-nemc.c 
> b/drivers/memory/jz4780-nemc.c
> index 3ec5cb0..465ea92 100644
> --- a/drivers/memory/jz4780-nemc.c
> +++ b/drivers/memory/jz4780-nemc.c
> @@ -291,6 +291,8 @@ static int jz4780_nemc_probe(struct 
> platform_device *pdev)
>  	nemc->dev = dev;
> 
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
> 
>  	/*
>  	 * The driver currently only uses the registers up to offset
> --
> 2.9.5
> 



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

* Re: [PATCH] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe()
  2020-12-04  8:31 [PATCH] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe() Zhang Changzhong
  2020-12-04 10:09 ` Paul Cercueil
@ 2020-12-05 14:00 ` Krzysztof Kozlowski
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2020-12-05 14:00 UTC (permalink / raw)
  To: Alex Smith, Paul Cercueil, Zhang Changzhong, Greg Kroah-Hartman,
	Zubair Lutfullah Kakakhel
  Cc: Krzysztof Kozlowski, linux-kernel

On Fri, 4 Dec 2020 16:31:57 +0800, Zhang Changzhong wrote:
> 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;
> @@
> 
> [...]

Applied, thanks!

[1/1] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe()
      commit: 4bfa07300b9334b487ed4f3d4901c35ebb31b7ca

Best regards,
-- 
Krzysztof Kozlowski <krzk@kernel.org>

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

end of thread, other threads:[~2020-12-05 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04  8:31 [PATCH] memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe() Zhang Changzhong
2020-12-04 10:09 ` Paul Cercueil
2020-12-05 14:00 ` Krzysztof Kozlowski

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).