[PATCH] fs/dcache: prevent repeated locking

From: cgel . zte
Date: Tue Dec 07 2021 - 05:17:06 EST


From: Lv Ruyi <lv.ruyi@xxxxxxxxxx>

Move the spin_lock above the restart to prevent to lock twice
when the code goto restart.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: Lv Ruyi <lv.ruyi@xxxxxxxxxx>
---
fs/dcache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index c84269c6e8bf..8580d51b397a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1102,8 +1102,8 @@ struct dentry *d_find_alias_rcu(struct inode *inode)
void d_prune_aliases(struct inode *inode)
{
struct dentry *dentry;
-restart:
spin_lock(&inode->i_lock);
+restart:
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
spin_lock(&dentry->d_lock);
if (!dentry->d_lockref.count) {
--
2.25.1