From: Bart Van Assche Date: Fri, 15 Jun 2018 22:20:42 +0000 (-0700) Subject: configfs: use kvasprintf() instead of open-coding it X-Git-Tag: v4.19~438^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=707c62352909a9be2453ae073e160de59d2d4a1f;p=platform%2Fkernel%2Flinux-rpi.git configfs: use kvasprintf() instead of open-coding it Signed-off-by: Bart Van Assche Signed-off-by: Christoph Hellwig --- diff --git a/fs/configfs/item.c b/fs/configfs/item.c index 88f266e..99d491c 100644 --- a/fs/configfs/item.c +++ b/fs/configfs/item.c @@ -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; @@ -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. */ @@ -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);