Skip to content

Commit d1a0919

Browse files
dmantipovpcmoore
authored andcommitted
securityfs: use kstrdup_const() to manage symlink targets
Since 'target' argument of 'securityfs_create_symlink()' is (for now at least) a compile-time constant, it may be reasonable to use 'kstrdup_const()' / 'kree_const()' to manage 'i_link' member of the corresponding inode in attempt to reuse .rodata instance rather than making a copy. Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent fe3c03b commit d1a0919

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

security/inode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int mount_count;
3030
static void securityfs_free_inode(struct inode *inode)
3131
{
3232
if (S_ISLNK(inode->i_mode))
33-
kfree(inode->i_link);
33+
kfree_const(inode->i_link);
3434
free_inode_nonrcu(inode);
3535
}
3636

@@ -258,17 +258,17 @@ struct dentry *securityfs_create_symlink(const char *name,
258258
const struct inode_operations *iops)
259259
{
260260
struct dentry *dent;
261-
char *link = NULL;
261+
const char *link = NULL;
262262

263263
if (target) {
264-
link = kstrdup(target, GFP_KERNEL);
264+
link = kstrdup_const(target, GFP_KERNEL);
265265
if (!link)
266266
return ERR_PTR(-ENOMEM);
267267
}
268268
dent = securityfs_create_dentry(name, S_IFLNK | 0444, parent,
269-
link, NULL, iops);
269+
(void *)link, NULL, iops);
270270
if (IS_ERR(dent))
271-
kfree(link);
271+
kfree_const(link);
272272

273273
return dent;
274274
}

0 commit comments

Comments
 (0)