* [PATCH V2 1/3] PCI: tegra: add missing __iomem annotation @ 2013-09-17 5:25 Jingoo Han 2013-09-17 5:26 ` [PATCH V2 2/3] PCI: mvebu: make local functions static Jingoo Han ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Jingoo Han @ 2013-09-17 5:25 UTC (permalink / raw) To: 'Bjorn Helgaas' Cc: 'Thierry Reding', linux-pci, 'Stephen Warren', 'Jingoo Han' Added missing __iomem annotation in order to fix the following sparse warnings: drivers/pci/host/pci-tegra.c:411:41: warning: incorrect type in return expression (different address spaces) drivers/pci/host/pci-tegra.c:411:41: expected void [noderef] <asn:2>* drivers/pci/host/pci-tegra.c:411:41: got void *addr drivers/pci/host/pci-tegra.c:419:25: warning: incorrect type in return expression (different address spaces) drivers/pci/host/pci-tegra.c:419:25: expected void [noderef] <asn:2>* drivers/pci/host/pci-tegra.c:419:25: got void *addr Signed-off-by: Jingoo Han <jg1.han@samsung.com> --- drivers/pci/host/pci-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c index 2e9888a..7c4f38d 100644 --- a/drivers/pci/host/pci-tegra.c +++ b/drivers/pci/host/pci-tegra.c @@ -408,7 +408,7 @@ static void __iomem *tegra_pcie_bus_map(struct tegra_pcie *pcie, list_for_each_entry(bus, &pcie->busses, list) if (bus->nr == busnr) - return bus->area->addr; + return (void __iomem *)bus->area->addr; bus = tegra_pcie_bus_alloc(pcie, busnr); if (IS_ERR(bus)) @@ -416,7 +416,7 @@ static void __iomem *tegra_pcie_bus_map(struct tegra_pcie *pcie, list_add_tail(&bus->list, &pcie->busses); - return bus->area->addr; + return (void __iomem *)bus->area->addr; } static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus, -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V2 2/3] PCI: mvebu: make local functions static 2013-09-17 5:25 [PATCH V2 1/3] PCI: tegra: add missing __iomem annotation Jingoo Han @ 2013-09-17 5:26 ` Jingoo Han 2013-09-17 5:27 ` [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation Jingoo Han 2013-09-23 4:35 ` [PATCH V3 3/3] PCI: mvebu: return NULL instead of ERR_PTR(ret) Jingoo Han 2 siblings, 0 replies; 16+ messages in thread From: Jingoo Han @ 2013-09-17 5:26 UTC (permalink / raw) To: 'Bjorn Helgaas' Cc: linux-pci, 'Thomas Petazzoni', 'Jason Cooper', 'Jingoo Han' mvebu_pcie_add_bus(), mvebu_pcie_align_resource() are used only in this file. Thus, these local functions should be staticized in order to fix the following sparse warnings: drivers/pci/host/pci-mvebu.c:684:6: warning: symbol 'mvebu_pcie_add_bus' was not declared. Should it be static? drivers/pci/host/pci-mvebu.c:690:17: warning: symbol 'mvebu_pcie_align_resource' was not declared. Should it be static? Signed-off-by: Jingoo Han <jg1.han@samsung.com> Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> --- drivers/pci/host/pci-mvebu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index d66530e..b54ceb1 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c @@ -681,17 +681,17 @@ static struct pci_bus *mvebu_pcie_scan_bus(int nr, struct pci_sys_data *sys) return bus; } -void mvebu_pcie_add_bus(struct pci_bus *bus) +static void mvebu_pcie_add_bus(struct pci_bus *bus) { struct mvebu_pcie *pcie = sys_to_pcie(bus->sysdata); bus->msi = pcie->msi; } -resource_size_t mvebu_pcie_align_resource(struct pci_dev *dev, - const struct resource *res, - resource_size_t start, - resource_size_t size, - resource_size_t align) +static resource_size_t mvebu_pcie_align_resource(struct pci_dev *dev, + const struct resource *res, + resource_size_t start, + resource_size_t size, + resource_size_t align) { if (dev->bus->number != 0) return start; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation 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 ` Jingoo Han 2013-09-17 17:42 ` Thomas Petazzoni 2013-09-23 4:35 ` [PATCH V3 3/3] PCI: mvebu: return NULL instead of ERR_PTR(ret) Jingoo Han 2 siblings, 1 reply; 16+ messages in thread From: Jingoo Han @ 2013-09-17 5:27 UTC (permalink / raw) To: 'Bjorn Helgaas' Cc: linux-pci, 'Thomas Petazzoni', 'Jason Cooper', 'Jingoo Han' Added missing __iomem annotation in order to fix the following sparse warning: drivers/pci/host/pci-mvebu.c:744:31: warning: incorrect type in return expression (different address spaces) drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>* drivers/pci/host/pci-mvebu.c:744:31: got void * Signed-off-by: Jingoo Han <jg1.han@samsung.com> Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> --- drivers/pci/host/pci-mvebu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index b54ceb1..fb2474f 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c @@ -741,7 +741,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); } @@ -940,11 +940,10 @@ 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 (!port->base) { dev_err(&pdev->dev, "PCIe%d.%d: cannot map registers\n", port->port, port->lane); clk_disable_unprepare(port->clk); - port->base = NULL; continue; } -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation 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 0 siblings, 1 reply; 16+ messages in thread From: Thomas Petazzoni @ 2013-09-17 17:42 UTC (permalink / raw) To: Jingoo Han; +Cc: 'Bjorn Helgaas', linux-pci, 'Jason Cooper' Dear Jingoo Han, On Tue, 17 Sep 2013 14:27:31 +0900, Jingoo Han wrote: > Added missing __iomem annotation in order to fix the following > sparse warning: I believe your commit title and log is now wrong: this commit is not adding an iomem annotation anywhere. Thanks! Thomas -- Thomas Petazzoni, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation 2013-09-17 17:42 ` Thomas Petazzoni @ 2013-09-23 2:27 ` Jingoo Han 0 siblings, 0 replies; 16+ messages in thread From: Jingoo Han @ 2013-09-23 2:27 UTC (permalink / raw) To: 'Thomas Petazzoni' Cc: 'Bjorn Helgaas', linux-pci, 'Jason Cooper', 'Jingoo Han' On Wednesday, September 18, 2013 2:42 AM, Thomas Petazzoni wrote: > On Tue, 17 Sep 2013 14:27:31 +0900, Jingoo Han wrote: > > Added missing __iomem annotation in order to fix the following > > sparse warning: > > I believe your commit title and log is now wrong: this commit is not > adding an iomem annotation anywhere. > Yes, you're right. I will fix the commit title and log, and send v3 patch, soon. Thank you for your comment. :-) Best regards, Jingoo Han ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH V3 3/3] PCI: mvebu: return NULL instead of ERR_PTR(ret) 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-23 4:35 ` Jingoo Han 2013-09-23 7:24 ` Thomas Petazzoni 2013-11-25 20:02 ` Jason Gunthorpe 2 siblings, 2 replies; 16+ messages in thread From: Jingoo Han @ 2013-09-23 4:35 UTC (permalink / raw) To: 'Bjorn Helgaas' Cc: linux-pci, 'Thomas Petazzoni', 'Jason Cooper', 'Jingoo Han' Return NULL instead of ERR_PTR(ret) in order to fix the following sparse warning: drivers/pci/host/pci-mvebu.c:744:31: warning: incorrect type in return expression (different address spaces) drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>* drivers/pci/host/pci-mvebu.c:744:31: got void * Signed-off-by: Jingoo Han <jg1.han@samsung.com> Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> --- drivers/pci/host/pci-mvebu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index 0bd3ba8..fb2474f 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c @@ -741,7 +741,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); } @@ -940,10 +940,9 @@ 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 (!port->base) { dev_err(&pdev->dev, "PCIe%d.%d: cannot map registers\n", port->port, port->lane); - port->base = NULL; clk_disable_unprepare(port->clk); continue; } -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH V3 3/3] PCI: mvebu: return NULL instead of ERR_PTR(ret) 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 1 sibling, 0 replies; 16+ messages in thread From: Thomas Petazzoni @ 2013-09-23 7:24 UTC (permalink / raw) To: Jingoo Han; +Cc: 'Bjorn Helgaas', linux-pci, 'Jason Cooper' Dear Jingoo Han, On Mon, 23 Sep 2013 13:35:42 +0900, Jingoo Han wrote: > Return NULL instead of ERR_PTR(ret) in order to fix the following > sparse warning: > > drivers/pci/host/pci-mvebu.c:744:31: warning: incorrect type in return expression (different address spaces) > drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>* > drivers/pci/host/pci-mvebu.c:744:31: got void * > > Signed-off-by: Jingoo Han <jg1.han@samsung.com> > Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> -- Thomas Petazzoni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 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-26 5:31 ` Jingoo Han 1 sibling, 1 reply; 16+ messages in thread From: Jason Gunthorpe @ 2013-11-25 20:02 UTC (permalink / raw) To: Jason Cooper, Jingoo Han Cc: Thomas Petazzoni, Bjorn Helgaas, linux-pci, Ezequiel Garcia, linux-arm-kernel On Sat, Nov 23, 2013 at 10:00:33PM -0500, Jason Cooper wrote: > And a small addendum: I currently have the following in mvebu/drivers > 058100a08be8 PCI: mvebu: return NULL instead of ERR_PTR(ret) Folks, I took a quick look at this, and it looks suspicious (sorry, I can't seem to find the thread to followup post) > PCI: mvebu: return NULL instead of ERR_PTR(ret) > > Return NULL instead of ERR_PTR(ret) in order to fix the following > sparse warning: > > drivers/pci/host/pci-mvebu.c:744:31: warning: incorrect type in return expression (different address > spaces) > drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>* > drivers/pci/host/pci-mvebu.c:744:31: got void * > > Signed-off-by: Jingoo Han <jg1.han@samsung.com> > Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> > Signed-off-by: Jason Cooper <jason@lakedaemon.net> > >--- 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); So we drop the ERR_PTR for that return but 'devm_ioremap_resource' returns ERR_PTR too: /** * devm_ioremap_resource() - check, request region, and ioremap resource * @dev: generic device to handle the resource for * @res: resource to be handled * * Checks that a resource is a valid memory region, requests the memory region * and ioremaps it either as cacheable or as non-cacheable memory depending on * the resource's flags. All operations are managed and will be undone on * driver detach. * * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code * on failure. Usage example: * * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); * base = devm_ioremap_resource(&pdev->dev, res); * if (IS_ERR(base)) * return PTR_ERR(base); So this is clearly wrong: > port->base = mvebu_pcie_map_registers(pdev, child, port); >- if (IS_ERR(port->base)) { >+ if (!port->base) { > dev_err(&pdev->dev, NAK I guess? This looks like a sparse problem, doesn't it complain for devm_ioremap_resource too? void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) { [..] return ERR_PTR(-EBUSY); Regards, Jason ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-25 20:02 ` Jason Gunthorpe @ 2013-11-26 5:31 ` Jingoo Han 2013-11-26 12:27 ` Jason Cooper 2013-11-26 18:09 ` Jason Gunthorpe 0 siblings, 2 replies; 16+ messages in thread From: Jingoo Han @ 2013-11-26 5:31 UTC (permalink / raw) To: 'Jason Gunthorpe', 'Jason Cooper' Cc: 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel, 'Jingoo Han' On Tuesday, November 26, 2013 5:03 AM, Jason Gunthorpe wrote: > On Sat, Nov 23, 2013 at 10:00:33PM -0500, Jason Cooper wrote: > > And a small addendum: I currently have the following in mvebu/drivers > > 058100a08be8 PCI: mvebu: return NULL instead of ERR_PTR(ret) > > Folks, I took a quick look at this, and it looks suspicious (sorry, I > can't seem to find the thread to followup post) > > > PCI: mvebu: return NULL instead of ERR_PTR(ret) > > > > Return NULL instead of ERR_PTR(ret) in order to fix the following > > sparse warning: > > > > drivers/pci/host/pci-mvebu.c:744:31: warning: incorrect type in return expression (different > address > > spaces) > > drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>* > > drivers/pci/host/pci-mvebu.c:744:31: got void * > > > > Signed-off-by: Jingoo Han <jg1.han@samsung.com> > > Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> > > Signed-off-by: Jason Cooper <jason@lakedaemon.net> > > > >--- 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); > > So we drop the ERR_PTR for that return but 'devm_ioremap_resource' > returns ERR_PTR too: Yes, you're right. It makes the problem. Thus, this commit "PCI: mvebu: return NULL instead of ERR_PTR(ret)" should be reverted. 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); return devm_ioremap_resource(&pdev->dev, ®s); } static int mvebu_pcie_probe(struct platform_device *pdev) { ..... port->base = mvebu_pcie_map_registers(pdev, child, port); if (IS_ERR(port->base)) { dev_err(&pdev->dev, "PCIe%d.%d: cannot map registers\n", port->port, port->lane); port->base = NULL; clk_disable_unprepare(port->clk); continue; } Best regards, Jingoo Han ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-26 5:31 ` Jingoo Han @ 2013-11-26 12:27 ` Jason Cooper 2013-11-26 18:09 ` Jason Gunthorpe 1 sibling, 0 replies; 16+ messages in thread From: Jason Cooper @ 2013-11-26 12:27 UTC (permalink / raw) To: Jingoo Han Cc: 'Jason Gunthorpe', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel On Tue, Nov 26, 2013 at 02:31:44PM +0900, Jingoo Han wrote: > > On Tuesday, November 26, 2013 5:03 AM, Jason Gunthorpe wrote: > > On Sat, Nov 23, 2013 at 10:00:33PM -0500, Jason Cooper wrote: > > > And a small addendum: I currently have the following in mvebu/drivers > > > 058100a08be8 PCI: mvebu: return NULL instead of ERR_PTR(ret) > > > > Folks, I took a quick look at this, and it looks suspicious (sorry, I > > can't seem to find the thread to followup post) > > > > > PCI: mvebu: return NULL instead of ERR_PTR(ret) > > > > > > Return NULL instead of ERR_PTR(ret) in order to fix the following > > > sparse warning: > > > > > > drivers/pci/host/pci-mvebu.c:744:31: warning: incorrect type in return expression (different > > address > > > spaces) > > > drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>* > > > drivers/pci/host/pci-mvebu.c:744:31: got void * > > > > > > Signed-off-by: Jingoo Han <jg1.han@samsung.com> > > > Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> > > > Signed-off-by: Jason Cooper <jason@lakedaemon.net> > > > > > >--- 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); > > > > So we drop the ERR_PTR for that return but 'devm_ioremap_resource' > > returns ERR_PTR too: > > Yes, you're right. > It makes the problem. > Thus, this commit "PCI: mvebu: return NULL instead of ERR_PTR(ret)" > should be reverted. It hasn't gone to mainline yet and I haven't sent a pull request for it yet. So I can just drop it. Since we have the discussion on all three of those patches re-ignited, I'll just drop the branch and Ack the resends for going through Bjorn. thx, Jason. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-26 5:31 ` Jingoo Han 2013-11-26 12:27 ` Jason Cooper @ 2013-11-26 18:09 ` Jason Gunthorpe 2013-11-27 1:59 ` Jingoo Han 1 sibling, 1 reply; 16+ messages in thread From: Jason Gunthorpe @ 2013-11-26 18:09 UTC (permalink / raw) To: Jingoo Han Cc: 'Jason Cooper', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel 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. Regards, Jason ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 2013-11-26 18:09 ` Jason Gunthorpe @ 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; 16+ messages in thread From: Jingoo Han @ 2013-11-27 1:59 UTC (permalink / raw) To: 'Christopher Li', linux-sparse, 'Joe Perches', 'Dan Carpenter' Cc: 'Jason Gunthorpe', 'Jason Cooper', 'Thomas Petazzoni', 'Bjorn Helgaas', linux-pci, 'Ezequiel Garcia', linux-arm-kernel, 'Axel Lin', 'Julia Lawall', 'Jingoo Han' 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] 16+ messages in thread
* [PATCH] linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer 2013-11-27 1:59 ` 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; 16+ 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] 16+ messages in thread
* Re: PCI: mvebu: return NULL instead of ERR_PTR(ret) 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 ` Joe Perches 2013-11-27 2:35 ` Josh Triplett 1 sibling, 1 reply; 16+ 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] 16+ 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; 16+ 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] 16+ 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; 16+ 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] 16+ messages in thread
end of thread, other threads:[~2013-11-27 2:48 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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-26 5:31 ` Jingoo Han 2013-11-26 12:27 ` Jason Cooper 2013-11-26 18:09 ` Jason Gunthorpe 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 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).