From: Markus Elfring <Markus.Elfring@web.de>
To: linux-cifs@vger.kernel.org, Namjae Jeon <linkinjeon@kernel.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Steve French <smfrench@gmail.com>, Tom Talpey <tom@talpey.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org, Neil Brown <neil@brown.name>,
Stefan Metzmacher <metze@samba.org>
Subject: [PATCH] ksmbd: Use scope-based resource management in ksmbd_validate_name_reconnect()
Date: Sat, 4 Oct 2025 13:36:54 +0200 [thread overview]
Message-ID: <1abbfe84-e3f1-4163-9789-6ec49a3ce821@web.de> (raw)
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
reply other threads:[~2025-10-04 11:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1abbfe84-e3f1-4163-9789-6ec49a3ce821@web.de \
--to=markus.elfring@web.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=metze@samba.org \
--cc=neil@brown.name \
--cc=senozhatsky@chromium.org \
--cc=smfrench@gmail.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).