Skip to content

Commit

Permalink
proc: fold kmalloc() + strcpy() into kmemdup()
Browse files Browse the repository at this point in the history
strcpy() will recalculate string length second time which is
unnecessary in this case.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Link: https://lore.kernel.org/r/90af27c1-0b86-47a6-a6c8-61a58b8aa747@p183
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Alexey Dobriyan authored and Christian Brauner committed Sep 9, 2024
1 parent d80b065 commit 4ad5f9a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/proc/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ struct proc_dir_entry *proc_symlink(const char *name,
(S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1);

if (ent) {
ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
ent->size = strlen(dest);
ent->data = kmemdup(dest, ent->size + 1, GFP_KERNEL);
if (ent->data) {
strcpy((char*)ent->data,dest);
ent->proc_iops = &proc_link_inode_operations;
ent = proc_register(parent, ent);
} else {
Expand Down

0 comments on commit 4ad5f9a

Please sign in to comment.