Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932111AbcLLDAQ (ORCPT ); Sun, 11 Dec 2016 22:00:16 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36813 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753790AbcLLDAP (ORCPT ); Sun, 11 Dec 2016 22:00:15 -0500 From: Arvind Yadav To: robert.jarzmik@free.fr, dwmw2@infradead.org, computersforpeace@gmail.com, boris.brezillon@free-electrons.com, marek.vasut@gmail.com, richard@nod.at, cyrille.pitchen@atmel.com Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Date: Mon, 12 Dec 2016 08:30:04 +0530 Message-Id: <1481511604-6116-1-git-send-email-arvind.yadav.cs@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 914 Lines: 30 Here, If devm_ioremap will fail. It will return NULL. Kernel can run into a NULL-pointer dereference. Signed-off-by: Arvind Yadav --- drivers/mtd/devices/docg3.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index b833e6c..ffe3db0 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -2083,9 +2083,14 @@ static int __init docg3_probe(struct platform_device *pdev) dev_err(dev, "No I/O memory resource defined\n"); return ret; } - base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE); ret = -ENOMEM; + base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE); + if (!base) { + dev_err(dev, "failed to map I/O memory\n"); + return ret; + } + cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS, GFP_KERNEL); if (!cascade) -- 2.7.4