linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	saeedm@nvidia.com, leon@kernel.org, davem@davemloft.net,
	kuba@kernel.org
Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] net/mlx5: Use kasprintf instead of hand-writing it
Date: Sun, 18 Apr 2021 13:03:53 -0700	[thread overview]
Message-ID: <131988e1-2327-99f8-95e1-778d653c36ec@acm.org> (raw)
In-Reply-To: <46235ec010551d2788483ce636686a61345e40ba.1618643703.git.christophe.jaillet@wanadoo.fr>

On 4/17/21 12:16 AM, Christophe JAILLET wrote:
> 'kasprintf()' can replace a kmalloc/strcpy/strcat sequence.
> It is less verbose and avoid the use of a magic number (64).
> 
> Anyway, the underlying 'alloc_workqueue()' would only keep the 24 first
> chars (i.e. sizeof(struct workqueue_struct->name) = WQ_NAME_LEN).
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/health.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
> index 9ff163c5bcde..a5383e701b4b 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
> @@ -802,12 +802,10 @@ int mlx5_health_init(struct mlx5_core_dev *dev)
>  	mlx5_fw_reporters_create(dev);
>  
>  	health = &dev->priv.health;
> -	name = kmalloc(64, GFP_KERNEL);
> +	name = kasprintf(GFP_KERNEL, "mlx5_health%s", dev_name(dev->device));
>  	if (!name)
>  		goto out_err;
>  
> -	strcpy(name, "mlx5_health");
> -	strcat(name, dev_name(dev->device));
>  	health->wq = create_singlethread_workqueue(name);
>  	kfree(name);
>  	if (!health->wq)

Instead of modifying the mlx5 driver, please change the definition of
the create_singlethread_workqueue() such that it accept a format
specifier and a variable number of arguments.

Thanks,

Bart.



  reply	other threads:[~2021-04-18 20:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-17  7:16 [PATCH] net/mlx5: Use kasprintf instead of hand-writing it Christophe JAILLET
2021-04-18 20:03 ` Bart Van Assche [this message]
2021-04-18 21:28   ` Christophe JAILLET

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=131988e1-2327-99f8-95e1-778d653c36ec@acm.org \
    --to=bvanassche@acm.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    /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;
as well as URLs for NNTP newsgroup(s).