diff --git a/kernel/resource.c b/kernel/resource.c index 38b8d11c9eaf46233028dc30c36b79c97399a62f..bce773cc5e4169022d8a1f5fbc6380771ae41fe2 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -325,7 +325,7 @@ EXPORT_SYMBOL(release_resource); * * If a resource is found, returns 0 and *res is overwritten with the part * of the resource that's within [start..end]; if none is found, returns - * -1. + * -ENODEV. Returns -EINVAL for invalid parameters. * * This function walks the whole tree and not just first level children * unless @first_level_children_only is true. @@ -359,16 +359,16 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, break; } + if (p) { + /* copy data */ + res->start = max(start, p->start); + res->end = min(end, p->end); + res->flags = p->flags; + res->desc = p->desc; + } + read_unlock(&resource_lock); - if (!p) - return -1; - - /* copy data */ - res->start = max(start, p->start); - res->end = min(end, p->end); - res->flags = p->flags; - res->desc = p->desc; - return 0; + return p ? 0 : -ENODEV; } static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,