Skip to content

Commit

Permalink
configfs: use kvasprintf() instead of open-coding it
Browse files Browse the repository at this point in the history
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Bart Van Assche authored and Christoph Hellwig committed Jun 19, 2018
1 parent ce397d2 commit 707c623
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions fs/configfs/item.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static void config_item_init(struct config_item *item)
*/
int config_item_set_name(struct config_item *item, const char *fmt, ...)
{
int error = 0;
int limit = CONFIGFS_ITEM_NAME_LEN;
int need;
va_list args;
Expand All @@ -79,25 +78,11 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
if (need < limit)
name = item->ci_namebuf;
else {
/*
* Need more space? Allocate it and try again
*/
limit = need + 1;
name = kmalloc(limit, GFP_KERNEL);
if (!name) {
error = -ENOMEM;
goto Done;
}
va_start(args, fmt);
need = vsnprintf(name, limit, fmt, args);
name = kvasprintf(GFP_KERNEL, fmt, args);
va_end(args);

/* Still? Give up. */
if (need >= limit) {
kfree(name);
error = -EFAULT;
goto Done;
}
if (!name)
return -EFAULT;
}

/* Free the old name, if necessary. */
Expand All @@ -106,8 +91,7 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)

/* Now, set the new name */
item->ci_name = name;
Done:
return error;
return 0;
}
EXPORT_SYMBOL(config_item_set_name);

Expand Down

0 comments on commit 707c623

Please sign in to comment.