Skip to contentSkip to conversation

PCI: tegra: add missing __iomem annotation

PATCH Superseded Jingoo Han 6 participants 16 messages Sep 17, 2013 – Nov 27, 2013

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH v2 1/3 PCI: tegra: add missing __iomem annotation

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

---
 drivers/pci/host/pci-tegra.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pci-tegra.c +2 -2
index 2e9888a..7c4f38d 100644
@@ -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,
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH v2 2/3 PCI: mvebu: make local functions static

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?

---
 drivers/pci/host/pci-mvebu.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/pci/host/pci-mvebu.c +6 -6
index d66530e..b54ceb1 100644
@@ -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;
Signature · 1 line
1.7.10.4
author
#2 lore raw

PATCH v2 3/3 PCI: mvebu: add missing __iomem annotation

In reply to 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 *

---
 drivers/pci/host/pci-mvebu.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/host/pci-mvebu.c +2 -3
index b54ceb1..fb2474f 100644
@@ -741,7 +741,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
 
 	ret = of_address_to_resource(np, 0, &regs);
 	if (ret)
-		return ERR_PTR(ret);
+		return NULL;
 
 	return devm_ioremap_resource(&pdev->dev, &regs);
 }
@@ -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;
 		}
 
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation

Dear Jingoo Han,

Quoted 2 lines · Jingoo Han

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

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
author
#4 lore raw

Re: [PATCH V2 3/3] PCI: mvebu: add missing __iomem annotation

Quoted 7 lines · Thomas Petazzoni
Quoted 2 lines · Jingoo Han

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

author
#5 lore raw

PATCH v3 3/3 PCI: mvebu: return NULL instead of ERR_PTR(ret)

In reply to 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 *

---
 drivers/pci/host/pci-mvebu.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/host/pci-mvebu.c +2 -3
index 0bd3ba8..fb2474f 100644
@@ -741,7 +741,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
 
 	ret = of_address_to_resource(np, 0, &regs);
 	if (ret)
-		return ERR_PTR(ret);
+		return NULL;
 
 	return devm_ioremap_resource(&pdev->dev, &regs);
 }
@@ -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;
 		}
Signature · 1 line
1.7.10.4
Acked-by on v3 3/3
#6 lore raw

Re: [PATCH V3 3/3] PCI: mvebu: return NULL instead of ERR_PTR(ret)

Dear Jingoo Han,

Quoted 9 lines · 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 *

Signature · 3 lines
Thomas Petazzoni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#7 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

In reply to Jingoo Han
Quoted 2 lines · Jason Cooper

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)

Quoted 17 lines

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 *

drivers/pci/host/pci-mvebu.c static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, · line 745

Quoted 7 lines
drivers/pci/host/pci-mvebu.c +1 -1
@@ -740,7 +740,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
 
       ret = of_address_to_resource(np, 0, &regs);
       if (ret)
-               return ERR_PTR(ret);
+               return NULL;
 
       return devm_ioremap_resource(&pdev->dev, &regs);

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:

Quoted 4 lines
drivers/pci/host/pci-mvebu.c +1 -1
 		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

author
#8 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

Quoted 31 lines · Jason Gunthorpe
Quoted 2 lines · Jason Cooper

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)

Quoted 6 lines

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

Quoted 17 lines

spaces)
drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>*
drivers/pci/host/pci-mvebu.c:744:31: got void *

drivers/pci/host/pci-mvebu.c +1 -1
@@ -740,7 +740,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
 
       ret = of_address_to_resource(np, 0, &regs);
       if (ret)
-               return ERR_PTR(ret);
+               return NULL;
 
Quoted 4 lines

drivers/pci/host/pci-mvebu.c static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, · line 746

Quoted 1 line
drivers/pci/host/pci-mvebu.c +0 -0
       return devm_ioremap_resource(&pdev->dev, &regs);

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, &regs);
	if (ret)

