* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) [not found] ` <20131126180930.GC19852@obsidianresearch.com> @ 2013-11-27 1:59 ` Jingoo Han 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 0 siblings, 2 replies; 5+ messages in thread From: Jingoo Han @ 2013-11-27 1:59 UTC (permalink / raw) To: 'Christopher Li', linux-sparse, 'Joe Perches', 'Dan Carpenter' Cc: 'Thomas Petazzoni', 'Axel Lin', 'Jason Cooper', linux-pci, 'Jingoo Han', 'Jason Gunthorpe', 'Julia Lawall', 'Ezequiel Garcia', 'Bjorn Helgaas', linux-arm-kernel 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 *). ./drivers/pci/host/pci-mvebu.c 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 devm_ioremap_resource(&pdev->dev, ®s); } ./include/linux/err.h static inline void * __must_check ERR_PTR(long error) { return (void *) error; } Previously, I submitted the following patch, that adds (void __iomem *) cast. ./drivers/pci/host/pci-mvebu.c static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, struct device_node *np, struct mvebu_pcie_port *port) { ..... ret = of_address_to_resource(np, 0, ®s); if (ret) - return ERR_PTR(ret); + return (void __iomem *)ERR_PTR(ret); However, other engineers said that "(void __iomem *)ERR_PTR(ret)" is not a general pattern. I cannot find the proper method to resolve this sparse warning. In this case, how can I resolve this sparse warning? Then, how about the following? --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c @@ -740,7 +740,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, ret = of_address_to_resource(np, 0, ®s); if (ret) - return ERR_PTR(ret); + return NULL; return devm_ioremap_resource(&pdev->dev, ®s); } @@ -939,7 +939,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev) continue; port->base = mvebu_pcie_map_registers(pdev, child, port); - if (IS_ERR(port->base)) { + if (IS_ERR_OR_NULL(port->base)) { dev_err(&pdev->dev, "PCIe%d.%d: cannot map registers\n", port->port, port->lane); port->base = NULL; Thank you for reading this. :-) Best regards, Jingoo Han ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer 2013-11-27 1:59 ` PCI: mvebu: return NULL instead of ERR_PTR(ret) Jingoo Han @ 2013-11-27 2:17 ` Josh Triplett 2013-11-27 2:26 ` PCI: mvebu: return NULL instead of ERR_PTR(ret) Joe Perches 1 sibling, 0 replies; 5+ messages in thread From: Josh Triplett @ 2013-11-27 2:17 UTC (permalink / raw) To: Jingoo Han Cc: 'Christopher Li', linux-sparse, 'Joe Perches', 'Dan Carpenter', 'Jason Gunthorpe', 'Jason Cooper', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel, 'Axel Lin', 'Julia Lawall' 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-27 1:59 ` PCI: mvebu: return NULL instead of ERR_PTR(ret) Jingoo Han 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 ` Joe Perches 2013-11-27 2:35 ` Josh Triplett 1 sibling, 1 reply; 5+ messages in thread From: Joe Perches @ 2013-11-27 2:26 UTC (permalink / raw) To: Jingoo Han Cc: 'Christopher Li', linux-sparse, 'Dan Carpenter', 'Jason Gunthorpe', 'Jason Cooper', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel, 'Axel Lin', 'Julia Lawall' On Wed, 2013-11-27 at 10:59 +0900, Jingoo Han wrote: [] > ./drivers/pci/host/pci-mvebu.c > static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, > struct device_node *np, struct mvebu_pcie_port *port) > { > ..... > > ret = of_address_to_resource(np, 0, ®s); > if (ret) > - return ERR_PTR(ret); > + return (void __iomem *)ERR_PTR(ret); > > However, other engineers said that "(void __iomem *)ERR_PTR(ret)" > is not a general pattern. I cannot find the proper method to resolve > this sparse warning. > > In this case, how can I resolve this sparse warning? I think there's no problem using the cast. It's not a pattern because it's not been required before as function returns have not previously been declared __iomem. Or, perhaps the arm|hexagon specific #define below could be made generic so it could be used. arch/arm/include/asm/io.h:#define IOMEM(x) ((void __force __iomem *)(x)) return IOMEM(ERR_PTR(ret)); There aren't any current uses of return IOMEM(foo) either though so the direct cast is probably more appropriate. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-27 2:26 ` PCI: mvebu: return NULL instead of ERR_PTR(ret) Joe Perches @ 2013-11-27 2:35 ` Josh Triplett 2013-11-27 2:48 ` Joe Perches 0 siblings, 1 reply; 5+ messages in thread From: Josh Triplett @ 2013-11-27 2:35 UTC (permalink / raw) To: Joe Perches Cc: Jingoo Han, 'Christopher Li', linux-sparse, 'Dan Carpenter', 'Jason Gunthorpe', 'Jason Cooper', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel, 'Axel Lin', 'Julia Lawall' On Tue, Nov 26, 2013 at 06:26:36PM -0800, Joe Perches wrote: > On Wed, 2013-11-27 at 10:59 +0900, Jingoo Han wrote: > [] > > ./drivers/pci/host/pci-mvebu.c > > static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, > > struct device_node *np, struct mvebu_pcie_port *port) > > { > > ..... > > > > ret = of_address_to_resource(np, 0, ®s); > > if (ret) > > - return ERR_PTR(ret); > > + return (void __iomem *)ERR_PTR(ret); > > > > However, other engineers said that "(void __iomem *)ERR_PTR(ret)" > > is not a general pattern. I cannot find the proper method to resolve > > this sparse warning. > > > > In this case, how can I resolve this sparse warning? > > I think there's no problem using the cast. It's not a > pattern because it's not been required before as function > returns have not previously been declared __iomem. > > Or, perhaps the arm|hexagon specific #define below could > be made generic so it could be used. > > arch/arm/include/asm/io.h:#define IOMEM(x) ((void __force __iomem *)(x)) > > return IOMEM(ERR_PTR(ret)); > > There aren't any current uses of return IOMEM(foo) either > though so the direct cast is probably more appropriate. I don't think that #define is appropriate for any non-constant value; almost any instance of that __force cast applied to a variable would be better written by fixing types more appropriately. I'd suggest updating that #define for both architectures to use BUILD_BUG_ON to assert __builtin_constant_p on its argument. - Josh Triplett ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-27 2:35 ` Josh Triplett @ 2013-11-27 2:48 ` Joe Perches 0 siblings, 0 replies; 5+ messages in thread From: Joe Perches @ 2013-11-27 2:48 UTC (permalink / raw) To: Josh Triplett Cc: Jingoo Han, 'Christopher Li', linux-sparse, 'Dan Carpenter', 'Jason Gunthorpe', 'Jason Cooper', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel, 'Axel Lin', 'Julia Lawall' On Tue, 2013-11-26 at 18:35 -0800, Josh Triplett wrote: > On Tue, Nov 26, 2013 at 06:26:36PM -0800, Joe Perches wrote: > > On Wed, 2013-11-27 at 10:59 +0900, Jingoo Han wrote: > > [] > > > ./drivers/pci/host/pci-mvebu.c > > > static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, > > > struct device_node *np, struct mvebu_pcie_port *port) > > > { > > > ..... > > > > > > ret = of_address_to_resource(np, 0, ®s); > > > if (ret) > > > - return ERR_PTR(ret); > > > + return (void __iomem *)ERR_PTR(ret); > > > > > > However, other engineers said that "(void __iomem *)ERR_PTR(ret)" > > > is not a general pattern. I cannot find the proper method to resolve > > > this sparse warning. > > > > > > In this case, how can I resolve this sparse warning? > > > > I think there's no problem using the cast. It's not a > > pattern because it's not been required before as function > > returns have not previously been declared __iomem. > > > > Or, perhaps the arm|hexagon specific #define below could > > be made generic so it could be used. > > > > arch/arm/include/asm/io.h:#define IOMEM(x) ((void __force __iomem *)(x)) > > > > return IOMEM(ERR_PTR(ret)); > > > > There aren't any current uses of return IOMEM(foo) either > > though so the direct cast is probably more appropriate. > > I don't think that #define is appropriate for any non-constant value; > almost any instance of that __force cast applied to a variable would be > better written by fixing types more appropriately. I'd suggest > updating that #define for both architectures to use BUILD_BUG_ON to > assert __builtin_constant_p on its argument. That's probably a good idea. There are at least a couple things would likely need to be fixed up if the #define were changed. arch/arm/plat-omap/sram.c drivers/clocksource/bcm_kona_timer.c I've no issue with either a direct cast or your idea of a new static inline like ERR_PTR_IO or IOMEM_ERR_PTR or any other appropriate name. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-11-27 2:48 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <001001ceb816$5d1aecc0$1750c640$%han@samsung.com> [not found] ` <20131125200256.GA7316@obsidianresearch.com> [not found] ` <001101ceea68$cb486220$61d92660$%han@samsung.com> [not found] ` <20131126180930.GC19852@obsidianresearch.com> 2013-11-27 1:59 ` PCI: mvebu: return NULL instead of ERR_PTR(ret) Jingoo Han 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:35 ` Josh Triplett 2013-11-27 2:48 ` Joe Perches
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).