Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1929265ybv; Fri, 14 Feb 2020 08:24:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxlCkVqE1RiB4uxd0Lb1eIkwnydijWk9XZz9zk1wEUjFATNXIYf6zUVS+PupMriZAecnRL4 X-Received: by 2002:a05:6830:1188:: with SMTP id u8mr2954842otq.274.1581697440751; Fri, 14 Feb 2020 08:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581697440; cv=none; d=google.com; s=arc-20160816; b=y2K0RYNnmoKu1Zi18Gw/R7FZFjpWTKTTAl+Az5Kr+jsanL3iw0VeHBQcxnMG1WTJJW 3wkZgIuQUrO+jJfLdO6xHv1cQj+EXY5eVOmrs3Jk/De2GKuxAhKzj6s/9i8DvWpD0rvX jRu0Yf7cNTLwzxc5pgxupq9VWGcG28U18+OlDY7h0y9yYYa/jSTrvEj3QSWqrHkBazfx b0p7B7mXahk6TI3QEKLOH0tYvno+eV2PozEp23aGd0W1XHwrr3xPZL3N7+bpC/HBQUsg poYxI6+pLZm6XvPQhi/1aEnmfZ8YJde8zuiT6rrTMG/TdnAx299S+aZFINDX1+kged4e ZRJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZvdGFZzzqJuDwEfOPVtOXuZ1CDL8FTXlRuu8d73xDTg=; b=iMlINKNpKqaX7Vy/M0FvCNJ76iGtSvtQyd8sA+DHNFIIOIIyM2IxGsKfRVmlHFoGCU KaR92fiYyMI3Gi/sI5EyGqa9pnlybYq1VUWcCNsyfBizarPFxQNqvfmhbun2wKMvlVVA mgvL9YdrVTmKYH2IIpDwg5sMvpfFytMLQ3U8Vuo9adPyWUlTidgBdebHbtfgMwTwlHgd 1c6yvLQobaDQV904r7a7vp4tZf+aLO00JMQZTIXEAxl++hzrUT0TFe3qNxGPT/GqGb6+ qns4ZUaGyGkv2xf9pxmJq0niJ9J4MF24X2BExkBPkU7ixdSsA1n6w4ndSXap7/SvLzG2 YgzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BuxFGYAY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4si3873815ots.107.2020.02.14.08.23.48; Fri, 14 Feb 2020 08:24:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BuxFGYAY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393333AbgBNQXF (ORCPT + 99 others); Fri, 14 Feb 2020 11:23:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:56614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393079AbgBNQVq (ORCPT ); Fri, 14 Feb 2020 11:21:46 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59AB8246BF; Fri, 14 Feb 2020 16:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697305; bh=KNL8q96VW054YfXBZfeHGlfLCZJ5LleWzR+KoB/9j4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BuxFGYAYjyP7ybq323UEzMEuTgl1m5ICFRLK2theYcftkEChrdA/VOm2LOU39gjuh dukJHaPEFd6+hNylFyfwWUi2RhAhFL4tTD/UzMsr2n+QYPaP0PwwYzeQ1txqBbM28N XrbpNxFUzSgZEHol9QYXHAflCcyrgYu+xKtUicis= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tiezhu Yang , Paul Burton , Ralf Baechle , Huacai Chen , Jiaxun Yang , linux-mips@vger.kernel.org, Sasha Levin Subject: [PATCH AUTOSEL 4.9 017/141] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Date: Fri, 14 Feb 2020 11:19:17 -0500 Message-Id: <20200214162122.19794-17-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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]; -- 2.20.1