From: "Gao Feng" <gfree.wind@foxmail.com>
To: "'Xin Long'" <lucien.xin@gmail.com>,
"'Gao Feng'" <gfree.wind@vip.163.com>
Cc: "'davem'" <davem@davemloft.net>, <jarod@redhat.com>,
"'Stephen Hemminger'" <stephen@networkplumber.org>,
<dsa@cumulusnetworks.com>,
"'network dev'" <netdev@vger.kernel.org>
Subject: RE: [PATCH net v3] driver: veth: Fix one possbile memleak when fail to register_netdevice
Date: Wed, 3 May 2017 10:07:36 +0800 [thread overview]
Message-ID: <000c01d2c3b2$0925e880$1b71b980$@foxmail.com> (raw)
In-Reply-To: <CADvbK_cVS=M3tuz0QQT18D32UzLkdL0RMHuFxqcBgtfq_w7+9Q@mail.gmail.com>
> From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org]
> On Behalf Of Xin Long
> Sent: Wednesday, May 3, 2017 12:59 AM
> On Tue, May 2, 2017 at 7:03 PM, Gao Feng <gfree.wind@vip.163.com> wrote:
> >> From: Xin Long [mailto:lucien.xin@gmail.com]
> >> Sent: Tuesday, May 2, 2017 3:56 PM
> >> On Sat, Apr 29, 2017 at 11:51 AM, <gfree.wind@foxmail.com> wrote:
> >> > From: Gao Feng <gfree.wind@foxmail.com>
> > [...]
> >> > -static void veth_dev_free(struct net_device *dev)
> >> > +static void veth_destructor_free(struct net_device *dev)
> >> > {
> >> > free_percpu(dev->vstats);
> >> > +}
> >> not sure why you needed to add this function.
> >> to use free_percpu() directly may be clearer.
> >
> > Because both of ndo_uninit and destructor need to perform same free
> statements.
> > It is good at maintain the codes with the common function.
> >>
> >> > +
> >> > +static void veth_dev_uninit(struct net_device *dev) {
> >> call free_percpu() here, no need to check dev->reg_state.
> >> free_percpu will just return if dev->vstats is NULL.
> >
> > It would break the original design if don't check the reg_state.
> > The original logic is that free the resources in the destructor, not in ndo_init.
> I got what you're doing now, can you pls try to fix this with:
>
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -219,10 +219,9 @@ static int veth_dev_init(struct net_device *dev)
> return 0;
> }
>
> -static void veth_dev_free(struct net_device *dev)
> +static void veth_dev_uninit(struct net_device *dev)
> {
> free_percpu(dev->vstats);
> - free_netdev(dev);
> }
>
> #ifdef CONFIG_NET_POLL_CONTROLLER
> @@ -279,6 +278,7 @@ static void veth_set_rx_headroom(struct net_device
> *dev, int new_hr)
>
> static const struct net_device_ops veth_netdev_ops = {
> .ndo_init = veth_dev_init,
> + .ndo_uninit = veth_dev_uninit,
> .ndo_open = veth_open,
> .ndo_stop = veth_close,
> .ndo_start_xmit = veth_xmit,
> @@ -317,7 +317,7 @@ static void veth_setup(struct net_device *dev)
> NETIF_F_HW_VLAN_STAG_TX |
> NETIF_F_HW_VLAN_CTAG_RX |
> NETIF_F_HW_VLAN_STAG_RX);
> - dev->destructor = veth_dev_free;
> + dev->destructor = free_netdev;
> dev->max_mtu = ETH_MAX_MTU;
>
> dev->hw_features = VETH_FEATURES;
>
>
> just as what other virtual nic drivers do (vxlan, geneve, macsec, bridge ....)
>
The fix you mentioned change the original logic.
The dev->vstats is freed in advance in the ndo_uninit, not destructor.
It may break the backward.
Regards
Feng
next prev parent reply other threads:[~2017-05-03 2:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-29 3:51 [PATCH net v3] driver: veth: Fix one possbile memleak when fail to register_netdevice gfree.wind
2017-05-01 15:08 ` David Ahern
2017-05-02 10:51 ` Gao Feng
2017-05-02 7:55 ` Xin Long
2017-05-02 11:03 ` Gao Feng
2017-05-02 16:59 ` Xin Long
2017-05-03 2:07 ` Gao Feng [this message]
2017-05-03 5:37 ` Xin Long
2017-05-03 6:37 ` Gao Feng
2017-05-03 11:25 ` Xin Long
2017-05-03 13:17 ` Gao Feng
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='000c01d2c3b2$0925e880$1b71b980$@foxmail.com' \
--to=gfree.wind@foxmail.com \
--cc=davem@davemloft.net \
--cc=dsa@cumulusnetworks.com \
--cc=gfree.wind@vip.163.com \
--cc=jarod@redhat.com \
--cc=lucien.xin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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 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).