Skip to content

Commit

Permalink
hostfs: Use kasprintf() instead of fixed buffer formatting
Browse files Browse the repository at this point in the history
Improve readability and maintainability by replacing a hardcoded string
allocation and formatting by the use of the kasprintf() helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
Andy Shevchenko authored and Richard Weinberger committed Mar 29, 2020
1 parent 35f3401 commit b58c4e9
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions fs/hostfs/hostfs_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ static char *inode_name(struct inode *ino)

static char *follow_link(char *link)
{
int len, n;
char *name, *resolved, *end;
int n;

name = __getname();
if (!name) {
Expand All @@ -164,15 +164,13 @@ static char *follow_link(char *link)
return name;

*(end + 1) = '\0';
len = strlen(link) + strlen(name) + 1;

resolved = kmalloc(len, GFP_KERNEL);
resolved = kasprintf(GFP_KERNEL, "%s%s", link, name);
if (resolved == NULL) {
n = -ENOMEM;
goto out_free;
}

sprintf(resolved, "%s%s", link, name);
__putname(name);
kfree(link);
return resolved;
Expand Down Expand Up @@ -921,18 +919,16 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
sb->s_d_op = &simple_dentry_operations;
sb->s_maxbytes = MAX_LFS_FILESIZE;

/* NULL is printed as <NULL> by sprintf: avoid that. */
/* NULL is printed as '(null)' by printf(): avoid that. */
if (req_root == NULL)
req_root = "";

err = -ENOMEM;
sb->s_fs_info = host_root_path =
kmalloc(strlen(root_ino) + strlen(req_root) + 2, GFP_KERNEL);
kasprintf(GFP_KERNEL, "%s/%s", root_ino, req_root);
if (host_root_path == NULL)
goto out;

sprintf(host_root_path, "%s/%s", root_ino, req_root);

root_inode = new_inode(sb);
if (!root_inode)
goto out;
Expand Down

0 comments on commit b58c4e9

Please sign in to comment.