diff options
author | Yinghai Lu <yinghai@kernel.org> | 2012-09-17 22:24:28 -0700 |
---|---|---|
committer | Yinghai Lu <yinghai@kernel.org> | 2012-09-17 22:24:28 -0700 |
commit | 4f2300d956a338a95bdc9e15df94f886f607abda (patch) | |
tree | 0c8c47b00e792fc4c057fe36a8a19f7e9a34a2d6 | |
parent | f436211e327e509a1da7867f0b707ddf627af12e (diff) | |
download | linux-yinghai-4f2300d956a338a95bdc9e15df94f886f607abda.tar.gz |
resources: Replace registered resource in tree.
We could have one resource inserted in tree at first during probing.
Later we need to put real resource into the tree.
So try to hold the lock to swap them.
-v2: make it more generic to handle old one with children or no parent.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r-- | include/linux/ioport.h | 1 | ||||
-rw-r--r-- | kernel/resource.c | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/ioport.h b/include/linux/ioport.h index fff4c567416402..9ab44ab9669d55 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -162,6 +162,7 @@ int probe_resource(struct resource *b_res, struct resource *busn_res, resource_size_t needed_size, struct resource **p, int skip_nr, int flags); +void replace_resource(struct resource *old_res, struct resource *new_res); struct resource *lookup_resource(struct resource *root, resource_size_t start); int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size); diff --git a/kernel/resource.c b/kernel/resource.c index fe6ad96beca0b9..370ab7de06eec9 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1165,6 +1165,31 @@ out: return ret; } +/* replace old with new in the resource tree */ +void replace_resource(struct resource *old, struct resource *new) +{ + struct resource *parent, *tmp, *p; + + write_lock(&resource_lock); + new->start = old->start; + new->end = old->end; + new->flags = old->flags; + + p = old->child; + while (p) { + tmp = p; + p = p->sibling; + __release_resource(tmp); + __request_resource(new, tmp); + } + parent = old->parent; + if (parent) { + __release_resource(old); + __request_resource(parent, new); + } + write_unlock(&resource_lock); +} + /* * Managed region resource */ |