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: 3245861 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 87AB49F3AE for ; Wed, 27 Nov 2013 02:17:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 839C72052D for ; Wed, 27 Nov 2013 02:17:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A4EA20412 for ; Wed, 27 Nov 2013 02:17:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752768Ab3K0CRo (ORCPT ); Tue, 26 Nov 2013 21:17:44 -0500 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:48129 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752705Ab3K0CRn (ORCPT ); Tue, 26 Nov 2013 21:17:43 -0500 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 Cc: 'Christopher Li' , linux-sparse@vger.kernel.org, 'Joe Perches' , 'Dan Carpenter' , 'Jason Gunthorpe' , 'Jason Cooper' , 'Thomas Petazzoni' , 'Bjorn Helgaas' , linux-pci@vger.kernel.org, 'Ezequiel Garcia' , linux-arm-kernel@lists.infradead.org, 'Axel Lin' , 'Julia Lawall' 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) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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;