Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754040AbcLLC70 (ORCPT ); Sun, 11 Dec 2016 21:59:26 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35518 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751613AbcLLC7Y (ORCPT ); Sun, 11 Dec 2016 21:59:24 -0500 Subject: Re: [V1] mtd: devices: docg3:- Handle return value of devm_ioremap. To: Marek Vasut , 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: arvind Yadav Message-ID: Date: Mon, 12 Dec 2016 08:29:19 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1305 Lines: 40 Yes, We are returning -ENOMEM, ret is initialized to -ENOMEM. As per your concern, I have added dev_err failure message. Thanks -Arvind On Monday 12 December 2016 12:45 AM, Marek Vasut wrote: > 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) >> >