[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251118134129.100224-1-thorsten.blum@linux.dev>
Date: Tue, 18 Nov 2025 14:41:28 +0100
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: Ian Kent <raven@...maw.net>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
autofs@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] autofs: replace manual symlink buffer allocation in autofs_dir_symlink
The symlink name was previously duplicated using an explicit kmalloc()
followed by strcpy(), which is deprecated [1]. Replace this open-coded
string duplication with kstrdup(), which allocates and copies the
symlink name with a single helper function.
Remove the local variable 'size' and set 'i_size' directly using
strlen(cp), which is equivalent to the previous value of 'size'.
This simplifies the code, uses common string-handling helpers, and
removes the deprecated use of strcpy().
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
---
fs/autofs/root.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 174c7205fee4..36b7b34d23b5 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -7,6 +7,7 @@
#include <linux/capability.h>
#include <linux/compat.h>
+#include <linux/string.h>
#include "autofs_i.h"
@@ -570,7 +571,6 @@ static int autofs_dir_symlink(struct mnt_idmap *idmap,
struct autofs_info *ino = autofs_dentry_ino(dentry);
struct autofs_info *p_ino;
struct inode *inode;
- size_t size = strlen(symname);
char *cp;
pr_debug("%s <- %pd\n", symname, dentry);
@@ -581,19 +581,17 @@ static int autofs_dir_symlink(struct mnt_idmap *idmap,
autofs_del_active(dentry);
- cp = kmalloc(size + 1, GFP_KERNEL);
+ cp = kstrdup(symname, GFP_KERNEL);
if (!cp)
return -ENOMEM;
- strcpy(cp, symname);
-
inode = autofs_get_inode(dir->i_sb, S_IFLNK | 0555);
if (!inode) {
kfree(cp);
return -ENOMEM;
}
inode->i_private = cp;
- inode->i_size = size;
+ inode->i_size = strlen(cp);
d_add(dentry, inode);
dget(dentry);
--
2.51.1
Powered by blists - more mailing lists