Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4303025ybi; Tue, 18 Jun 2019 15:44:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk2FWim+mHxFJk3FjeEk/5Ih8JCykscXwjz7sEBWzmzgUD0ZdDyRx5X+31yjlTvAgvXBEF X-Received: by 2002:a17:90a:36e4:: with SMTP id t91mr7443378pjb.22.1560897879411; Tue, 18 Jun 2019 15:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560897879; cv=none; d=google.com; s=arc-20160816; b=YB0ufH9RbcDTjHOSkSftR81iASd2nCs+dD4ROvBYsZIfx5xZAVM+4SC5IR9U4TpVbk w1wmJgxXliwSO61wOw8AyCfVoiTLDqXfv/N/PgTk+YKp48kCrM8/dI2SZVJs/Lk0r59e Xq8DgCkpQRbY4f801kfQO92BxuvD2bhHlMB7NdV6p4aH1iqeFTYuj+VGwfMAU8nROKR5 2ntTT8tAougGp6H1smpNv8zh5EPhnl6J9N5Pck/YuYYWFrlj/YR6WCpvOYhjhNy2Ui0y kIKPGx8XobFcCCXz6arPUTazZb3nXrMMIriMGUP57tvp+xhB3bluovtbz+VaTfZUOto5 S/rQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject:reply-to; bh=FZxv6Njv8zCjUDztNDUQpNNPPQfXYY9BBECQXUqmRSk=; b=cra/qkav7VaZT1Pp5R+aDkmgB8XF+Ik8DuerE63z9wjouI9pO/FuHrqoQEj24CxzkL nydtVNtsYShXOlUybuLXepgmtiiL/wocla8ldTVuxBGcAtXj2cF51lUYoVMOSVg6p1ip rBln0JAdEMdeiheNqqC5r5tFWnxb7VzLBQmeKif35Zgcbl31iPY3lZRZ797dKOv/SR8F Uzs2Nah4xCJOousAohWzn2DN1oUR9L0WuoyA6eP26Sou/eg+hf8lLcYeYwwKw78oSnQz sLmYGsRxld4H2QkcSGEthfPc5i2t5KG60sFR9jW822Nt12DdJjmcbZzl2pyyz1Wax532 +MJg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5si1308980pgv.164.2019.06.18.15.44.04; Tue, 18 Jun 2019 15:44:39 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730555AbfFRWoA (ORCPT + 99 others); Tue, 18 Jun 2019 18:44:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58484 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730176AbfFRWoA (ORCPT ); Tue, 18 Jun 2019 18:44:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E361C308FC4E; Tue, 18 Jun 2019 22:43:59 +0000 (UTC) Received: from mchristi.msp.csb (unknown [10.64.242.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6903D5C1B5; Tue, 18 Jun 2019 22:43:58 +0000 (UTC) Reply-To: mchristi@redhat.com Subject: Re: [PATCH] scsi: tcmu: Simplify 'tcmu_update_uio_info()' To: Christophe JAILLET , 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 References: <20190616070220.24189-1-christophe.jaillet@wanadoo.fr> From: Michael Christie Organization: Red Hat Message-ID: <2ffa1964-30b1-d8bd-a2e2-608fe4f06f45@redhat.com> Date: Tue, 18 Jun 2019 17:43:57 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20190616070220.24189-1-christophe.jaillet@wanadoo.fr> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 18 Jun 2019 22:44:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/16/2019 02:02 AM, Christophe JAILLET wrote: > 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); > Thanks. Acked-by: Mike Christie