Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754121AbcLLEKd (ORCPT ); Sun, 11 Dec 2016 23:10:33 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34462 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751689AbcLLEKc (ORCPT ); Sun, 11 Dec 2016 23:10:32 -0500 Subject: Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. To: Arvind Yadav , robert.jarzmik@free.fr, dwmw2@infradead.org, computersforpeace@gmail.com, boris.brezillon@free-electrons.com, richard@nod.at, cyrille.pitchen@atmel.com References: <1481511604-6116-1-git-send-email-arvind.yadav.cs@gmail.com> Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org From: Marek Vasut Message-ID: <0b23dbab-3454-2505-d411-41dbfd3d3f3c@gmail.com> Date: Mon, 12 Dec 2016 05:10:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <1481511604-6116-1-git-send-email-arvind.yadav.cs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1131 Lines: 41 On 12/12/2016 04:00 AM, Arvind Yadav wrote: > 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; Um, return -ENOMEM right away ? Otherwise, Acked-by: Marek Vasut > + } > + > cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS, > GFP_KERNEL); > if (!cascade) > -- Best regards, Marek Vasut