From patchwork Sun Jun 16 07:02:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 10997269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F7FE13AF for ; Sun, 16 Jun 2019 07:02:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81BD728774 for ; Sun, 16 Jun 2019 07:02:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75CC5287A2; Sun, 16 Jun 2019 07:02:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7EE928774 for ; Sun, 16 Jun 2019 07:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726069AbfFPHC0 (ORCPT ); Sun, 16 Jun 2019 03:02:26 -0400 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:26053 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbfFPHC0 (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 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Mike Christie --- 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);