From patchwork Thu Feb 27 13:34:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 11408729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D52B14D5 for ; Thu, 27 Feb 2020 14:39:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71F1424656 for ; Thu, 27 Feb 2020 14:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582814389; bh=KNL8q96VW054YfXBZfeHGlfLCZJ5LleWzR+KoB/9j4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hQSPmbab57ucdr71BPj7HW5XSLI8ikgzL6o8bnHdIzyo8JCU5k6TqZwp2LaUv4Afz gEOXmgpyBLPX0fqd4xt4mKthXzGUUV6npyCFVrxvWoipK1cqnbyaMvAEjAWYLR/u7M FEA221Kj8tC0fy9d15EnRtTR1YcTd3vH667rjtYs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731506AbgB0Nya (ORCPT ); Thu, 27 Feb 2020 08:54:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:54564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731851AbgB0Ny2 (ORCPT ); Thu, 27 Feb 2020 08:54:28 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7CB52469D; Thu, 27 Feb 2020 13:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811668; bh=KNL8q96VW054YfXBZfeHGlfLCZJ5LleWzR+KoB/9j4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bFxhHv0quYoHEaLY5V8FFJAvY3Y8FO4rFszpTH/cJQXCObt8c03bwAkn/XmCZw6o7 qrYFaPPsN+KGxl86NX4yBMArisgUI0Cb10fy2yoAMved8eHuBF3O/8HdQdSzWhRXvG /wHcNoPLlwM/3kJJNsM7naglh2PvNlX2g+mS7/rQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tiezhu Yang , Paul Burton , Ralf Baechle , Huacai Chen , Jiaxun Yang , linux-mips@vger.kernel.org, Sasha Levin Subject: [PATCH 4.14 055/237] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Date: Thu, 27 Feb 2020 14:34:29 +0100 Message-Id: <20200227132300.901186917@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132255.285644406@linuxfoundation.org> References: <20200227132255.285644406@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Tiezhu Yang [ 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 Signed-off-by: Paul Burton Cc: Ralf Baechle Cc: Huacai Chen Cc: Jiaxun Yang Cc: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Sasha Levin --- arch/mips/loongson64/loongson-3/platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/mips/loongson64/loongson-3/platform.c b/arch/mips/loongson64/loongson-3/platform.c index 25a97cc0ee336..0db4cc3196ebd 100644 --- a/arch/mips/loongson64/loongson-3/platform.c +++ b/arch/mips/loongson64/loongson-3/platform.c @@ -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];