From: Kulikov Vasiliy <segooon@gmail.com>
To: Denis Kirjanov <dkirjanov@hera.kernel.org>
Cc: davem@davemloft.net, john.linn@xilinx.com, brian.hill@xilinx.com,
grant.likely@secretlab.ca, jpirko@redhat.com,
netdev@vger.kernel.org
Subject: Re: [PATCH v2 -net-2.6] ll_temac: fix DMA resources leak
Date: Fri, 9 Jul 2010 21:59:52 +0400 [thread overview]
Message-ID: <20100709175952.GA5450@albatros> (raw)
In-Reply-To: <20100709114347.GA3553@albatros>
On Fri, Jul 09, 2010 at 15:43 +0400, Kulikov Vasiliy wrote:
> On Thu, Jul 08, 2010 at 20:24 +0000, Denis Kirjanov wrote:
> > V2: Check pointers before releasing resources.
> >
> > Fix DMA resources leak.
> > Signed-off-by: Denis Kirjanov <dkirjanov@kernel.org>
> > Signed-off-by: Kulikov Vasiliy <segooon@gmail.com>
> > ---
> > 1 files changed, 32 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/net/ll_temac_main.c b/drivers/net/ll_temac_main.c
> > index fa303c8..b57d0ff 100644
> > --- a/drivers/net/ll_temac_main.c
> > +++ b/drivers/net/ll_temac_main.c
> > @@ -193,6 +193,35 @@ static int temac_dcr_setup(struct temac_local *lp, struct of_device *op,
> > #endif
> >
> > /**
> > + * * temac_dma_bd_release - Release buffer descriptor rings
> > + */
> > +static void temac_dma_bd_release(struct net_device *ndev)
> > +{
> > + struct temac_local *lp = netdev_priv(ndev);
> > + int i;
> > +
> > + for (i = 0; i < RX_BD_NUM; i++) {
> > + if (!lp->rx_skb[i])
> > + break;
> > + else {
> > + dma_unmap_single(ndev->dev.parent, lp->rx_bd_v[i].phys,
> > + XTE_MAX_JUMBO_FRAME_SIZE, DMA_FROM_DEVICE);
> > + dev_kfree_skb(lp->rx_skb[i]);
> > + }
> > + }
> This cycle is needed only if (lp->rx_skb != NULL).
>
> > + if (lp->rx_bd_v)
> > + dma_free_coherent(ndev->dev.parent,
> > + sizeof(*lp->rx_bd_v) * RX_BD_NUM,
> > + lp->rx_bd_v, lp->rx_bd_p);
> > + if (lp->tx_bd_v)
> > + dma_free_coherent(ndev->dev.parent,
> > + sizeof(*lp->tx_bd_v) * TX_BD_NUM,
> > + lp->tx_bd_v, lp->tx_bd_p);
> After temac_dma_bd_release() lp->rx_bd_v and lp->rx_bd_p are freed but
> are nonzero. If lp->rx_skb allocation fails second time then these DMA's
> would be freed second time.
> lp->tx_bd_v = lp->rx_bd_v = NULL here fixes this.
>
> > + if (lp->rx_skb)
> > + kfree(lp->rx_skb);
> > +}
> > +
> > +/**
> > * temac_dma_bd_init - Setup buffer descriptor rings
> > */
> > static int temac_dma_bd_init(struct net_device *ndev)
> > @@ -275,6 +304,7 @@ static int temac_dma_bd_init(struct net_device *ndev)
> > return 0;
> >
> > out:
> > + temac_dma_bd_release(ndev);
> > return -ENOMEM;
> > }
> >
> > @@ -858,6 +888,8 @@ static int temac_stop(struct net_device *ndev)
> > phy_disconnect(lp->phy_dev);
> > lp->phy_dev = NULL;
> >
> > + temac_dma_bd_release(ndev);
> > +
> > return 0;
> > }
> >
I've fixed it in PATCH v3.
http://marc.info/?l=kernel-janitors&m=127869815002994&w=2
next prev parent reply other threads:[~2010-07-09 18:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-08 20:24 [PATCH v2 -net-2.6] ll_temac: fix DMA resources leak Denis Kirjanov
2010-07-09 11:43 ` Kulikov Vasiliy
2010-07-09 17:59 ` Kulikov Vasiliy [this message]
2010-07-09 20:09 ` Denis Kirjanov
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=20100709175952.GA5450@albatros \
--to=segooon@gmail.com \
--cc=brian.hill@xilinx.com \
--cc=davem@davemloft.net \
--cc=dkirjanov@hera.kernel.org \
--cc=grant.likely@secretlab.ca \
--cc=john.linn@xilinx.com \
--cc=jpirko@redhat.com \
--cc=netdev@vger.kernel.org \
/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.