From patchwork Mon Sep 28 12:53:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 34379 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org 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 30446B7C03 for ; Mon, 28 Sep 2009 23:02:49 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751797AbZI1NCW (ORCPT ); Mon, 28 Sep 2009 09:02:22 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751609AbZI1NCW (ORCPT ); Mon, 28 Sep 2009 09:02:22 -0400 Received: from eddie.linux-mips.org ([78.24.191.182]:51939 "EHLO eddie.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbZI1NCV (ORCPT ); Mon, 28 Sep 2009 09:02:21 -0400 X-Greylist: delayed 503 seconds by postgrey-1.27 at vger.kernel.org; Mon, 28 Sep 2009 09:02:21 EDT Received: from localhost.localdomain ([127.0.0.1]:59604 "EHLO h5.dl5rb.org.uk" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org with ESMTP id S1492976AbZI1MyB (ORCPT + 1 other); Mon, 28 Sep 2009 14:54:01 +0200 Received: from h5.dl5rb.org.uk (localhost.localdomain [127.0.0.1]) by h5.dl5rb.org.uk (8.14.3/8.14.3) with ESMTP id n8SCsFK8026620; Mon, 28 Sep 2009 13:54:15 +0100 Received: (from ralf@localhost) by h5.dl5rb.org.uk (8.14.3/8.14.3/Submit) id n8SCrDF4026616; Mon, 28 Sep 2009 13:53:13 +0100 Date: Mon, 28 Sep 2009 13:53:13 +0100 From: Ralf Baechle To: Jarek Poplawski Cc: David Miller , Bernard Pidoux F6BVP , Bernard Pidoux , Linux Netdev List , linux-hams Subject: [PATCH] ax25: Add missing dev_put in ax25_setsockopt Message-ID: <20090928125313.GA14250@linux-mips.org> References: <20090921201157.GA5460@del.dom.local> <4ABA9058.3010605@free.fr> <20090928071211.GA8658@ff.dom.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090928071211.GA8658@ff.dom.local> User-Agent: Mutt/1.5.19 (2009-01-05) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ax25_setsockopt SO_BINDTODEVICE is missing a dev_put call in case of success. Re-order code to fix this bug. While at it also reformat two lines of code to comply with the Linux coding style. Initial patch by Jarek Poplawski . Reported-by: Bernard Pidoux F6BVP Signed-off-by: Ralf Baechle --- Counter-proposal. Reordering all the code avoids the need for a 2nd dev_put and is more readable. Ralf net/ax25/af_ax25.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/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index fbcac76..4102de1 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -641,15 +641,10 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname, case SO_BINDTODEVICE: if (optlen > IFNAMSIZ) - optlen=IFNAMSIZ; - if (copy_from_user(devname, optval, optlen)) { - res = -EFAULT; - break; - } + optlen = IFNAMSIZ; - dev = dev_get_by_name(&init_net, devname); - if (dev == NULL) { - res = -ENODEV; + if (copy_from_user(devname, optval, optlen)) { + res = -EFAULT; break; } @@ -657,12 +652,18 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname, (sock->state != SS_UNCONNECTED || sk->sk_state == TCP_LISTEN)) { res = -EADDRNOTAVAIL; - dev_put(dev); + break; + } + + dev = dev_get_by_name(&init_net, devname); + if (!dev) { + res = -ENODEV; break; } ax25->ax25_dev = ax25_dev_ax25dev(dev); ax25_fillin_cb(ax25, ax25->ax25_dev); + dev_put(dev); break; default: