Skip to content

Commit 192b9af

Browse files
anadavgregkh
authored andcommitted
resource: fix locking in find_next_iomem_res()
[ Upstream commit 49f17c26c123b60fd1c74629eef077740d16ffc2 ] Since resources can be removed, locking should ensure that the resource is not removed while accessing it. However, find_next_iomem_res() does not hold the lock while copying the data of the resource. Keep holding the lock while the data is copied. While at it, change the return value to a more informative value. It is disregarded by the callers. [[email protected]: fix find_next_iomem_res() documentation] Link: http://lkml.kernel.org/r/[email protected] Fixes: ff3cc95 ("resource: Add remove_resource interface") Signed-off-by: Nadav Amit <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Reviewed-by: Dan Williams <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Toshi Kani <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 485bcc2 commit 192b9af

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

kernel/resource.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ EXPORT_SYMBOL(release_resource);
325325
*
326326
* If a resource is found, returns 0 and *res is overwritten with the part
327327
* of the resource that's within [start..end]; if none is found, returns
328-
* -1.
328+
* -ENODEV. Returns -EINVAL for invalid parameters.
329329
*
330330
* This function walks the whole tree and not just first level children
331331
* 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,
359359
break;
360360
}
361361

362+
if (p) {
363+
/* copy data */
364+
res->start = max(start, p->start);
365+
res->end = min(end, p->end);
366+
res->flags = p->flags;
367+
res->desc = p->desc;
368+
}
369+
362370
read_unlock(&resource_lock);
363-
if (!p)
364-
return -1;
365-
366-
/* copy data */
367-
res->start = max(start, p->start);
368-
res->end = min(end, p->end);
369-
res->flags = p->flags;
370-
res->desc = p->desc;
371-
return 0;
371+
return p ? 0 : -ENODEV;
372372
}
373373

374374
static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,

0 commit comments

Comments
 (0)