Linux-MIPS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init()
@ 2020-01-10  1:30 Tiezhu Yang
  2020-01-13 19:10 ` Paul Burton
  0 siblings, 1 reply; 2+ messages in thread
From: Tiezhu Yang @ 2020-01-10  1:30 UTC (permalink / raw)
  To: Paul Burton, Ralf Baechle, Huacai Chen, Jiaxun Yang
  Cc: linux-mips, linux-kernel

If kzalloc fails, it should return -ENOMEM, otherwise may trigger a NULL
pointer dereference.

Fixes: 3adeb2566b9b ("MIPS: Loongson: Improve LEFI firmware interface")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/mips/loongson64/platform.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/mips/loongson64/platform.c b/arch/mips/loongson64/platform.c
index 13f3404..9674ae1 100644
--- a/arch/mips/loongson64/platform.c
+++ b/arch/mips/loongson64/platform.c
@@ -27,6 +27,9 @@ static int __init loongson3_platform_init(void)
 			continue;
 
 		pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
+		if (!pdev)
+			return -ENOMEM;
+
 		pdev->name = loongson_sysconf.sensors[i].name;
 		pdev->id = loongson_sysconf.sensors[i].id;
 		pdev->dev.platform_data = &loongson_sysconf.sensors[i];
-- 
2.1.0


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

* Re: [PATCH] MIPS: Loongson: Fix potential NULL dereference in  loongson3_platform_init()
  2020-01-10  1:30 [PATCH] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Tiezhu Yang
@ 2020-01-13 19:10 ` Paul Burton
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Burton @ 2020-01-13 19:10 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Paul Burton, Ralf Baechle, Huacai Chen, Jiaxun Yang, linux-mips,
	linux-kernel, linux-mips

Hello,

Tiezhu Yang wrote:
> If kzalloc fails, it should return -ENOMEM, otherwise may trigger a NULL
> pointer dereference.

Applied to mips-next.

> commit 72d052e28d1d
> https://git.kernel.org/mips/c/72d052e28d1d
> 
> Fixes: 3adeb2566b9b ("MIPS: Loongson: Improve LEFI firmware interface")
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> Signed-off-by: Paul Burton <paulburton@kernel.org>

Thanks,
    Paul

[ This message was auto-generated; if you believe anything is incorrect
  then please email paulburton@kernel.org to report it. ]

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10  1:30 [PATCH] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Tiezhu Yang
2020-01-13 19:10 ` Paul Burton

Linux-MIPS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mips/0 linux-mips/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-mips linux-mips/ https://lore.kernel.org/linux-mips \
		linux-mips@vger.kernel.org
	public-inbox-index linux-mips

Example config snippet for mirrors

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


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