All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
@ 2018-05-10 11:26 ` Christophe JAILLET
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe JAILLET @ 2018-05-10 11:26 UTC (permalink / raw)
  To: jiri, idosch, davem
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

Resources are not freed in the reverse order of the allocation.
Labels are also mixed-up.

Fix it and reorder code and labels in the error handling path of
'mlxsw_core_bus_device_register()'

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Please review carefully. This patch is proposed because it triggers one of
my coccinelle scripts. I'm not 100% sure if correct.

The script tries to spot wrongly ordered error handling path. It is:
@@
identifier l1, l2;
@@

   if (...) {
      ...
*     goto l1;
   }
   ...
   if (...) {
      ...
*     goto l2;
   }
   ...
*l1:
   ...
*l2:
   ...
---
 drivers/net/ethernet/mellanox/mlxsw/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
index 93ea56620a24..e13ac3b8dff7 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
@@ -1100,11 +1100,11 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
 err_alloc_lag_mapping:
 	mlxsw_ports_fini(mlxsw_core);
 err_ports_init:
-	mlxsw_bus->fini(bus_priv);
-err_bus_init:
 	if (!reload)
 		devlink_resources_unregister(devlink, NULL);
 err_register_resources:
+	mlxsw_bus->fini(bus_priv);
+err_bus_init:
 	if (!reload)
 		devlink_free(devlink);
 err_devlink_alloc:
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
@ 2018-05-10 11:26 ` Christophe JAILLET
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe JAILLET @ 2018-05-10 11:26 UTC (permalink / raw)
  To: jiri, idosch, davem
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

Resources are not freed in the reverse order of the allocation.
Labels are also mixed-up.

Fix it and reorder code and labels in the error handling path of
'mlxsw_core_bus_device_register()'

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Please review carefully. This patch is proposed because it triggers one of
my coccinelle scripts. I'm not 100% sure if correct.

The script tries to spot wrongly ordered error handling path. It is:
@@
identifier l1, l2;
@@

   if (...) {
      ...
*     goto l1;
   }
   ...
   if (...) {
      ...
*     goto l2;
   }
   ...
*l1:
   ...
*l2:
   ...
---
 drivers/net/ethernet/mellanox/mlxsw/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
index 93ea56620a24..e13ac3b8dff7 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
@@ -1100,11 +1100,11 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
 err_alloc_lag_mapping:
 	mlxsw_ports_fini(mlxsw_core);
 err_ports_init:
-	mlxsw_bus->fini(bus_priv);
-err_bus_init:
 	if (!reload)
 		devlink_resources_unregister(devlink, NULL);
 err_register_resources:
+	mlxsw_bus->fini(bus_priv);
+err_bus_init:
 	if (!reload)
 		devlink_free(devlink);
 err_devlink_alloc:
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
  2018-05-10 11:26 ` Christophe JAILLET
@ 2018-05-10 11:58   ` Ido Schimmel
  -1 siblings, 0 replies; 10+ messages in thread
From: Ido Schimmel @ 2018-05-10 11:58 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: jiri, idosch, davem, netdev, linux-kernel, kernel-janitors

On Thu, May 10, 2018 at 01:26:16PM +0200, Christophe JAILLET wrote:
> Resources are not freed in the reverse order of the allocation.
> Labels are also mixed-up.
> 
> Fix it and reorder code and labels in the error handling path of
> 'mlxsw_core_bus_device_register()'
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

For net:

Fixes: ef3116e5403e ("mlxsw: spectrum: Register KVD resources with devlink")
Reviewed-by: Ido Schimmel <idosch@mellanox.com>

Next time, please indicate the tree you're targeting as explained here:
https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt

And include a Fixes line as explained here:
https://www.kernel.org/doc/Documentation/process/submitting-patches.rst

Thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
@ 2018-05-10 11:58   ` Ido Schimmel
  0 siblings, 0 replies; 10+ messages in thread
From: Ido Schimmel @ 2018-05-10 11:58 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: jiri, idosch, davem, netdev, linux-kernel, kernel-janitors

On Thu, May 10, 2018 at 01:26:16PM +0200, Christophe JAILLET wrote:
> Resources are not freed in the reverse order of the allocation.
> Labels are also mixed-up.
> 
> Fix it and reorder code and labels in the error handling path of
> 'mlxsw_core_bus_device_register()'
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

For net:

Fixes: ef3116e5403e ("mlxsw: spectrum: Register KVD resources with devlink")
Reviewed-by: Ido Schimmel <idosch@mellanox.com>

Next time, please indicate the tree you're targeting as explained here:
https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt

And include a Fixes line as explained here:
https://www.kernel.org/doc/Documentation/process/submitting-patches.rst

Thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
  2018-05-10 11:26 ` Christophe JAILLET
@ 2018-05-10 12:41   ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2018-05-10 12:41 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: jiri, idosch, davem, netdev, linux-kernel, kernel-janitors

On Thu, May 10, 2018 at 01:26:16PM +0200, Christophe JAILLET wrote:
> Resources are not freed in the reverse order of the allocation.
> Labels are also mixed-up.
> 
> Fix it and reorder code and labels in the error handling path of
> 'mlxsw_core_bus_device_register()'
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Please review carefully. This patch is proposed because it triggers one of
> my coccinelle scripts. I'm not 100% sure if correct.
> 

Looks correct.