- return ERR_PTR(ret);
+ return (void __iomem *)ERR_PTR(ret);

	return devm_ioremap_resource(&pdev->dev, &regs);
}

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

#9 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

Quoted 38 lines · Jingoo Han
Quoted 31 lines · Jason Gunthorpe
Quoted 2 lines · Jason Cooper

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)

Quoted 6 lines

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

Quoted 17 lines

spaces)
drivers/pci/host/pci-mvebu.c:744:31: expected void [noderef] <asn:2>*
drivers/pci/host/pci-mvebu.c:744:31: got void *

drivers/pci/host/pci-mvebu.c +1 -1
@@ -740,7 +740,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
 
       ret = of_address_to_resource(np, 0, &regs);
       if (ret)
-               return ERR_PTR(ret);
+               return NULL;
 
Quoted 4 lines

drivers/pci/host/pci-mvebu.c static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev, · line 746

Quoted 1 line
drivers/pci/host/pci-mvebu.c +0 -0
       return devm_ioremap_resource(&pdev->dev, &regs);

So we drop the ERR_PTR for that return but 'devm_ioremap_resource' returns ERR_PTR too:

Quoted 4 lines

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.

#10 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

In reply to Jingoo Han

Review

Quoted 13 lines · Jingoo Han

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, &regs);
	if (ret)
(quoted diff) +1 -1
-		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

author
#11 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

Quoted 18 lines · Jason Gunthorpe

Review

Quoted 13 lines · Jingoo Han

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, &regs);
	if (ret)
(quoted diff) +1 -1
-		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.

Quoted 3 lines

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, &regs);
	if (ret)
		return ERR_PTR(ret);

	return devm_ioremap_resource(&pdev->dev, &regs);
}
./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, &regs);
	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?

drivers/pci/host/pci-mvebu.c +0 -0
@@ -740,7 +740,7 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
 
	ret = of_address_to_resource(np, 0, &regs);
	if (ret)

- return ERR_PTR(ret);
+ return NULL;

	return devm_ioremap_resource(&pdev->dev, &regs);
 }
@@ -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

#12 lore raw

PATCH 1/1 linux/err.h: Provide an ERR_PTR_IO that returns an __iomem pointer

Quoted 33 lines · Jingoo Han
Quoted 18 lines · Jason Gunthorpe

Review

Quoted 13 lines · Jingoo Han

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, &regs);
	if (ret)
(quoted diff) +1 -1
-		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.

Quoted 3 lines

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.

Quoted 6 lines

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 <[email protected]>
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.

---
 include/linux/err.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/err.h +5 -0
index 15f92e0..d64215b 100644
@@ -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;
Signature · 1 line
1.8.4.4
#13 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

In reply to Jingoo Han

On Wed, 2013-11-27 at 10:59 +0900, Jingoo Han wrote:
[]

Quoted 11 lines

./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, &regs);
	if (ret)
(quoted diff) +1 -1
-		return ERR_PTR(ret);
+		return (void __iomem *)ERR_PTR(ret);
Quoted 5 lines

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.

#14 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

Quoted 26 lines · Joe Perches

On Wed, 2013-11-27 at 10:59 +0900, Jingoo Han wrote:
[]

Quoted 11 lines

./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, &regs);
	if (ret)
(quoted diff) +1 -1
-		return ERR_PTR(ret);
+		return (void __iomem *)ERR_PTR(ret);
Quoted 5 lines

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.

Quoted 6 lines

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

#15 lore raw

PCI: mvebu: return NULL instead of ERR_PTR(ret)

Quoted 31 lines · Josh Triplett
Quoted 30 lines · Joe Perches

On Wed, 2013-11-27 at 10:59 +0900, Jingoo Han wrote:
[]

Quoted 11 lines

./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, &regs);
	if (ret)
(quoted diff) +1 -1
-		return ERR_PTR(ret);
+		return (void __iomem *)ERR_PTR(ret);
Quoted 5 lines

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));
Quoted 8 lines
Quoted 2 lines

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.