inotify: convert inotify_add_to_idr() to use idr_alloc_cyclic()
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / notify / inotify / inotify_user.c
index 228a2c2..8562bd3 100644 (file)
@@ -359,27 +359,23 @@ static int inotify_find_inode(const char __user *dirname, struct path *path, uns
 }
 
 static int inotify_add_to_idr(struct idr *idr, spinlock_t *idr_lock,
-                             int *last_wd,
                              struct inotify_inode_mark *i_mark)
 {
        int ret;
 
-       do {
-               if (unlikely(!idr_pre_get(idr, GFP_KERNEL)))
-                       return -ENOMEM;
+       idr_preload(GFP_KERNEL);
+       spin_lock(idr_lock);
 
-               spin_lock(idr_lock);
-               ret = idr_get_new_above(idr, i_mark, *last_wd + 1,
-                                       &i_mark->wd);
+       ret = idr_alloc_cyclic(idr, i_mark, 1, 0, GFP_NOWAIT);
+       if (ret >= 0) {
                /* we added the mark to the idr, take a reference */
-               if (!ret) {
-                       *last_wd = i_mark->wd;
-                       fsnotify_get_mark(&i_mark->fsn_mark);
-               }
-               spin_unlock(idr_lock);
-       } while (ret == -EAGAIN);
+               i_mark->wd = ret;
+               fsnotify_get_mark(&i_mark->fsn_mark);
+       }
 
-       return ret;
+       spin_unlock(idr_lock);
+       idr_preload_end();
+       return ret < 0 ? ret : 0;
 }
 
 static struct inotify_inode_mark *inotify_idr_find_locked(struct fsnotify_group *group,
@@ -576,8 +572,6 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
 
        /* don't allow invalid bits: we don't want flags set */
        mask = inotify_arg_to_mask(arg);
-       if (unlikely(!(mask & IN_ALL_EVENTS)))
-               return -EINVAL;
 
        fsn_mark = fsnotify_find_inode_mark(group, inode);
        if (!fsn_mark)
@@ -629,8 +623,6 @@ static int inotify_new_watch(struct fsnotify_group *group,
 
        /* don't allow invalid bits: we don't want flags set */
        mask = inotify_arg_to_mask(arg);
-       if (unlikely(!(mask & IN_ALL_EVENTS)))
-               return -EINVAL;
 
        tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
        if (unlikely(!tmp_i_mark))
@@ -644,8 +636,7 @@ static int inotify_new_watch(struct fsnotify_group *group,
        if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches)
                goto out_err;
 
-       ret = inotify_add_to_idr(idr, idr_lock, &group->inotify_data.last_wd,
-                                tmp_i_mark);
+       ret = inotify_add_to_idr(idr, idr_lock, tmp_i_mark);
        if (ret)
                goto out_err;
 
@@ -703,7 +694,6 @@ static struct fsnotify_group *inotify_new_group(unsigned int max_events)
 
        spin_lock_init(&group->inotify_data.idr_lock);
        idr_init(&group->inotify_data.idr);
-       group->inotify_data.last_wd = 0;
        group->inotify_data.user = get_current_user();
 
        if (atomic_inc_return(&group->inotify_data.user->inotify_devs) >