Commit 4542da631ad210716d097aa803a0828f9fed5e87
Committed by
Linus Torvalds
1 parent
2a86b3e74f
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
inotify: convert to idr_alloc()
Convert to the much saner new idr interface. Note that the adhoc cyclic id allocation is buggy. If wraparound happens, the previous code with idr_get_new_above() may segfault and the converted code will trigger WARN and return -EINVAL. Even if it's fixed to wrap to zero, the code will be prone to unnecessary -ENOSPC failures after the first wraparound. We probably need to implement proper cyclic support in idr. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: John McCutchan <john@johnmccutchan.com> Cc: Robert Love <rlove@rlove.org> Cc: Eric Paris <eparis@parisplace.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 11 additions and 13 deletions Side-by-side Diff
fs/notify/inotify/inotify_user.c
... | ... | @@ -364,22 +364,20 @@ |
364 | 364 | { |
365 | 365 | int ret; |
366 | 366 | |
367 | - do { | |
368 | - if (unlikely(!idr_pre_get(idr, GFP_KERNEL))) | |
369 | - return -ENOMEM; | |
367 | + idr_preload(GFP_KERNEL); | |
368 | + spin_lock(idr_lock); | |
370 | 369 | |
371 | - spin_lock(idr_lock); | |
372 | - ret = idr_get_new_above(idr, i_mark, *last_wd + 1, | |
373 | - &i_mark->wd); | |
370 | + ret = idr_alloc(idr, i_mark, *last_wd + 1, 0, GFP_NOWAIT); | |
371 | + if (ret >= 0) { | |
374 | 372 | /* we added the mark to the idr, take a reference */ |
375 | - if (!ret) { | |
376 | - *last_wd = i_mark->wd; | |
377 | - fsnotify_get_mark(&i_mark->fsn_mark); | |
378 | - } | |
379 | - spin_unlock(idr_lock); | |
380 | - } while (ret == -EAGAIN); | |
373 | + i_mark->wd = ret; | |
374 | + *last_wd = i_mark->wd; | |
375 | + fsnotify_get_mark(&i_mark->fsn_mark); | |
376 | + } | |
381 | 377 | |
382 | - return ret; | |
378 | + spin_unlock(idr_lock); | |
379 | + idr_preload_end(); | |
380 | + return ret < 0 ? ret : 0; | |
383 | 381 | } |
384 | 382 | |
385 | 383 | static struct inotify_inode_mark *inotify_idr_find_locked(struct fsnotify_group *group, |