Skip to content

Commit 49f17c2

Browse files
anadavtorvalds
authored andcommitted
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 callers. [akpm@linux-foundation.org: fix find_next_iomem_res() documentation] Link: http://lkml.kernel.org/r/20190613045903.4922-2-namit@vmware.com Fixes: ff3cc95 ("resource: Add remove_resource interface") Signed-off-by: Nadav Amit <namit@vmware.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: Toshi Kani <toshi.kani@hpe.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c063066 commit 49f17c2

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎kernel/resource.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ EXPORT_SYMBOL(release_resource);
326326
*
327327
* If a resource is found, returns 0 and @*res is overwritten with the part
328328
* of the resource that's within [@start..@end]; if none is found, returns
329-
* -1 or -EINVAL for other invalid parameters.
329+
* -ENODEV. Returns -EINVAL for invalid parameters.
330330
*
331331
* This function walks the whole tree and not just first level children
332332
* unless @first_lvl is true.
@@ -365,16 +365,16 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
365365
break;
366366
}
367367

368+
if (p) {
369+
/* copy data */
370+
res->start = max(start, p->start);
371+
res->end = min(end, p->end);
372+
res->flags = p->flags;
373+
res->desc = p->desc;
374+
}
375+
368376
read_unlock(&resource_lock);
369-
if (!p)
370-
return -1;
371-
372-
/* copy data */
373-
res->start = max(start, p->start);
374-
res->end = min(end, p->end);
375-
res->flags = p->flags;
376-
res->desc = p->desc;
377-
return 0;
377+
return p ? 0 : -ENODEV;
378378
}
379379

380380
static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,

0 commit comments

Comments
 (0)