From: Michael Christie <mchristi@redhat.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
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
Subject: Re: [PATCH] scsi: tcmu: Simplify 'tcmu_update_uio_info()'
Date: Tue, 18 Jun 2019 17:43:57 -0500 [thread overview]
Message-ID: <2ffa1964-30b1-d8bd-a2e2-608fe4f06f45@redhat.com> (raw)
In-Reply-To: <20190616070220.24189-1-christophe.jaillet@wanadoo.fr>
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 <christophe.jaillet@wanadoo.fr>
> ---
> 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 <mchristi@redhat.com>
next prev parent reply other threads:[~2019-06-18 22:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-16 7:02 Christophe JAILLET
2019-06-18 22:43 ` Michael Christie [this message]
2019-06-19 1:10 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2ffa1964-30b1-d8bd-a2e2-608fe4f06f45@redhat.com \
--to=mchristi@redhat.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome