Skip to content

Commit b58c4e9

Browse files
andy-shevrichardweinberger
authored andcommitted
hostfs: Use kasprintf() instead of fixed buffer formatting
Improve readability and maintainability by replacing a hardcoded string allocation and formatting by the use of the kasprintf() helper. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 35f3401 commit b58c4e9

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

fs/hostfs/hostfs_kern.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static char *inode_name(struct inode *ino)
139139

140140
static char *follow_link(char *link)
141141
{
142-
int len, n;
143142
char *name, *resolved, *end;
143+
int n;
144144

145145
name = __getname();
146146
if (!name) {
@@ -164,15 +164,13 @@ static char *follow_link(char *link)
164164
return name;
165165

166166
*(end + 1) = '\0';
167-
len = strlen(link) + strlen(name) + 1;
168167

169-
resolved = kmalloc(len, GFP_KERNEL);
168+
resolved = kasprintf(GFP_KERNEL, "%s%s", link, name);
170169
if (resolved == NULL) {
171170
n = -ENOMEM;
172171
goto out_free;
173172
}
174173

175-
sprintf(resolved, "%s%s", link, name);
176174
__putname(name);
177175
kfree(link);
178176
return resolved;
@@ -921,18 +919,16 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
921919
sb->s_d_op = &simple_dentry_operations;
922920
sb->s_maxbytes = MAX_LFS_FILESIZE;
923921

924-
/* NULL is printed as <NULL> by sprintf: avoid that. */
922+
/* NULL is printed as '(null)' by printf(): avoid that. */
925923
if (req_root == NULL)
926924
req_root = "";
927925

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

934-
sprintf(host_root_path, "%s/%s", root_ino, req_root);
935-
936932
root_inode = new_inode(sb);
937933
if (!root_inode)
938934
goto out;

0 commit comments

Comments
 (0)