]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
scsi: tcmu: Simplify tcmu_update_uio_info()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 16 Jun 2019 07:02:20 +0000 (09:02 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 20 Jun 2019 19:37:02 +0000 (15:37 -0400)
Use 'kasprintf()' instead of:
   - snprintf(NULL, 0...
   - kmalloc(...
   - snprintf(...

This is less verbose and saves 7 bytes (i.e. the space for '/(null)') if
'udev->dev_config' is NULL.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/target_core_user.c

index 40b29ca5a98d00d040e0f592da11af438d747abd..9dbd0db64328dc204ec7afa93fc432221e6484ff 100644 (file)
@@ -1836,20 +1836,18 @@ static int tcmu_update_uio_info(struct tcmu_dev *udev)
 {
        struct tcmu_hba *hba = udev->hba->hba_ptr;
        struct uio_info *info;
-       size_t size, used;
        char *str;
 
        info = &udev->uio_info;
-       size = snprintf(NULL, 0, "tcm-user/%u/%s/%s", hba->host_id, udev->name,
-                       udev->dev_config);
-       size += 1; /* for \0 */
-       str = kmalloc(size, GFP_KERNEL);
-       if (!str)
-               return -ENOMEM;
 
-       used = snprintf(str, size, "tcm-user/%u/%s", hba->host_id, udev->name);
        if (udev->dev_config[0])
-               snprintf(str + used, size - used, "/%s", udev->dev_config);
+               str = kasprintf(GFP_KERNEL, "tcm-user/%u/%s/%s", hba->host_id,
+                               udev->name, udev->dev_config);
+       else
+               str = kasprintf(GFP_KERNEL, "tcm-user/%u/%s", hba->host_id,
+                               udev->name);
+       if (!str)
+               return -ENOMEM;
 
        /* If the old string exists, free it */
        kfree(info->name);