All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Geetha sowjanya <gakula@marvell.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com,
	edumazet@google.com, sgoutham@marvell.com, sbhatta@marvell.com,
	hkelam@marvell.com
Subject: Re: [net-next PATCH v5 03/10] octeontx2-pf: Create representor netdev
Date: Tue, 18 Jun 2024 09:25:28 +0100	[thread overview]
Message-ID: <20240618082528.GD8447@kernel.org> (raw)
In-Reply-To: <20240611162213.22213-4-gakula@marvell.com>

On Tue, Jun 11, 2024 at 09:52:06PM +0530, Geetha sowjanya wrote:
> Adds initial devlink support to set/get the switchdev mode.
> Representor netdevs are created for each rvu devices when
> the switch mode is set to 'switchdev'. These netdevs are
> be used to control and configure VFs.
> 
> Signed-off-by: Geetha sowjanya <gakula@marvell.com>

...

> +void rvu_rep_destroy(struct otx2_nic *priv)
> +{
> +	struct rep_dev *rep;
> +	int rep_id;
> +
> +	rvu_rep_free_cq_rsrc(priv);
> +	for (rep_id = 0; rep_id < priv->rep_cnt; rep_id++) {
> +		rep = priv->reps[rep_id];
> +		unregister_netdev(rep->netdev);
> +		free_netdev(rep->netdev);
> +	}
> +	kfree(priv->reps);
> +}
> +
> +int rvu_rep_create(struct otx2_nic *priv, struct netlink_ext_ack *extack)
> +{
> +	int rep_cnt = priv->rep_cnt;
> +	struct net_device *ndev;
> +	struct rep_dev *rep;
> +	int rep_id, err;
> +	u16 pcifunc;
> +
> +	priv->reps = kcalloc(rep_cnt, sizeof(struct rep_dev *), GFP_KERNEL);
> +	if (!priv->reps)
> +		return -ENOMEM;
> +
> +	for (rep_id = 0; rep_id < rep_cnt; rep_id++) {
> +		ndev = alloc_etherdev(sizeof(*rep));
> +		if (!ndev) {
> +			NL_SET_ERR_MSG_FMT_MOD(extack,
> +					       "PFVF representor:%d creation failed",
> +					       rep_id);
> +			err = -ENOMEM;
> +			goto exit;
> +		}
> +
> +		rep = netdev_priv(ndev);
> +		priv->reps[rep_id] = rep;
> +		rep->mdev = priv;
> +		rep->netdev = ndev;
> +		rep->rep_id = rep_id;
> +
> +		ndev->min_mtu = OTX2_MIN_MTU;
> +		ndev->max_mtu = priv->hw.max_mtu;
> +		pcifunc = priv->rep_pf_map[rep_id];
> +		rep->pcifunc = pcifunc;
> +
> +		snprintf(ndev->name, sizeof(ndev->name), "r%dp%d", rep_id,
> +			 rvu_get_pf(pcifunc));
> +
> +		eth_hw_addr_random(ndev);
> +		err = register_netdev(ndev);
> +		if (err) {
> +			NL_SET_ERR_MSG_MOD(extack,
> +					   "PFVF reprentator registration failed");

Hi Geetha,

(The most recently allocated) ndev appears to be leaked here.

I think that one way to address this could be to moving the contents of
this loop into a separate function that unwinds the most recent allocation
on error.

Highlighted by Smatch (although it seems a bit confused here).

 .../rep.c:184 rvu_rep_create() warn: 'ndev' from alloc_etherdev_mqs() not released on lines: 184.
 .../rep.c:184 rvu_rep_create() warn: 'ndev' from register_netdev() not released on lines: 184.

Sorry for not bringing this up earlier: it is at least the third time I
have looked over this, and for some reason I didn't notice this the other
times.

> +			goto exit;
> +		}
> +	}
> +	err = rvu_rep_napi_init(priv, extack);
> +	if (err)
> +		goto exit;
> +
> +	return 0;
> +exit:
> +	while (--rep_id >= 0) {
> +		rep = priv->reps[rep_id];
> +		unregister_netdev(rep->netdev);
> +		free_netdev(rep->netdev);
> +	}
> +	kfree(priv->reps);
> +	return err;
> +}
> +
>  static int rvu_rep_rsrc_free(struct otx2_nic *priv)
>  {
>  	struct otx2_qset *qset = &priv->qset;

...

  reply	other threads:[~2024-06-18  8:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11 16:22 [net-next PATCH v5 00/10] Introduce RVU representors Geetha sowjanya
2024-06-11 16:22 ` [net-next PATCH v5 01/10] octeontx2-pf: Refactoring RVU driver Geetha sowjanya
2024-06-15 11:15   ` Markus Elfring
2024-06-18  9:03     ` [EXTERNAL] " Geethasowjanya Akula
2024-06-18  7:40   ` Simon Horman
2024-06-24  9:56     ` Geethasowjanya Akula
2024-06-11 16:22 ` [net-next PATCH v5 02/10] octeontx2-pf: RVU representor driver Geetha sowjanya
2024-06-14  2:02   ` Jakub Kicinski
2024-06-18  9:08     ` [EXTERNAL] " Geethasowjanya Akula
2024-06-15 15:11   ` Markus Elfring
2024-06-17 19:49     ` Simon Horman
2024-06-25 11:58     ` [EXTERNAL] " Geethasowjanya Akula
2024-06-11 16:22 ` [net-next PATCH v5 03/10] octeontx2-pf: Create representor netdev Geetha sowjanya
2024-06-18  8:25   ` Simon Horman [this message]
2024-06-24  8:49     ` Geethasowjanya Akula
2024-06-11 16:22 ` [net-next PATCH v5 04/10] octeontx2-pf: Add basic net_device_ops Geetha sowjanya
2024-06-11 16:22 ` [net-next PATCH v5 05/10] octeontx2-af: Add packet path between representor and VF Geetha sowjanya
2024-06-17 20:19   ` Simon Horman
2024-06-18  8:38   ` Simon Horman
2024-06-19 12:16     ` [EXTERNAL] " Geethasowjanya Akula
2024-06-11 16:22 ` [net-next PATCH v5 06/10] octeontx2-pf: Get VF stats via representor Geetha sowjanya
2024-06-20 12:54   ` Simon Horman
2024-06-20 12:56   ` Simon Horman
2024-06-11 16:22 ` [net-next PATCH v5 07/10] octeontx2-pf: Add support to sync link state between representor and VFs Geetha sowjanya
2024-06-20 12:56   ` Simon Horman
2024-06-11 16:22 ` [net-next PATCH v4 08/10] octeontx2-pf: Configure VF mtu via representor Geetha sowjanya
2024-06-20 12:56   ` Simon Horman
2024-06-11 16:22 ` [net-next PATCH v5 09/10] octeontx2-pf: Add representors for sdp MAC Geetha sowjanya
2024-06-18  8:55   ` Simon Horman
2024-06-11 16:22 ` [net-next PATCH v5 10/10] octeontx2-pf: Add devlink port support Geetha sowjanya
2024-06-20 12:57   ` Simon Horman

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=20240618082528.GD8447@kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gakula@marvell.com \
    --cc=hkelam@marvell.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sbhatta@marvell.com \
    --cc=sgoutham@marvell.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 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.