From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/smb/server/vfs_cache.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c
index dfed6fce8904..af8a16879b88 100644
--- a/fs/smb/server/vfs_cache.c
+++ b/fs/smb/server/vfs_cache.c
@@ -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)
--
2.51.0