If we're recycling a previously used struct ida_bitmap, it ended up in ->free_bitmap precisely because it was all zeroes. Thus, by using kzalloc in ida_pre_get we can avoid doing the memset while holding whatever locks protects the ida (which, judging by the number of callers of ida_simple_get vs ida_get_new_above, is usually always the global simple_ida_lock).
Signed-off-by: Rasmus Villemoes <[email protected]> --- lib/idr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 6098336df267..9cbfae251d77 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -903,7 +903,7 @@ int ida_pre_get(struct ida *ida, gfp_t gfp_mask) if (!ida->free_bitmap) { struct ida_bitmap *bitmap; - bitmap = kmalloc(sizeof(struct ida_bitmap), gfp_mask); + bitmap = kzalloc(sizeof(struct ida_bitmap), gfp_mask); if (!bitmap) return 0; @@ -962,7 +962,6 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) if (!bitmap) return -EAGAIN; - memset(bitmap, 0, sizeof(struct ida_bitmap)); rcu_assign_pointer(pa[0]->ary[idr_id & IDR_MASK], (void *)bitmap); pa[0]->count++; -- 2.1.4

