debugfs: simplify __debugfs_remove_file() [Linux 5.3]

This Linux kernel change "debugfs: simplify __debugfs_remove_file()" is included in the Linux 5.3 release. This change is authored by Amir Goldstein <amir73il [at] gmail.com> on Sun May 26 17:34:07 2019 +0300. The commit for this change in Linux stable tree is 823e545 (patch).

debugfs: simplify __debugfs_remove_file()

Move simple_unlink()+d_delete() from __debugfs_remove_file() into
caller __debugfs_remove() and rename helper for post remove file to
__debugfs_file_removed().

This will simplify adding fsnotify_unlink() hook.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>

There are 20 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/debugfs/inode.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index acef14ad5..d89874d 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -617,13 +617,10 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);

-static void __debugfs_remove_file(struct dentry *dentry, struct dentry *parent)
+static void __debugfs_file_removed(struct dentry *dentry)
 {
    struct debugfs_fsdata *fsd;

-   simple_unlink(d_inode(parent), dentry);
-   d_delete(dentry);
-
    /*
     * Paired with the closing smp_mb() implied by a successful
     * cmpxchg() in debugfs_file_get(): either
@@ -644,16 +641,15 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)

    if (simple_positive(dentry)) {
        dget(dentry);
-       if (!d_is_reg(dentry)) {
-           if (d_is_dir(dentry))
-               ret = simple_rmdir(d_inode(parent), dentry);
-           else
-               simple_unlink(d_inode(parent), dentry);
-           if (!ret)
-               d_delete(dentry);
+       if (d_is_dir(dentry)) {
+           ret = simple_rmdir(d_inode(parent), dentry);
        } else {
-           __debugfs_remove_file(dentry, parent);
+           simple_unlink(d_inode(parent), dentry);
        }
+       if (!ret)
+           d_delete(dentry);
+       if (d_is_reg(dentry))
+           __debugfs_file_removed(dentry);
        dput(dentry);
    }
    return ret;

Leave a Reply

Your email address will not be published. Required fields are marked *