[net-next PATCH v5 4/5] net: ethernet: stmicro: stmmac: generate stmmac dma conf before open

Christian Marangi ansuelsmth at gmail.com
Tue Jun 13 19:16:08 PDT 2023


On Wed, Jun 14, 2023 at 07:15:03AM +0000, Jose Abreu wrote:
> Hi Christian,
> 
> From: Christian Marangi <ansuelsmth at gmail.com>
> Date: Sat, Jul 23, 2022 at 15:29:32
> 
> > +static int __stmmac_open(struct net_device *dev,
> > +			 struct stmmac_dma_conf *dma_conf)
> >  {
> >  	struct stmmac_priv *priv = netdev_priv(dev);
> >  	int mode = priv->plat->phy_interface;
> > -	int bfsize = 0;
> >  	u32 chan;
> >  	int ret;
> >  
> > @@ -3657,45 +3794,10 @@ static int stmmac_open(struct net_device *dev)
> >  	memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
> >  	priv->xstats.threshold = tc;
> >  
> > -	bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
> > -	if (bfsize < 0)
> > -		bfsize = 0;
> > -
> > -	if (bfsize < BUF_SIZE_16KiB)
> > -		bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_conf.dma_buf_sz);
> > -
> > -	priv->dma_conf.dma_buf_sz = bfsize;
> > -	buf_sz = bfsize;
> > -
> >  	priv->rx_copybreak = STMMAC_RX_COPYBREAK;
> >  
> > -	if (!priv->dma_conf.dma_tx_size)
> > -		priv->dma_conf.dma_tx_size = DMA_DEFAULT_TX_SIZE;
> > -	if (!priv->dma_conf.dma_rx_size)
> > -		priv->dma_conf.dma_rx_size = DMA_DEFAULT_RX_SIZE;
> > -
> > -	/* Earlier check for TBS */
> > -	for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) {
> > -		struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[chan];
> > -		int tbs_en = priv->plat->tx_queues_cfg[chan].tbs_en;
> > -
> > -		/* Setup per-TXQ tbs flag before TX descriptor alloc */
> > -		tx_q->tbs |= tbs_en ? STMMAC_TBS_AVAIL : 0;
> > -	}
> > -
> > -	ret = alloc_dma_desc_resources(priv);
> > -	if (ret < 0) {
> > -		netdev_err(priv->dev, "%s: DMA descriptors allocation failed\n",
> > -			   __func__);
> > -		goto dma_desc_error;
> > -	}
> > -
> > -	ret = init_dma_desc_rings(dev, GFP_KERNEL);
> > -	if (ret < 0) {
> > -		netdev_err(priv->dev, "%s: DMA descriptors initialization failed\n",
> > -			   __func__);
> > -		goto init_error;
> > -	}
> > +	buf_sz = dma_conf->dma_buf_sz;
> > +	memcpy(&priv->dma_conf, dma_conf, sizeof(*dma_conf));
> 
> This memcpy() needs to be the first thing to be done on __stmmac_open(), otherwise
> you'll leak the dma_conf when stmmac_init_phy() fails.
>

I'm not following the meaning of leak here. If it's intended as a memory
leak then dma_conf is correctly freed in the 2 user of __stmmac_open.

stmmac_init_phy also doesn't seems to use dma_conf. Am I missing
something here?

> Can you please send follow-up patch?

Happy to push a follow-up patch with these concern cleared!

> 
> Thanks,
> Jose

-- 
	Ansuel



More information about the linux-arm-kernel mailing list