Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1228800ybi; Sun, 16 Jun 2019 00:04:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcwu07vXlMA37BsVLbBryP3VY5Z7jKrx3er/xVIuqhOq8xqPYF4keTptsHjdCOPIZm0VMA X-Received: by 2002:a17:902:8d91:: with SMTP id v17mr82773704plo.91.1560668656557; Sun, 16 Jun 2019 00:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560668656; cv=none; d=google.com; s=arc-20160816; b=JFctFDOMfAufqhpecUY2AfyE5t3L6B/byGXt+vp/SuhmvdXg7V+U3Pmq+8mDpafAUA RBasK6ETQ123R2FTgGtuXz6Qi7Evx8hJoNw23ExzfDG54LbddV6ixquDXUcd+Ww4NuFd bJ0pvYzMbWmi9lPP/lbO/z1W7kL/0GTiwmdjadhbngEuRKDfVNvC75WoUcpycZY2ThYF +Z+YOZUcKgJoRDRK8+hwNWCrP4Xvwx4tChxUodeAgOTtLVww1GkqInYtKCs4vJzk3UJI j/Bx7wNEeL6jvGEwmRE+dXSltBvYN9C3I9VVza9kI/i9+5NLch2TXTkhur2Pm3Aqf8Wh /OCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=23HU+n0w+lsRBugvLT4Whc5mhEo0MvKHBTSUUlQes3c=; b=XntvfKbWSxWOCG9/PFVhOvgsvE8VH3YVyuFDYN2ckTDGp/6lRz+PqM6L37REDsNWVV bXJVXwCim6sSwpn6roev0yzJx4gfhD2uzPgSRElixXpBgOP7UOyG0Du1IA4GPA4ZGWlc y/GQ1IXPTHVLlz6C5rcDnRYu1OsYj7xXvWbxjn42Fe1H7Ha9JqjeACnC0iEQjs87qTcD tXggH4E2vVLzJ0sDfD2NHihbjIxxY0OiiDAWF9l0UzY8I115SucfiPeDIz1q1Di6HVFz v3Pqi+uZgZHhYBsR28p8x50ul8QlQ0umUry12PLhCWTZdBuqlCf5WL1Dnom93Gl6Mr45 YWbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32si6835126plc.152.2019.06.16.00.04.01; Sun, 16 Jun 2019 00:04:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726154AbfFPHC0 (ORCPT + 99 others); Sun, 16 Jun 2019 03:02:26 -0400 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:33193 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbfFPHC0 (ORCPT ); Sun, 16 Jun 2019 03:02:26 -0400 Received: from localhost.localdomain ([86.243.180.47]) by mwinf5d17 with ME id RK2N2000C11lVym03K2NQE; Sun, 16 Jun 2019 09:02:23 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 16 Jun 2019 09:02:23 +0200 X-ME-IP: 86.243.180.47 From: Christophe JAILLET To: martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] scsi: tcmu: Simplify 'tcmu_update_uio_info()' Date: Sun, 16 Jun 2019 09:02:20 +0200 Message-Id: <20190616070220.24189-1-christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/target/target_core_user.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index b43d6385a1a0..04eda111920e 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1824,20 +1824,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); -- 2.20.1