]> git.ipfire.org Git - thirdparty/kernel/stable.git/blobdiff - kernel/resource.c
resource: fix locking in find_next_iomem_res()
[thirdparty/kernel/stable.git] / kernel / resource.c
index d22423e85cf801ba358581f08390041c0929a2cf..3ced0cd45bdd5132d21c72c2121d04cc848646dd 100644 (file)
@@ -326,7 +326,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 or -EINVAL for other invalid parameters.
+ * -ENODEV.  Returns -EINVAL for invalid parameters.
  *
  * This function walks the whole tree and not just first level children
  * unless @first_lvl is true.
@@ -365,16 +365,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,