The err = mlxsw_driver->resources_register(mlxsw_core); pointer is a
pointer to mlxsw_sp_resources_register().  That function doesn't clean
up after itself on failure.  Ideally, you'd want a matching
mlxsw_driver->resources_unregister as well pointer instead of hard
coding devlink_resources_unregister().

The error handling would be easier to review if the gotos told you what
the did.  Right now they're written in "come from" style so the tell you
what happened on the line before.

	if (!foo)
		goto allocating_foo_failed;

Hopefully if someone fixes mlxsw_sp_resources_register() they'll choose
better label names.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
@ 2018-05-10 12:41   ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2018-05-10 12:41 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: jiri, idosch, davem, netdev, linux-kernel, kernel-janitors

On Thu, May 10, 2018 at 01:26:16PM +0200, Christophe JAILLET wrote:
> Resources are not freed in the reverse order of the allocation.
> Labels are also mixed-up.
> 
> Fix it and reorder code and labels in the error handling path of
> 'mlxsw_core_bus_device_register()'
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Please review carefully. This patch is proposed because it triggers one of
> my coccinelle scripts. I'm not 100% sure if correct.
> 

Looks correct.

The err = mlxsw_driver->resources_register(mlxsw_core); pointer is a
pointer to mlxsw_sp_resources_register().  That function doesn't clean
up after itself on failure.  Ideally, you'd want a matching
mlxsw_driver->resources_unregister as well pointer instead of hard
coding devlink_resources_unregister().

The error handling would be easier to review if the gotos told you what
the did.  Right now they're written in "come from" style so the tell you
what happened on the line before.

	if (!foo)
		goto allocating_foo_failed;

Hopefully if someone fixes mlxsw_sp_resources_register() they'll choose
better label names.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in \'mlxsw_core_bus_device_register()\'
  2018-05-10 12:41   ` Dan Carpenter
  (?)
@ 2018-05-10 13:08   ` Arkadi Sharshevsky
  2018-05-10 13:17     ` Dan Carpenter
  -1 siblings, 1 reply; 10+ messages in thread
From: Arkadi Sharshevsky @ 2018-05-10 13:08 UTC (permalink / raw)
  To: dan.carpenter; +Cc: netdev

Hi Dan,

I will fix the error path. Regarding the goto label this is
the convention in the driver.

Thanks,
Arkadi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in \'mlxsw_core_bus_device_register()\'
  2018-05-10 13:08   ` [PATCH] mlxsw: core: Fix an error handling path in \'mlxsw_core_bus_device_register()\' Arkadi Sharshevsky
@ 2018-05-10 13:17     ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2018-05-10 13:17 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev

On Thu, May 10, 2018 at 04:08:22PM +0300, Arkadi Sharshevsky wrote:
> Hi Dan,
> 
> I will fix the error path. Regarding the goto label this is
> the convention in the driver.

There is no rule against learning from the past.

Or there might be... I don't know all the rules at Mellanox.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
  2018-05-10 11:58   ` Ido Schimmel
@ 2018-05-11 15:57     ` David Miller
  -1 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-05-11 15:57 UTC (permalink / raw)
  To: idosch
  Cc: christophe.jaillet, jiri, idosch, netdev, linux-kernel, kernel-janitors

From: Ido Schimmel <idosch@idosch.org>
Date: Thu, 10 May 2018 14:58:21 +0300

> On Thu, May 10, 2018 at 01:26:16PM +0200, Christophe JAILLET wrote:
>> Resources are not freed in the reverse order of the allocation.
>> Labels are also mixed-up.
>> 
>> Fix it and reorder code and labels in the error handling path of
>> 'mlxsw_core_bus_device_register()'
>> 
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> For net:
> 
> Fixes: ef3116e5403e ("mlxsw: spectrum: Register KVD resources with devlink")
> Reviewed-by: Ido Schimmel <idosch@mellanox.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()'
@ 2018-05-11 15:57     ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-05-11 15:57 UTC (permalink / raw)
  To: idosch
  Cc: christophe.jaillet, jiri, idosch, netdev, linux-kernel, kernel-janitors

From: Ido Schimmel <idosch@idosch.org>
Date: Thu, 10 May 2018 14:58:21 +0300

> On Thu, May 10, 2018 at 01:26:16PM +0200, Christophe JAILLET wrote:
>> Resources are not freed in the reverse order of the allocation.
>> Labels are also mixed-up.
>> 
>> Fix it and reorder code and labels in the error handling path of
>> 'mlxsw_core_bus_device_register()'
>> 
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> For net:
> 
> Fixes: ef3116e5403e ("mlxsw: spectrum: Register KVD resources with devlink")
> Reviewed-by: Ido Schimmel <idosch@mellanox.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-05-11 15:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-10 11:26 [PATCH] mlxsw: core: Fix an error handling path in 'mlxsw_core_bus_device_register()' Christophe JAILLET
2018-05-10 11:26 ` Christophe JAILLET
2018-05-10 11:58 ` Ido Schimmel
2018-05-10 11:58   ` Ido Schimmel
2018-05-11 15:57   ` David Miller
2018-05-11 15:57     ` David Miller
2018-05-10 12:41 ` Dan Carpenter
2018-05-10 12:41   ` Dan Carpenter
2018-05-10 13:08   ` [PATCH] mlxsw: core: Fix an error handling path in \'mlxsw_core_bus_device_register()\' Arkadi Sharshevsky
2018-05-10 13:17     ` Dan Carpenter

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.