Skip to contentSkip to conversation

ksmbd: Use scope-based resource management in ksmbd_validate_name_reconnect()

PATCH New Markus Elfring 1 participant 1 message Oct 4, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: Use scope-based resource management in ksmbd_validate_name_reconnect()

From: Markus Elfring <[email protected]>
Date: Sat, 4 Oct 2025 13:27:12 +0200

Scope-based resource management became supported for some programming interfaces by contributions of Peter Zijlstra on 2023-05-26. See also the commit 54da6a0924311c7cf5015533991e44fb8eb12773 ("locking:
Introduce __cleanup() based infrastructure").

* Thus use the attribute “__free(kfree)”.

* Reduce the scope for the local variable “ab_pathname”.

* Omit two kfree() calls accordingly.

* Return status codes directly without using an intermediate variable.

---
 fs/smb/server/vfs_cache.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
fs/smb/server/vfs_cache.c +6 -11
index dfed6fce8904..af8a16879b88 100644
@@ -933,27 +933,22 @@ void ksmbd_free_global_file_table(void)
 int ksmbd_validate_name_reconnect(struct ksmbd_share_config *share,
 				  struct ksmbd_file *fp, char *name)
 {
-	char *pathname, *ab_pathname;
-	int ret = 0;
+	char *pathname __free(kfree) = kmalloc(PATH_MAX, KSMBD_DEFAULT_GFP);
 
-	pathname = kmalloc(PATH_MAX, KSMBD_DEFAULT_GFP);
 	if (!pathname)
 		return -EACCES;
 
-	ab_pathname = d_path(&fp->filp->f_path, pathname, PATH_MAX);
-	if (IS_ERR(ab_pathname)) {
-		kfree(pathname);
+	char *ab_pathname = d_path(&fp->filp->f_path, pathname, PATH_MAX);
+
+	if (IS_ERR(ab_pathname))
 		return -EACCES;
-	}
 
 	if (name && strcmp(&ab_pathname[share->path_sz + 1], name)) {
 		ksmbd_debug(SMB, "invalid name reconnect %s\n", name);
-		ret = -EINVAL;
+		return -EINVAL;
 	}
 
-	kfree(pathname);
-
-	return ret;
+	return 0;
 }
 
 int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp)
Signature · 1 line
2.51.0