diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2014-02-05 07:32:28 +0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2014-02-27 01:42:09 +0400 |
commit | 5edb93b89f6cc3089ee283656555e7a9ad36a8a0 (patch) | |
tree | 496964f830aa06af8351de8645ec7e19ef931264 /include/linux/ioport.h | |
parent | d2e074ccbf84e91819ae07b3ca838120db2c97a9 (diff) | |
download | linux-5edb93b89f6cc3089ee283656555e7a9ad36a8a0.tar.xz |
resource: Add resource_contains()
We have two identical copies of resource_contains() already, and more
places that could use it. This moves it to ioport.h where it can be
shared.
resource_contains(struct resource *r1, struct resource *r2) returns true
iff r1 and r2 are the same type (most callers already checked this
separately) and the r1 address range completely contains r2.
In addition, the new resource_contains() checks that both r1 and r2 have
addresses assigned to them. If a resource is IORESOURCE_UNSET, it doesn't
have a valid address and can't contain or be contained by another resource.
Some callers already check this or for res->start.
No functional change.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'include/linux/ioport.h')
-rw-r--r-- | include/linux/ioport.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 89b7c24a36e9..9fcaac8bc4f6 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -169,6 +169,16 @@ static inline unsigned long resource_type(const struct resource *res) { return res->flags & IORESOURCE_TYPE_BITS; } +/* True iff r1 completely contains r2 */ +static inline bool resource_contains(struct resource *r1, struct resource *r2) +{ + if (resource_type(r1) != resource_type(r2)) + return false; + if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET) + return false; + return r1->start <= r2->start && r1->end >= r2->end; +} + /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) |