netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: Duan Andy <fugang.duan@freescale.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Li Frank <Frank.Li@freescale.com>,
	"kernel@pengutronix.de" <kernel@pengutronix.de>,
	"patchwork-lst@pengutronix.de" <patchwork-lst@pengutronix.de>
Subject: Re: [PATCH v2 1/2] net: fec: use managed DMA API functions to allocate BD ring
Date: Thu, 23 Jul 2015 12:24:05 +0200	[thread overview]
Message-ID: <1437647045.3071.36.camel@pengutronix.de> (raw)
In-Reply-To: <BLUPR03MB373240F9253F98CF962AA88F5830@BLUPR03MB373.namprd03.prod.outlook.com>

Am Mittwoch, den 22.07.2015, 01:55 +0000 schrieb Duan Andy:
> From: Lucas Stach <l.stach@pengutronix.de> Sent: Tuesday, July 21, 2015 11:11 PM
> > To: David S. Miller
> > Cc: Duan Fugang-B38611; Li Frank-B20596; netdev@vger.kernel.org;
> > kernel@pengutronix.de; patchwork-lst@pengutronix.de
> > Subject: [PATCH v2 1/2] net: fec: use managed DMA API functions to
> > allocate BD ring
> > 
> > So it gets freed when the device is going away.
> > This fixes a DMA memory leak on driver probe() fail and driver remove().
> > 
> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> > ---
> > v2: Fix indentation of second line to fix alignment with opening bracket.
> > ---
> >  drivers/net/ethernet/freescale/fec_main.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/freescale/fec_main.c
> > b/drivers/net/ethernet/freescale/fec_main.c
> > index 349365d85b92..a7f1bdf718f8 100644
> > --- a/drivers/net/ethernet/freescale/fec_main.c
> > +++ b/drivers/net/ethernet/freescale/fec_main.c
> > @@ -3142,8 +3142,8 @@ static int fec_enet_init(struct net_device *ndev)
> >  			fep->bufdesc_size;
> > 
> >  	/* Allocate memory for buffer descriptors. */
> > -	cbd_base = dma_alloc_coherent(NULL, bd_size, &bd_dma,
> > -				      GFP_KERNEL);
> > +	cbd_base = dmam_alloc_coherent(&fep->pdev->dev, bd_size, &bd_dma,
> > +				       GFP_KERNEL);
> >  	if (!cbd_base) {
> >  		return -ENOMEM;
> >  	}
> > --
> 
> Can you also replace the below position with dma_alloc_coherent() ?
>                 txq->tso_hdrs = dma_alloc_coherent(NULL,
>                                         txq->tx_ring_size * TSO_HEADER_SIZE,
>                                         &txq->tso_hdrs_dma,
>                                         GFP_KERNEL);
> 
> 
No, that one has an explicit free functions.
So using managed function would result in a double free in paths. We
might want to move those over to devm eventually to make the error
handling more robust, but that's clearly out of the scope of this patch.

Regards,
Lucas

-- 
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |

      reply	other threads:[~2015-07-23 10:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-21 15:11 [PATCH v2 1/2] net: fec: use managed DMA API functions to allocate BD ring Lucas Stach
2015-07-21 15:11 ` [PATCH v2 2/2] net: fec: introduce fec_ptp_stop and use in probe fail path Lucas Stach
2015-07-22  1:58   ` Duan Andy
2015-07-22  1:55 ` [PATCH v2 1/2] net: fec: use managed DMA API functions to allocate BD ring Duan Andy
2015-07-23 10:24   ` Lucas Stach [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=1437647045.3071.36.camel@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=Frank.Li@freescale.com \
    --cc=davem@davemloft.net \
    --cc=fugang.duan@freescale.com \
    --cc=kernel@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=patchwork-lst@pengutronix.de \
    /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).