Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net-next] ionic: cleanly release devlink instance
@ 2021-07-21 12:39 Leon Romanovsky
  2021-07-21 15:55 ` Shannon Nelson
  2021-07-21 21:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Leon Romanovsky @ 2021-07-21 12:39 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Shannon Nelson
  Cc: Leon Romanovsky, drivers, linux-kernel, Moshe Shemesh, netdev

From: Leon Romanovsky <leonro@nvidia.com>

The failure to register devlink will leave the system with dangled
devlink resource, which is not cleaned if devlink_port_register() fails.

In order to remove access to ".registered" field of struct devlink_port,
require both devlink_register and devlink_port_register to success and
check it through device pointer.

Fixes: fbfb8031533c ("ionic: Add hardware init and device commands")
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
Future series will remove .registered field from the devlink.
---
 .../net/ethernet/pensando/ionic/ionic_devlink.c    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
index b41301a5b0df..cd520e4c5522 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
@@ -91,20 +91,20 @@ int ionic_devlink_register(struct ionic *ionic)
 	attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
 	devlink_port_attrs_set(&ionic->dl_port, &attrs);
 	err = devlink_port_register(dl, &ionic->dl_port, 0);
-	if (err)
+	if (err) {
 		dev_err(ionic->dev, "devlink_port_register failed: %d\n", err);
-	else
-		devlink_port_type_eth_set(&ionic->dl_port,
-					  ionic->lif->netdev);
+		devlink_unregister(dl);
+		return err;
+	}
 
-	return err;
+	devlink_port_type_eth_set(&ionic->dl_port, ionic->lif->netdev);
+	return 0;
 }
 
 void ionic_devlink_unregister(struct ionic *ionic)
 {
 	struct devlink *dl = priv_to_devlink(ionic);
 
-	if (ionic->dl_port.registered)
-		devlink_port_unregister(&ionic->dl_port);
+	devlink_port_unregister(&ionic->dl_port);
 	devlink_unregister(dl);
 }
-- 
2.31.1


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

* Re: [PATCH net-next] ionic: cleanly release devlink instance
  2021-07-21 12:39 [PATCH net-next] ionic: cleanly release devlink instance Leon Romanovsky
@ 2021-07-21 15:55 ` Shannon Nelson
  2021-07-21 21:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Shannon Nelson @ 2021-07-21 15:55 UTC (permalink / raw)
  To: Leon Romanovsky, David S. Miller, Jakub Kicinski
  Cc: Leon Romanovsky, drivers, linux-kernel, Moshe Shemesh, netdev

On 7/21/21 5:39 AM, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> The failure to register devlink will leave the system with dangled
> devlink resource, which is not cleaned if devlink_port_register() fails.
>
> In order to remove access to ".registered" field of struct devlink_port,
> require both devlink_register and devlink_port_register to success and
> check it through device pointer.
>
> Fixes: fbfb8031533c ("ionic: Add hardware init and device commands")
> Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>

Sure, thanks.

Acked-by: Shannon Nelson <snelson@pensando.io>

> ---
> Future series will remove .registered field from the devlink.
> ---
>   .../net/ethernet/pensando/ionic/ionic_devlink.c    | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
> index b41301a5b0df..cd520e4c5522 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
> @@ -91,20 +91,20 @@ int ionic_devlink_register(struct ionic *ionic)
>   	attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
>   	devlink_port_attrs_set(&ionic->dl_port, &attrs);
>   	err = devlink_port_register(dl, &ionic->dl_port, 0);
> -	if (err)
> +	if (err) {
>   		dev_err(ionic->dev, "devlink_port_register failed: %d\n", err);
> -	else
> -		devlink_port_type_eth_set(&ionic->dl_port,
> -					  ionic->lif->netdev);
> +		devlink_unregister(dl);
> +		return err;
> +	}
>   
> -	return err;
> +	devlink_port_type_eth_set(&ionic->dl_port, ionic->lif->netdev);
> +	return 0;
>   }
>   
>   void ionic_devlink_unregister(struct ionic *ionic)
>   {
>   	struct devlink *dl = priv_to_devlink(ionic);
>   
> -	if (ionic->dl_port.registered)
> -		devlink_port_unregister(&ionic->dl_port);
> +	devlink_port_unregister(&ionic->dl_port);
>   	devlink_unregister(dl);
>   }


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

* Re: [PATCH net-next] ionic: cleanly release devlink instance
  2021-07-21 12:39 [PATCH net-next] ionic: cleanly release devlink instance Leon Romanovsky
  2021-07-21 15:55 ` Shannon Nelson
@ 2021-07-21 21:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-21 21:50 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: davem, kuba, snelson, leonro, drivers, linux-kernel, moshe, netdev

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Wed, 21 Jul 2021 15:39:44 +0300 you wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> The failure to register devlink will leave the system with dangled
> devlink resource, which is not cleaned if devlink_port_register() fails.
> 
> In order to remove access to ".registered" field of struct devlink_port,
> require both devlink_register and devlink_port_register to success and
> check it through device pointer.
> 
> [...]

Here is the summary with links:
  - [net-next] ionic: cleanly release devlink instance
    https://git.kernel.org/netdev/net-next/c/c2255ff47768

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-07-21 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 12:39 [PATCH net-next] ionic: cleanly release devlink instance Leon Romanovsky
2021-07-21 15:55 ` Shannon Nelson
2021-07-21 21:50 ` patchwork-bot+netdevbpf

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).