From 55580ad027a6764b7b1ee75f537d67811a06307f Mon Sep 17 00:00:00 2001 From: Henrique Carvalho Date: Thu, 18 Sep 2025 18:39:51 -0300 Subject: [PATCH] smb: client: short-circuit in open_cached_dir_by_dentry() if !dentry When dentry is NULL, the current code acquires the spinlock and traverses the entire list, but the condition (dentry && cfid->dentry == dentry) ensures no match will ever be found. Return -ENOENT early in this case, avoiding unnecessary lock acquisition and list traversal. Signed-off-by: Henrique Carvalho Signed-off-by: Steve French --- fs/smb/client/cached_dir.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c index 03bfb919ad477..b36f9f9340f00 100644 --- a/fs/smb/client/cached_dir.c +++ b/fs/smb/client/cached_dir.c @@ -416,9 +416,12 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon, if (cfids == NULL) return -EOPNOTSUPP; + if (!dentry) + return -ENOENT; + spin_lock(&cfids->cfid_list_lock); list_for_each_entry(cfid, &cfids->entries, entry) { - if (dentry && cfid->dentry == dentry) { + if (cfid->dentry == dentry) { if (!is_valid_cached_dir(cfid)) break; cifs_dbg(FYI, "found a cached file handle by dentry\n"); -- 2.47.3