Skip to content

Commit 55580ad

Browse files
hac-vsmfrench
authored andcommitted
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 <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 2f6a4af commit 55580ad

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/smb/client/cached_dir.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,12 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
416416
if (cfids == NULL)
417417
return -EOPNOTSUPP;
418418

419+
if (!dentry)
420+
return -ENOENT;
421+
419422
spin_lock(&cfids->cfid_list_lock);
420423
list_for_each_entry(cfid, &cfids->entries, entry) {
421-
if (dentry && cfid->dentry == dentry) {
424+
if (cfid->dentry == dentry) {
422425
if (!is_valid_cached_dir(cfid))
423426
break;
424427
cifs_dbg(FYI, "found a cached file handle by dentry\n");

0 commit comments

Comments
 (0)