Commit bc9ae224 authored by Eric Dumazet's avatar Eric Dumazet Committed by Linus Torvalds
Browse files

radix-tree: must check __radix_tree_preload() return value

__radix_tree_preload() only disables preemption if no error is returned.

So we really need to make sure callers always check the return value.

idr_preload() contract is to always disable preemption, so we need
to add a missing preempt_disable() if an error happened.

Similarly, ida_pre_get() only needs to call preempt_enable() in the
case no error happened.

Fixes: 0a835c4f ("Reimplement IDR and IDA using the radix tree")
Fixes: 7ad3d4d8

 ("ida: Move ida_bitmap to a percpu variable")
Signed-off-by: default avatarEric Dumazet <>
Cc: Matthew Wilcox <>
Cc: "Kirill A. Shutemov" <>
Cc: <>    [4.11+]
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 7c61bd69
......@@ -463,7 +463,7 @@ radix_tree_node_free(struct radix_tree_node *node)
* To make use of this facility, the radix tree must be initialised without
static int __radix_tree_preload(gfp_t gfp_mask, unsigned nr)
static __must_check int __radix_tree_preload(gfp_t gfp_mask, unsigned nr)
struct radix_tree_preload *rtp;
struct radix_tree_node *node;
......@@ -2104,7 +2104,8 @@ EXPORT_SYMBOL(radix_tree_tagged);
void idr_preload(gfp_t gfp_mask)
__radix_tree_preload(gfp_mask, IDR_PRELOAD_SIZE);
if (__radix_tree_preload(gfp_mask, IDR_PRELOAD_SIZE))
......@@ -2118,13 +2119,13 @@ EXPORT_SYMBOL(idr_preload);
int ida_pre_get(struct ida *ida, gfp_t gfp)
__radix_tree_preload(gfp, IDA_PRELOAD_SIZE);
* The IDA API has no preload_end() equivalent. Instead,
* ida_get_new() can return -EAGAIN, prompting the caller
* to return to the ida_pre_get() step.
if (!__radix_tree_preload(gfp, IDA_PRELOAD_SIZE))
if (!this_cpu_read(ida_bitmap)) {
struct ida_bitmap *bitmap = kmalloc(sizeof(*bitmap), gfp);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment