resource: fix locking in find_next_iomem_res()

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

[ fix find_next_iomem_res() documentation]
Fixes: ff3cc952d3f00 ("resource: Add remove_resource interface")
Signed-off-by: Nadav Amit <>
Reviewed-by: Andrew Morton <>
Reviewed-by: Dan Williams <>
Cc: Borislav Petkov <>
Cc: Toshi Kani <>
Cc: Peter Zijlstra <>
Cc: Dave Hansen <>
Cc: Bjorn Helgaas <>
Cc: Ingo Molnar <>
Cc: <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
1 file changed