@@ -332,7 +332,10 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
332332 parent = debugfs_mount -> mnt_root ;
333333
334334 inode_lock (d_inode (parent ));
335- dentry = lookup_one_len (name , parent , strlen (name ));
335+ if (unlikely (IS_DEADDIR (d_inode (parent ))))
336+ dentry = ERR_PTR (- ENOENT );
337+ else
338+ dentry = lookup_one_len (name , parent , strlen (name ));
336339 if (!IS_ERR (dentry ) && d_really_is_positive (dentry )) {
337340 if (d_is_dir (dentry ))
338341 pr_err ("Directory '%s' with parent '%s' already present!\n" ,
@@ -681,62 +684,15 @@ static void __debugfs_file_removed(struct dentry *dentry)
681684 wait_for_completion (& fsd -> active_users_drained );
682685}
683686
684- static int __debugfs_remove (struct dentry * dentry , struct dentry * parent )
685- {
686- int ret = 0 ;
687-
688- if (simple_positive (dentry )) {
689- dget (dentry );
690- if (d_is_dir (dentry )) {
691- ret = simple_rmdir (d_inode (parent ), dentry );
692- if (!ret )
693- fsnotify_rmdir (d_inode (parent ), dentry );
694- } else {
695- simple_unlink (d_inode (parent ), dentry );
696- fsnotify_unlink (d_inode (parent ), dentry );
697- }
698- if (!ret )
699- d_delete (dentry );
700- if (d_is_reg (dentry ))
701- __debugfs_file_removed (dentry );
702- dput (dentry );
703- }
704- return ret ;
705- }
706-
707- /**
708- * debugfs_remove - removes a file or directory from the debugfs filesystem
709- * @dentry: a pointer to a the dentry of the file or directory to be
710- * removed. If this parameter is NULL or an error value, nothing
711- * will be done.
712- *
713- * This function removes a file or directory in debugfs that was previously
714- * created with a call to another debugfs function (like
715- * debugfs_create_file() or variants thereof.)
716- *
717- * This function is required to be called in order for the file to be
718- * removed, no automatic cleanup of files will happen when a module is
719- * removed, you are responsible here.
720- */
721- void debugfs_remove (struct dentry * dentry )
687+ static void remove_one (struct dentry * victim )
722688{
723- struct dentry * parent ;
724- int ret ;
725-
726- if (IS_ERR_OR_NULL (dentry ))
727- return ;
728-
729- parent = dentry -> d_parent ;
730- inode_lock (d_inode (parent ));
731- ret = __debugfs_remove (dentry , parent );
732- inode_unlock (d_inode (parent ));
733- if (!ret )
734- simple_release_fs (& debugfs_mount , & debugfs_mount_count );
689+ if (d_is_reg (victim ))
690+ __debugfs_file_removed (victim );
691+ simple_release_fs (& debugfs_mount , & debugfs_mount_count );
735692}
736- EXPORT_SYMBOL_GPL (debugfs_remove );
737693
738694/**
739- * debugfs_remove_recursive - recursively removes a directory
695+ * debugfs_remove - recursively removes a directory
740696 * @dentry: a pointer to a the dentry of the directory to be removed. If this
741697 * parameter is NULL or an error value, nothing will be done.
742698 *
@@ -748,65 +704,16 @@ EXPORT_SYMBOL_GPL(debugfs_remove);
748704 * removed, no automatic cleanup of files will happen when a module is
749705 * removed, you are responsible here.
750706 */
751- void debugfs_remove_recursive (struct dentry * dentry )
707+ void debugfs_remove (struct dentry * dentry )
752708{
753- struct dentry * child , * parent ;
754-
755709 if (IS_ERR_OR_NULL (dentry ))
756710 return ;
757711
758- parent = dentry ;
759- down :
760- inode_lock (d_inode (parent ));
761- loop :
762- /*
763- * The parent->d_subdirs is protected by the d_lock. Outside that
764- * lock, the child can be unlinked and set to be freed which can
765- * use the d_u.d_child as the rcu head and corrupt this list.
766- */
767- spin_lock (& parent -> d_lock );
768- list_for_each_entry (child , & parent -> d_subdirs , d_child ) {
769- if (!simple_positive (child ))
770- continue ;
771-
772- /* perhaps simple_empty(child) makes more sense */
773- if (!list_empty (& child -> d_subdirs )) {
774- spin_unlock (& parent -> d_lock );
775- inode_unlock (d_inode (parent ));
776- parent = child ;
777- goto down ;
778- }
779-
780- spin_unlock (& parent -> d_lock );
781-
782- if (!__debugfs_remove (child , parent ))
783- simple_release_fs (& debugfs_mount , & debugfs_mount_count );
784-
785- /*
786- * The parent->d_lock protects agaist child from unlinking
787- * from d_subdirs. When releasing the parent->d_lock we can
788- * no longer trust that the next pointer is valid.
789- * Restart the loop. We'll skip this one with the
790- * simple_positive() check.
791- */
792- goto loop ;
793- }
794- spin_unlock (& parent -> d_lock );
795-
796- inode_unlock (d_inode (parent ));
797- child = parent ;
798- parent = parent -> d_parent ;
799- inode_lock (d_inode (parent ));
800-
801- if (child != dentry )
802- /* go up */
803- goto loop ;
804-
805- if (!__debugfs_remove (child , parent ))
806- simple_release_fs (& debugfs_mount , & debugfs_mount_count );
807- inode_unlock (d_inode (parent ));
712+ simple_pin_fs (& debug_fs_type , & debugfs_mount , & debugfs_mount_count );
713+ simple_recursive_removal (dentry , remove_one );
714+ simple_release_fs (& debugfs_mount , & debugfs_mount_count );
808715}
809- EXPORT_SYMBOL_GPL (debugfs_remove_recursive );
716+ EXPORT_SYMBOL_GPL (debugfs_remove );
810717
811718/**
812719 * debugfs_rename - rename a file/directory in the debugfs filesystem
0 commit comments