* [PATCH] net/mlx5: Use kasprintf instead of hand-writing it
@ 2021-04-17 7:16 Christophe JAILLET
2021-04-18 20:03 ` Bart Van Assche
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2021-04-17 7:16 UTC (permalink / raw)
To: saeedm, leon, davem, kuba
Cc: netdev, linux-rdma, linux-kernel, kernel-janitors, Christophe JAILLET
'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)
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net/mlx5: Use kasprintf instead of hand-writing it
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
2021-04-18 21:28 ` Christophe JAILLET
0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2021-04-18 20:03 UTC (permalink / raw)
To: Christophe JAILLET, saeedm, leon, davem, kuba
Cc: netdev, linux-rdma, linux-kernel, kernel-janitors
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/mlx5: Use kasprintf instead of hand-writing it
2021-04-18 20:03 ` Bart Van Assche
@ 2021-04-18 21:28 ` Christophe JAILLET
0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2021-04-18 21:28 UTC (permalink / raw)
To: Bart Van Assche, saeedm, leon, davem, kuba
Cc: netdev, linux-rdma, linux-kernel, kernel-janitors
Le 18/04/2021 à 22:03, Bart Van Assche a écrit :
> 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.
>
Agreed. I've sent another patch serie which is more elegant.
Thanks for the feedback.
CJ
> Thanks,
>
> Bart.
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-18 21:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-04-18 21:28 ` Christophe JAILLET
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.