diff mbox series

MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init()

Message ID 1578619842-926-1-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Mainlined
Commit 72d052e28d1d2363f9107be63ef3a3afdea6143c
Delegated to: Paul Burton
Headers show
Series MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() | expand

Commit Message

Tiezhu Yang Jan. 10, 2020, 1:30 a.m. UTC
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(+)

Comments

Paul Burton Jan. 13, 2020, 7:10 p.m. UTC | #1
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. ]
diff mbox series

Patch

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];