]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init()
authorTiezhu Yang <yangtiezhu@loongson.cn>
Fri, 10 Jan 2020 01:30:42 +0000 (09:30 +0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 7 Apr 2020 08:49:52 +0000 (10:49 +0200)
BugLink: https://bugs.launchpad.net/bugs/1867837
[ Upstream commit 72d052e28d1d2363f9107be63ef3a3afdea6143c ]

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>
Signed-off-by: Paul Burton <paulburton@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/mips/loongson64/loongson-3/platform.c

index 25a97cc0ee33664f79f16e3ffb4d350a4b033dae..0db4cc3196ebdcc92b98791e139f652636b83c9f 100644 (file)
@@ -31,6 +31,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];