linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeed@kernel.org>
To: Zizhuang Deng <sunsetdzz@gmail.com>, mbloch@nvidia.com
Cc: saeedm@nvidia.com, leon@kernel.org, davem@davemloft.net,
	kuba@kernel.org, netdev@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/mlx5: Add vport return value checks
Date: Fri, 31 Dec 2021 14:46:15 -0800	[thread overview]
Message-ID: <20211231224615.oneibk4ks5wofgf7@sx1> (raw)
In-Reply-To: <20211230052558.959617-1-sunsetdzz@gmail.com>

On Thu, Dec 30, 2021 at 01:25:58PM +0800, Zizhuang Deng wrote:
>add missing vport return value checks for recent code, as in [1].
>
>Ref:
>[1] https://lkml.org/lkml/2020/11/1/315
>

Where did this patch come from ? real bug ? or just aligning the code to
be according the link below ? 
because all the use-cases below are supposed to be guaranteed to have a
valid vport object for uplink/pf/and ecpf vportrs, i am not against the
patch, I am just trying to understand if there is a hidden bug somewhere .. 



>Signed-off-by: Zizhuang Deng <sunsetdzz@gmail.com>
>---
> .../mellanox/mlx5/core/eswitch_offloads.c     | 20 +++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
>diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>index f4eaa5893886..fda214021738 100644
>--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

[...]

>@@ -1309,11 +1317,15 @@ static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw)
>
> 	if (mlx5_ecpf_vport_exists(esw->dev)) {
> 		vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_ECPF);
>+		if (IS_ERR(vport))
>+			return;

memleak, we need to hit kvfree(flows) below, 
instead of returning you should make the del_flow conditional and continue
to next steps in the esw_del_fdb_peer_miss_rules routine, 
e.g:
if (vport)
	mlx5_del_flow_rules(flows[vport->index]);

> 		mlx5_del_flow_rules(flows[vport->index]);
> 	}
>
> 	if (mlx5_core_is_ecpf_esw_manager(esw->dev)) {
> 		vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_PF);
>+		if (IS_ERR(vport))
>+			return;

ditto 

> 		mlx5_del_flow_rules(flows[vport->index]);
> 	}
> 	kvfree(flows);
>@@ -2385,6 +2397,9 @@ static int esw_set_uplink_slave_ingress_root(struct mlx5_core_dev *master,
> 	if (master) {
> 		esw = master->priv.eswitch;
> 		vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_UPLINK);
>+		if (IS_ERR(vport))
>+			return PTR_ERR(vport);
>+
> 		MLX5_SET(set_flow_table_root_in, in, table_of_other_vport, 1);
> 		MLX5_SET(set_flow_table_root_in, in, table_vport_number,
> 			 MLX5_VPORT_UPLINK);
>@@ -2405,6 +2420,9 @@ static int esw_set_uplink_slave_ingress_root(struct mlx5_core_dev *master,
> 	} else {
> 		esw = slave->priv.eswitch;
> 		vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_UPLINK);
>+		if (IS_ERR(vport))
>+			return PTR_ERR(vport);
>+
> 		ns = mlx5_get_flow_vport_acl_namespace(slave,
> 						       MLX5_FLOW_NAMESPACE_ESW_INGRESS,
> 						       vport->index);
>@@ -2590,6 +2608,8 @@ static void esw_unset_master_egress_rule(struct mlx5_core_dev *dev)
>
> 	vport = mlx5_eswitch_get_vport(dev->priv.eswitch,
> 				       dev->priv.eswitch->manager_vport);
>+	if (IS_ERR(vport))
>+		return;
>
> 	esw_acl_egress_ofld_cleanup(vport);
> }
>-- 
>2.25.1
>

      reply	other threads:[~2021-12-31 22:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-30  5:25 [PATCH] net/mlx5: Add vport return value checks Zizhuang Deng
2021-12-31 22:46 ` Saeed Mahameed [this message]

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=20211231224615.oneibk4ks5wofgf7@sx1 \
    --to=saeed@kernel.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=sunsetdzz@gmail.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).