From bb9d67ba859876373ee29ccfd9fa39b1c6fb87ed Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 31 May 2012 02:36:05 +0000 Subject: [PATCH] Use kasprintf() instead of kmalloc() + snprintf(). Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4330 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_pres.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index 8ddfafbf1..afd5c2d66 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -1212,32 +1212,25 @@ out_setfs: int scst_pr_init_dev(struct scst_device *dev) { int res = 0; - uint8_t q; - int name_len; TRACE_ENTRY(); - name_len = snprintf(&q, sizeof(q), "%s/%s", SCST_PR_DIR, dev->virt_name) + 1; - dev->pr_file_name = kmalloc(name_len, GFP_KERNEL); + dev->pr_file_name = kasprintf(GFP_KERNEL, "%s/%s", SCST_PR_DIR, + dev->virt_name); if (dev->pr_file_name == NULL) { PRINT_ERROR("Allocation of device '%s' file path failed", dev->virt_name); res = -ENOMEM; goto out; - } else - snprintf(dev->pr_file_name, name_len, "%s/%s", SCST_PR_DIR, - dev->virt_name); - - name_len = snprintf(&q, sizeof(q), "%s/%s.1", SCST_PR_DIR, dev->virt_name) + 1; - dev->pr_file_name1 = kmalloc(name_len, GFP_KERNEL); + } + dev->pr_file_name1 = kasprintf(GFP_KERNEL, "%s/%s.1", SCST_PR_DIR, + dev->virt_name); if (dev->pr_file_name1 == NULL) { PRINT_ERROR("Allocation of device '%s' backup file path failed", dev->virt_name); res = -ENOMEM; goto out_free_name; - } else - snprintf(dev->pr_file_name1, name_len, "%s/%s.1", SCST_PR_DIR, - dev->virt_name); + } #ifndef CONFIG_SCST_PROC res = scst_pr_check_pr_path();