From: Josh Triplett <josh@joshtriplett.org>
To: Jingoo Han <jg1.han@samsung.com>
Cc: 'Christopher Li' <sparse@chrisli.org>,
linux-sparse@vger.kernel.org, 'Joe Perches' <joe@perches.com>,
'Dan Carpenter' <dan.carpenter@oracle.com>,
'Jason Gunthorpe' <jgunthorpe@obsidianresearch.com>,
'Jason Cooper' <jason@lakedaemon.net>,
'Thomas Petazzoni' <thomas.petazzoni@free-electrons.com>,
'Bjorn Helgaas' <bhelgaas@google.com>,
linux-pci@vger.kernel.org,
'Ezequiel Garcia' <ezequiel.garcia@free-electrons.com>,
linux-arm-kernel@lists.infradead.org,
'Axel Lin' <axel.lin@ingics.com>,
'Julia Lawall' <julia.lawall@lip6.fr>
Subject: [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer
Date: Tue, 26 Nov 2013 18:17:30 -0800 [thread overview]
Message-ID: <20131127021730.GA14138@leaf> (raw)
In-Reply-To: <000101ceeb14$480fee80$d82fcb80$%han@samsung.com>
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] <asn:2>*
> 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 <josh@joshtriplett.org>
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 <josh@joshtriplett.org>
---
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;
--
1.8.4.4
WARNING: multiple messages have this Message-ID (diff)
From: josh@joshtriplett.org (Josh Triplett)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer
Date: Tue, 26 Nov 2013 18:17:30 -0800 [thread overview]
Message-ID: <20131127021730.GA14138@leaf> (raw)
In-Reply-To: <000101ceeb14$480fee80$d82fcb80$%han@samsung.com>
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] <asn:2>*
> 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 <josh@joshtriplett.org>
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 <josh@joshtriplett.org>
---
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;
--
1.8.4.4
next prev parent reply other threads:[~2013-11-27 2:17 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-17 5:25 [PATCH V2 1/3] PCI: tegra: add missing __iomem annotation Jingoo Han
2013-09-17 5:26 ` [PATCH V2 2/3] PCI: mvebu: make local functions static Jingoo Han
2013-09-17 5:27 ` [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation Jingoo Han
2013-09-17 17:42 ` Thomas Petazzoni
2013-09-23 2:27 ` Jingoo Han
2013-09-23 4:35 ` [PATCH V3 3/3] PCI: mvebu: return NULL instead of ERR_PTR(ret) Jingoo Han
2013-09-23 7:24 ` Thomas Petazzoni
2013-11-25 20:02 ` Jason Gunthorpe
2013-11-25 20:02 ` Jason Gunthorpe
2013-11-26 5:31 ` Jingoo Han
2013-11-26 5:31 ` Jingoo Han
2013-11-26 12:27 ` Jason Cooper
2013-11-26 12:27 ` Jason Cooper
2013-11-26 18:09 ` Jason Gunthorpe
2013-11-26 18:09 ` Jason Gunthorpe
2013-11-27 1:59 ` Jingoo Han
2013-11-27 1:59 ` Jingoo Han
2013-11-27 1:59 ` Jingoo Han
2013-11-27 2:17 ` Josh Triplett [this message]
2013-11-27 2:17 ` [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer Josh Triplett
2013-11-27 2:26 ` PCI: mvebu: return NULL instead of ERR_PTR(ret) Joe Perches
2013-11-27 2:26 ` Joe Perches
2013-11-27 2:35 ` Josh Triplett
2013-11-27 2:35 ` Josh Triplett
2013-11-27 2:48 ` Joe Perches
2013-11-27 2:48 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131127021730.GA14138@leaf \
--to=josh@joshtriplett.org \
--cc=axel.lin@ingics.com \
--cc=bhelgaas@google.com \
--cc=dan.carpenter@oracle.com \
--cc=ezequiel.garcia@free-electrons.com \
--cc=jason@lakedaemon.net \
--cc=jg1.han@samsung.com \
--cc=jgunthorpe@obsidianresearch.com \
--cc=joe@perches.com \
--cc=julia.lawall@lip6.fr \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=thomas.petazzoni@free-electrons.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.