From patchwork Mon Aug 3 16:12:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Moore X-Patchwork-Id: 30587 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 2F3CCB6F2B for ; Tue, 4 Aug 2009 02:13:03 +1000 (EST) Received: by ozlabs.org (Postfix) id 1DBD0DDDB6; Tue, 4 Aug 2009 02:13:03 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 9799DDDDA2 for ; Tue, 4 Aug 2009 02:13:02 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755386AbZHCQMu (ORCPT ); Mon, 3 Aug 2009 12:12:50 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755345AbZHCQMt (ORCPT ); Mon, 3 Aug 2009 12:12:49 -0400 Received: from g5t0009.atlanta.hp.com ([15.192.0.46]:35126 "EHLO g5t0009.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755228AbZHCQMt (ORCPT ); Mon, 3 Aug 2009 12:12:49 -0400 Received: from g4t0009.houston.hp.com (g4t0009.houston.hp.com [16.234.32.26]) by g5t0009.atlanta.hp.com (Postfix) with ESMTP id 3F0C5302FD for ; Mon, 3 Aug 2009 16:12:50 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g4t0009.houston.hp.com (Postfix) with ESMTP id 0DEBEC04D; Mon, 3 Aug 2009 16:12:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ldl (Postfix) with ESMTP id E52D9CF0018; Mon, 3 Aug 2009 10:12:49 -0600 (MDT) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AyAqFDWgsGMZ; Mon, 3 Aug 2009 10:12:49 -0600 (MDT) Received: from flek.lan (squirrel.fc.hp.com [15.11.146.57]) by ldl (Postfix) with ESMTP id 119C6CF0015; Mon, 3 Aug 2009 10:12:48 -0600 (MDT) From: Paul Moore Subject: [RFC PATCH v1] tun: Cleanup error handling in tun_set_iff() To: netdev@vger.kernel.org Date: Mon, 03 Aug 2009 12:12:43 -0400 Message-ID: <20090803161242.12947.14620.stgit@flek.lan> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Convert some pointless gotos into returns and ensure tun_attach() errors are handled correctly. Signed-off-by: Paul Moore --- I'm sending this as an RFC patch because I'm not entirely certain that the changes to the tun_attach() error handling code are 100% correct, although I strongly suspect that the current behavor of simply returning an error code without any cleanup is broken. Can anyone comment on this? --- drivers/net/tun.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 4a0db7a..b6d06fd 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -938,13 +938,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) err = tun_attach(tun, file); if (err < 0) return err; - } - else { + } else { char *name; unsigned long flags = 0; - err = -EINVAL; - if (!capable(CAP_NET_ADMIN)) return -EPERM; @@ -958,7 +955,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) flags |= TUN_TAP_DEV; name = "tap%d"; } else - goto failed; + return -EINVAL; if (*ifr->ifr_name) name = ifr->ifr_name; @@ -976,10 +973,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) tun->flags = flags; tun->txflt.count = 0; - err = -ENOMEM; sk = sk_alloc(net, AF_UNSPEC, GFP_KERNEL, &tun_proto); - if (!sk) + if (!sk) { + err = -ENOMEM; goto err_free_dev; + } init_waitqueue_head(&tun->socket.wait); sock_init_data(&tun->socket, sk); @@ -1010,7 +1008,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) err = tun_attach(tun, file); if (err < 0) - goto failed; + goto err_unreg_dev; } DBG(KERN_INFO "%s: tun_set_iff\n", tun->dev->name); @@ -1039,11 +1037,14 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) strcpy(ifr->ifr_name, tun->dev->name); return 0; + err_unreg_dev: + rtnl_lock(); + unregister_netdevice(tun->dev); + rtnl_unlock(); err_free_sk: sock_put(sk); err_free_dev: free_netdev(dev); - failed: return err; }