Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753798AbcLKTPr (ORCPT ); Sun, 11 Dec 2016 14:15:47 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:33994 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753457AbcLKTPq (ORCPT ); Sun, 11 Dec 2016 14:15:46 -0500 Subject: Re: [V1] 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: <1481479310-2698-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: Date: Sun, 11 Dec 2016 20:15:39 +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: <1481479310-2698-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: 1099 Lines: 38 On 12/11/2016 07:01 PM, 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 | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c > index b833e6c..013b5b9 100644 > --- a/drivers/mtd/devices/docg3.c > +++ b/drivers/mtd/devices/docg3.c > @@ -2083,9 +2083,12 @@ 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) > + return ret; I think return -ENOMEM right away won't hurt here. Also, dev_err() explaining the failure would be nice to add. Thanks! > cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS, > GFP_KERNEL); > if (!cascade) > -- Best regards, Marek Vasut