Message ID | 46235ec010551d2788483ce636686a61345e40ba.1618643703.git.christophe.jaillet@wanadoo.fr (mailing list archive) |
---|---|
State | Awaiting Upstream |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net/mlx5: Use kasprintf instead of hand-writing it | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Guessed tree name to be net-next |
netdev/subject_prefix | warning | Target tree name not specified in the subject |
netdev/cc_maintainers | success | CCed 6 of 6 maintainers |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 13 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
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.
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. > > >
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)
'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(-)