From patchwork Wed Nov 27 02:17:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 3245881 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 48066C045B for ; Wed, 27 Nov 2013 02:18:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5419C20490 for ; Wed, 27 Nov 2013 02:18:22 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 53B8420412 for ; Wed, 27 Nov 2013 02:18:21 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VlUhh-0005hW-6c; Wed, 27 Nov 2013 02:18:13 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VlUhe-0006az-S3; Wed, 27 Nov 2013 02:18:10 +0000 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VlUha-0006aG-AZ for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2013 02:18:07 +0000 Received: from mfilter13-d.gandi.net (mfilter13-d.gandi.net [217.70.178.141]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id EF0AE17209B; Wed, 27 Nov 2013 03:17:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter13-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter13-d.gandi.net (mfilter13-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id XQ1ELG+eCNt4; Wed, 27 Nov 2013 03:17:38 +0100 (CET) X-Originating-IP: 50.43.14.201 Received: from leaf (static-50-43-14-201.bvtn.or.frontiernet.net [50.43.14.201]) (Authenticated sender: josh@joshtriplett.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id C38AC172094; Wed, 27 Nov 2013 03:17:32 +0100 (CET) Date: Tue, 26 Nov 2013 18:17:30 -0800 From: Josh Triplett To: Jingoo Han Subject: [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer Message-ID: <20131127021730.GA14138@leaf> References: <001001ceb816$5d1aecc0$1750c640$%han@samsung.com> <20131125200256.GA7316@obsidianresearch.com> <001101ceea68$cb486220$61d92660$%han@samsung.com> <20131126180930.GC19852@obsidianresearch.com> <000101ceeb14$480fee80$d82fcb80$%han@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <000101ceeb14$480fee80$d82fcb80$%han@samsung.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131126_211806_734820_904D8159 X-CRM114-Status: GOOD ( 23.17 ) X-Spam-Score: -1.9 (-) Cc: 'Thomas Petazzoni' , 'Axel Lin' , 'Jason Cooper' , 'Julia Lawall' , linux-pci@vger.kernel.org, 'Christopher Li' , 'Jason Gunthorpe' , 'Bjorn Helgaas' , linux-sparse@vger.kernel.org, linux-arm-kernel@lists.infradead.org, 'Ezequiel Garcia' , 'Joe Perches' , 'Dan Carpenter' X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Nov 27, 2013 at 10:59:18AM +0900, Jingoo Han wrote: > On Wednesday, November 27, 2013 3:10 AM, Jason Gunthorpe wrote: > > On Tue, Nov 26, 2013 at 02:31:44PM +0900, Jingoo Han wrote: > > > Previously, I sent the patch in order to fix sparse warning as below: > > > How about this? > > > > > > static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, > > > struct device_node *np, struct mvebu_pcie_port *port) > > > { > > > struct resource regs; > > > int ret = 0; > > > > > > ret = of_address_to_resource(np, 0, ®s); > > > if (ret) > > > - return ERR_PTR(ret); > > > + return (void __iomem *)ERR_PTR(ret); > > > > You should probably ask the sparse folks for guidance 'git grep > > iomem.*ERR_PTR' returns nothing, so this isn't an established pattern. > > > > It seems like sparse should know that ERR_PTR functions can work with > > any pointer no matter the type? IS_ERR_PTR will have the same problem > > with implicitly dropping the iomem tag. > > +cc Christopher Li, sparse mailing-list, Joe Perches, Dan Carpenter, > Axel Lin, Julia Lawall, > > Hi All, > > I have some questions about handling sparse warning. > > Currently, the following sparse warning happens > at Marvell Armada PCIe driver. > > drivers/pci/host/pci-mvebu.c:743:31: warning: incorrect type in return expression (different address spaces) > drivers/pci/host/pci-mvebu.c:743:31: expected void [noderef] * > drivers/pci/host/pci-mvebu.c:743:31: got void * > > mvebu_pcie_map_registers() returns ERR_PTR(ret), > however ERR_PTR() returns (void *), not (void __iomem *). Given that PTR_ERR, IS_ERR, and IS_ERR_OR_NULL currently accept any kind of pointer (by using __force), it does make sense for ERR_PTR to return any kind of pointer. There's no built-in way to do this, but we could add an ERR_PTR_iomem that has the appropriate return type. Here's a possible patch; please test in your particular use case and see if it works for you. (You can apply this patch from this mail via git am --scissors.) ---8<--- From: Josh Triplett Subject: [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer PTR_ERR, IS_ERR, and IS_ERR_OR_NULL already accept any type of pointer by using __force; ERR_PTR should similarly be able to return any type of pointer. Provide an ERR_PTR_IO to return an error pointer in __iomem. Signed-off-by: Josh Triplett --- include/linux/err.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/err.h b/include/linux/err.h index 15f92e0..d64215b 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -24,6 +24,11 @@ static inline void * __must_check ERR_PTR(long error) return (void *) error; } +static inline __iomem void * __must_check ERR_PTR_IO(long error) +{ + return (__force __iomem void *) error; +} + static inline long __must_check PTR_ERR(__force const void *ptr) { return (long) ptr;