Commit b104d6a5 authored by Steven Rostedt's avatar Steven Rostedt Committed by Linus Torvalds

lib/devres.c: fix some sparse warnings

Having a discussion about sparse warnings in the kernel, and that we
should clean them up, I decided to pick a random file to do so.  This
happened to be devres.c which gives the following warnings:

    CHECK   lib/devres.c
  lib/devres.c:83:9: warning: cast removes address space of expression
  lib/devres.c:117:31: warning: incorrect type in return expression (different address spaces)
  lib/devres.c:117:31:    expected void [noderef] <asn:2>*
  lib/devres.c:117:31:    got void *
  lib/devres.c:125:31: warning: incorrect type in return expression (different address spaces)
  lib/devres.c:125:31:    expected void [noderef] <asn:2>*
  lib/devres.c:125:31:    got void *
  lib/devres.c:136:26: warning: incorrect type in assignment (different address spaces)
  lib/devres.c:136:26:    expected void [noderef] <asn:2>*[assigned] dest_ptr
  lib/devres.c:136:26:    got void *
  lib/devres.c:226:9: warning: cast removes address space of expression

Mostly it's just the use of typecasting to void * without adding
__force, or returning ERR_PTR(-ESOMEERR) without typecasting to a
__iomem type.

I added a helper macro IOMEM_ERR_PTR() that does the typecast to make
the code a little nicer than adding ugly typecasts to the code.
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3d8e4b40
...@@ -81,11 +81,13 @@ EXPORT_SYMBOL(devm_ioremap_nocache); ...@@ -81,11 +81,13 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
void devm_iounmap(struct device *dev, void __iomem *addr) void devm_iounmap(struct device *dev, void __iomem *addr)
{ {
WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match, WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
(void *)addr)); (__force void *)addr));
iounmap(addr); iounmap(addr);
} }
EXPORT_SYMBOL(devm_iounmap); EXPORT_SYMBOL(devm_iounmap);
#define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
/** /**
* devm_ioremap_resource() - check, request region, and ioremap resource * devm_ioremap_resource() - check, request region, and ioremap resource
* @dev: generic device to handle the resource for * @dev: generic device to handle the resource for
...@@ -114,7 +116,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) ...@@ -114,7 +116,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
if (!res || resource_type(res) != IORESOURCE_MEM) { if (!res || resource_type(res) != IORESOURCE_MEM) {
dev_err(dev, "invalid resource\n"); dev_err(dev, "invalid resource\n");
return ERR_PTR(-EINVAL); return IOMEM_ERR_PTR(-EINVAL);
} }
size = resource_size(res); size = resource_size(res);
...@@ -122,7 +124,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) ...@@ -122,7 +124,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
if (!devm_request_mem_region(dev, res->start, size, name)) { if (!devm_request_mem_region(dev, res->start, size, name)) {
dev_err(dev, "can't request region for resource %pR\n", res); dev_err(dev, "can't request region for resource %pR\n", res);
return ERR_PTR(-EBUSY); return IOMEM_ERR_PTR(-EBUSY);
} }
if (res->flags & IORESOURCE_CACHEABLE) if (res->flags & IORESOURCE_CACHEABLE)
...@@ -133,7 +135,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) ...@@ -133,7 +135,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
if (!dest_ptr) { if (!dest_ptr) {
dev_err(dev, "ioremap failed for resource %pR\n", res); dev_err(dev, "ioremap failed for resource %pR\n", res);
devm_release_mem_region(dev, res->start, size); devm_release_mem_region(dev, res->start, size);
dest_ptr = ERR_PTR(-ENOMEM); dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
} }
return dest_ptr; return dest_ptr;
...@@ -224,7 +226,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr) ...@@ -224,7 +226,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
{ {
ioport_unmap(addr); ioport_unmap(addr);
WARN_ON(devres_destroy(dev, devm_ioport_map_release, WARN_ON(devres_destroy(dev, devm_ioport_map_release,
devm_ioport_map_match, (void *)addr)); devm_ioport_map_match, (__force void *)addr));
} }
EXPORT_SYMBOL(devm_ioport_unmap); EXPORT_SYMBOL(devm_ioport_unmap);
#endif /* CONFIG_HAS_IOPORT */ #endif /* CONFIG_HAS_IOPORT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment