Merge tag 'fsnotify_for_v5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / fs / configfs / dir.c
index ba17881a8d84823e1ab8600ca86d57c3d823ee5e..92112915de8e752a1a9ae1b548513e41c7d0f7e4 100644 (file)
@@ -1,23 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* -*- mode: c; c-basic-offset: 8; -*-
  * vim: noexpandtab sw=8 ts=8 sts=0:
  *
  * dir.c - Operations for configfs directories.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- *
  * Based on sysfs:
  *     sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
  *
@@ -59,15 +45,13 @@ static void configfs_d_iput(struct dentry * dentry,
        if (sd) {
                /* Coordinate with configfs_readdir */
                spin_lock(&configfs_dirent_lock);
-               /* Coordinate with configfs_attach_attr where will increase
-                * sd->s_count and update sd->s_dentry to new allocated one.
-                * Only set sd->dentry to null when this dentry is the only
-                * sd owner.
-                * If not do so, configfs_d_iput may run just after
-                * configfs_attach_attr and set sd->s_dentry to null
-                * even it's still in use.
+               /*
+                * Set sd->s_dentry to null only when this dentry is the one
+                * that is going to be killed.  Otherwise configfs_d_iput may
+                * run just after configfs_attach_attr and set sd->s_dentry to
+                * NULL even it's still in use.
                 */
-               if (atomic_read(&sd->s_count) <= 2)
+               if (sd->s_dentry == dentry)
                        sd->s_dentry = NULL;
 
                spin_unlock(&configfs_dirent_lock);