From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757909AbcAYTPY (ORCPT ); Mon, 25 Jan 2016 14:15:24 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:64869 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757575AbcAYTPV (ORCPT ); Mon, 25 Jan 2016 14:15:21 -0500 Date: Mon, 25 Jan 2016 19:15:49 +0000 From: "Maciej W. Rozycki" To: Brian Norris CC: =?ISO-8859-2?Q?Rafa=B3_Mi=B3ecki?= , , Javier Martinez Canillas , Linux Kernel Mailing List , Fengguang Wu , Michael Ellerman , Luis de Bethencourt , Jeremy Kerr , Neelesh Gupta , David Woodhouse , Cyril Bur , Ralf Baechle Subject: Re: [PATCH] mtd: bcm47xxsflash: use ioremap_cachable() instead of KSEG0ADDR() In-Reply-To: <20160125040459.GA4386@localhost> Message-ID: References: <1452991370-20121-1-git-send-email-zajec5@gmail.com> <20160125040459.GA4386@localhost> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [10.100.200.15] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Jan 2016, Brian Norris wrote: > > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > > + if (!res) { > > > + dev_err(dev, "invalid resource\n"); > > > + return -EINVAL; > > > + } > > > + if (!devm_request_mem_region(dev, res->start, resource_size(res), > > > + res->name)) { > > > + dev_err(dev, "can't request region for resource %pR\n", res); > > > + return -EBUSY; > > > + } > > > + b47s->window = ioremap_cachable(res->start, resource_size(res)); > > > + if (!b47s->window) { > > > + dev_err(dev, "ioremap failed for resource %pR\n", res); > > > > You need to call `devm_release_mem_region' in this case. > > No he doesn't. devm_* functions automatically release their resources > when either the device is removed, or the probe() fails. So the whole > point is that we don't have to explicitly manage the error case. Why does `devm_ioremap_resource' (in lib/devres.c) do that manually then? dest_ptr = devm_ioremap(dev, res->start, size); if (!dest_ptr) { dev_err(dev, "ioremap failed for resource %pR\n", res); devm_release_mem_region(dev, res->start, size); dest_ptr = IOMEM_ERR_PTR(-ENOMEM); } Is this an oversight or was it a deliberate design decision? > But...since he's not using a devm_* version of ioremap (there isn't one > for ioremap_cachable()), we actually need to add an iounmap() for the > case where mtd_device_parse_register() fails. If we fix that one, I can > apply this. As from 4.5-rc1 we now have `ioremap_cache' available for MIPS as well (thanks, Ralf, for a quick action on that!), so you can use that instead to make your code generic. > Thanks for the review! You're welcome! :) Maciej