Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753841AbcD0K5T (ORCPT ); Wed, 27 Apr 2016 06:57:19 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:37035 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752502AbcD0K5R (ORCPT ); Wed, 27 Apr 2016 06:57:17 -0400 Subject: Re: [PATCH] veth: Fix potential memory leak in veth_newlink To: Haishuang Yan , "David S. Miller" , Toshiaki Makita References: <1461753739-4803-1-git-send-email-yanhaishuang@cmss.chinamobile.com> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org From: Nikolay Aleksandrov Message-ID: <57209B0A.8070800@cumulusnetworks.com> Date: Wed, 27 Apr 2016 12:57:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1461753739-4803-1-git-send-email-yanhaishuang@cmss.chinamobile.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 863 Lines: 26 On 04/27/2016 12:42 PM, Haishuang Yan wrote: > Free peer netdev when failed to configure peer link or register dev. > > Signed-off-by: Haishuang Yan > --- > drivers/net/veth.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/drivers/net/veth.c b/drivers/net/veth.c > index f37a6e6..8bb9fb8 100644 > --- a/drivers/net/veth.c > +++ b/drivers/net/veth.c > @@ -472,7 +472,6 @@ err_register_dev: > /* nothing to do */ > err_configure_peer: > unregister_netdevice(peer); > - return err; > > err_register_peer: > free_netdev(peer); > No, it won't leak. unregister_netdevice() will queue it on the todo list and at the next rtnl unlock the peer device will get freed. In fact calling it like this you'll hit BUG_ON(dev->reg_state != NETREG_UNREGISTERED) in free_netdev so I guess you didn't even test your patch.