*/
 void __fput_sync(struct file *file)
 {
-       if (atomic_long_dec_and_test(&file->f_count)) {
-               struct task_struct *task = current;
-               BUG_ON(!(task->flags & PF_KTHREAD));
+       if (atomic_long_dec_and_test(&file->f_count))
                __fput(file);
-       }
 }
 
 EXPORT_SYMBOL(fput);
 
  * "id" is the POSIX thread ID. We use the
  * files pointer for this..
  */
-int filp_close(struct file *filp, fl_owner_t id)
+static int filp_flush(struct file *filp, fl_owner_t id)
 {
        int retval = 0;
 
                dnotify_flush(filp, id);
                locks_remove_posix(filp, id);
        }
-       fput(filp);
        return retval;
 }
 
+int filp_close(struct file *filp, fl_owner_t id)
+{
+       int retval;
+
+       retval = filp_flush(filp, id);
+       fput(filp);
+
+       return retval;
+}
 EXPORT_SYMBOL(filp_close);
 
 /*
  */
 SYSCALL_DEFINE1(close, unsigned int, fd)
 {
-       int retval = close_fd(fd);
+       int retval;
+       struct file *file;
+
+       file = close_fd_get_file(fd);
+       if (!file)
+               return -EBADF;
+
+       retval = filp_flush(file, current->files);
+
+       /*
+        * We're returning to user space. Don't bother
+        * with any delayed fput() cases.
+        */
+       __fput_sync(file);
 
        /* can't restart close syscall because file table entry was cleared */
        if (unlikely(retval == -ERESTARTSYS ||