Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751441AbcDRBM3 (ORCPT ); Sun, 17 Apr 2016 21:12:29 -0400 Received: from mleia.com ([178.79.152.223]:43416 "EHLO mail.mleia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbcDRBM2 (ORCPT ); Sun, 17 Apr 2016 21:12:28 -0400 Subject: Re: [PATCH v2] misc: sram: fix check of devm_ioremap*() return value To: Greg Kroah-Hartman References: <1458701565-10722-1-git-send-email-vz@mleia.com> Cc: Arnd Bergmann , linux-kernel@vger.kernel.org From: Vladimir Zapolskiy Message-ID: <57143472.8080100@mleia.com> Date: Mon, 18 Apr 2016 04:12:18 +0300 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Icedove/38.5.0 MIME-Version: 1.0 In-Reply-To: <1458701565-10722-1-git-send-email-vz@mleia.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-49551924 X-CRM114-CacheID: sfid-20160418_021742_501558_CF021E0C X-CRM114-Status: GOOD ( 23.94 ) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1591 Lines: 46 Hi Greg, On 23.03.2016 04:52, Vladimir Zapolskiy wrote: > Both devm_ioremap() and devm_ioremap_wc() functions return either > a pointer to valid iomem region or NULL, check for IS_ERR() is improper > and may result in oops on error path. Now on error -ENOMEM is returned. > > Fixes: 0ab163ad1ea0 ("misc: sram: switch to ioremap_wc from ioremap") > Signed-off-by: Vladimir Zapolskiy > --- > I add Fixes: tag for reference, but unfortunately the change can not > be cleanly applied to kernel versions liable to the problem. > > Changes from v1 to v2: > - had to rebase on top of eb43e023130b ("misc: sram: add optional ioremap without write combining") > - slightly reworded the commit message and subject > > v1 of the change: https://lkml.org/lkml/2016/3/6/202 > this is a trivial fix of a potential NULL pointer dereference, do you have any review comments? > drivers/misc/sram.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c > index 69cdabe..f84b53d 100644 > --- a/drivers/misc/sram.c > +++ b/drivers/misc/sram.c > @@ -364,8 +364,8 @@ static int sram_probe(struct platform_device *pdev) > sram->virt_base = devm_ioremap(sram->dev, res->start, size); > else > sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size); > - if (IS_ERR(sram->virt_base)) > - return PTR_ERR(sram->virt_base); > + if (!sram->virt_base) > + return -ENOMEM; > > sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), > NUMA_NO_NODE, NULL); > -- With best wishes, Vladimir