Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp954462imm; Thu, 4 Oct 2018 06:09:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV61aZH6D+VhfbS60DbTWrEUOpX1IQ4uTNdmLrTXB6NU5POqFtKQW+b7KyOJWGwbeXwEwpf4d X-Received: by 2002:a17:902:6546:: with SMTP id d6-v6mr6590937pln.139.1538658574575; Thu, 04 Oct 2018 06:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538658574; cv=none; d=google.com; s=arc-20160816; b=urNAtfnhnCmb3alBtdNLFQPfO21l+PuDzZfGfF4QKt5fmtwz/1V6CZAvicjQh48syz Um5T5Pt6/XX1FdY+6Cq08Lw/SBrThxcO06l/HY1Nkf6u8nNi11S2fD76gZw8GNvhWXUU hZ96yTmO+3bjreTlBhGNjGxQThnn5eMRioZQNs/ZRdOLgw+Bp4HUSf2LdSt2JeDt5ZIl 3dHWkjpcVKlRmIyd/HGLLQTCNL8Fiq/l/sjLcJTN9wAl5jorjW/BPOB3aCU5Iq7e4p1a Ej6TgiGN/cVKwfT380j2XfGCu7lCwt5+XCJ5A+KXBsqTM4GUntcWY+CSfF93TXQoR9M4 w7lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=Ai02fUZvgrCwtojcYcWDEtyyZTG8eW+qL9Y2eSCaCVc=; b=0m1PurGyoMU86XANCjMw6R7NtejC4JUyzfmFSH3nwYdz9EiigtLu1n3dQQknufJg/h FOKYyvLnsG/mmuDGxBsqHAFIrVeep0zhtgCClhkMLEBeMpwA3T3+VWqoPg/w1IK5RLoY tvUf8fVxUyxfo4+zKMCSLB4rOvKE8HrV9NxiSdHd/F7XVns/k37HCMNMUeQS5VgTU0w4 E2B8d6fgaL1E57xTrSabxjXscXhkgCAX4ayrYD1d6pffZP7MiypUDQ3TWiM4e8RwOqne 4bpMyiRcKMGGYFkyPBOBssqFbfZtnLcczUdxPKUYCG2kiBsojp/kn1/4rLSvTqo/TQ6E kOlw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14-v6si4646328pfi.184.2018.10.04.06.09.18; Thu, 04 Oct 2018 06:09:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbeJDUCR (ORCPT + 99 others); Thu, 4 Oct 2018 16:02:17 -0400 Received: from mail.bootlin.com ([62.4.15.54]:38089 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727367AbeJDUCP (ORCPT ); Thu, 4 Oct 2018 16:02:15 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 42254207CC; Thu, 4 Oct 2018 15:09:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-28-153.w90-88.abo.wanadoo.fr [90.88.148.153]) by mail.bootlin.com (Postfix) with ESMTPSA id EEDD0207C4; Thu, 4 Oct 2018 15:08:49 +0200 (CEST) Date: Thu, 4 Oct 2018 15:08:50 +0200 From: Boris Brezillon To: Ricardo Ribalda Delgado Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, open list Subject: Re: [PATCH v6 01/10] mtd: physmap_of: Release resources on error Message-ID: <20181004150850.780f6d21@bbrezillon> In-Reply-To: <20181004130110.8496-1-ricardo.ribalda@gmail.com> References: <20181004130110.8496-1-ricardo.ribalda@gmail.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ricardo, On Thu, 4 Oct 2018 15:01:01 +0200 Ricardo Ribalda Delgado wrote: > During probe, if there was an error the memory region and the memory > map were not properly released. > > This can lead a system unusable if deferred probe is in use. > > Signed-off-by: Ricardo Ribalda Delgado > --- > drivers/mtd/maps/physmap_of_core.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/mtd/maps/physmap_of_core.c b/drivers/mtd/maps/physmap_of_core.c > index 4129535b8e46..062add8b3a6e 100644 > --- a/drivers/mtd/maps/physmap_of_core.c > +++ b/drivers/mtd/maps/physmap_of_core.c > @@ -241,10 +241,10 @@ static int of_flash_probe(struct platform_device *dev) > > err = of_flash_probe_gemini(dev, dp, &info->list[i].map); > if (err) > - goto err_out; > + goto err_out_release; > err = of_flash_probe_versatile(dev, dp, &info->list[i].map); > if (err) > - goto err_out; > + goto err_out_release; > > err = -ENOMEM; > info->list[i].map.virt = ioremap(info->list[i].map.phys, > @@ -252,7 +252,7 @@ static int of_flash_probe(struct platform_device *dev) > if (!info->list[i].map.virt) { > dev_err(&dev->dev, "Failed to ioremap() flash" > " region\n"); > - goto err_out; > + goto err_out_release; > } > > simple_map_init(&info->list[i].map); > @@ -290,7 +290,7 @@ static int of_flash_probe(struct platform_device *dev) > err = -ENXIO; > if (!info->list[i].mtd) { > dev_err(&dev->dev, "do_map_probe() failed\n"); > - goto err_out; > + goto err_out_iounmap; > } else { > info->list_size++; > } > @@ -329,6 +329,10 @@ static int of_flash_probe(struct platform_device *dev) > > return 0; > > +err_out_iounmap: > + iounmap(info->list[i].map.virt); > +err_out_release: > + release_mem_region(res.start, resource_size(&res)); > err_out: > kfree(mtd_list); > err_flash_remove: Please fix that using devm_ioremap_resource() instead. Thanks, Boris