From patchwork Tue Mar 5 16:09:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hurley X-Patchwork-Id: 225072 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.180.67]) by ozlabs.org (Postfix) with ESMTP id 66C9F2C0333 for ; Wed, 6 Mar 2013 03:11:31 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757212Ab3CEQJ4 (ORCPT ); Tue, 5 Mar 2013 11:09:56 -0500 Received: from mailout01.c08.mtsvc.net ([205.186.168.189]:41139 "EHLO mailout01.c08.mtsvc.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756816Ab3CEQJv (ORCPT ); Tue, 5 Mar 2013 11:09:51 -0500 Received: from n22.c08.mtsvc.net ([205.186.176.22]) by mailout01.c08.mtsvc.net with esmtp (Exim 4.72) (envelope-from ) id 1UCuQn-0006xF-6G; Tue, 05 Mar 2013 08:09:33 -0800 Received: from 68-189-242-29.dhcp.oxfr.ma.charter.com ([68.189.242.29]:43839 helo=thor.lan) by n22.c08.mtsvc.net with esmtpsa (TLS1.1:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80.1) (envelope-from ) id 1UCuQl-0001tA-KO; Tue, 05 Mar 2013 08:09:32 -0800 From: Peter Hurley To: David Miller , Samuel Ortiz Cc: Sasha Levin , Greg Kroah-Hartman , netdev@vger.kernel.org, Jiri Slaby , linux-kernel@vger.kernel.org, Peter Hurley Subject: [PATCH 1/4] net/irda: Fix port open counts Date: Tue, 5 Mar 2013 11:09:04 -0500 Message-Id: <1362499747-4262-2-git-send-email-peter@hurleysoftware.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1362499747-4262-1-git-send-email-peter@hurleysoftware.com> References: <1362371063.3221.185.camel@thor.lan> <1362499747-4262-1-git-send-email-peter@hurleysoftware.com> X-Authenticated-User: 125194 peter@hurleysoftware.com X-Spam-Status: "score=-0.9 tests=ALL_TRUSTED, TVD_RCVD_IP version=3.3.1 cmae=v=1.1 cv=lrjH+2xzIqj4PtBndNBiF3kNcDPTgJYy5MO9fqj9h9k= c=1 sm=0 a=Wt-goX4EMH4A:10 a=lF0tP7JmhmIA:10 a=hykYmh53AP4XJEdaM13vyQ==:17 a=xGRsDScCAAAA:8 a=0IC9aRnL58pYSNqirJoA:9 a=A4LuvFU5fKoA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117" X-Spam-Level: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Saving the port count bump is unsafe. If the tty is hung up while this open was blocking, the port count is zeroed. Explicitly check if the tty was hung up while blocking, and correct the port count if not. Signed-off-by: Peter Hurley --- net/irda/ircomm/ircomm_tty.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c index 9a5fd3c..1721dc7 100644 --- a/net/irda/ircomm/ircomm_tty.c +++ b/net/irda/ircomm/ircomm_tty.c @@ -280,7 +280,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self, struct tty_port *port = &self->port; DECLARE_WAITQUEUE(wait, current); int retval; - int do_clocal = 0, extra_count = 0; + int do_clocal = 0; unsigned long flags; IRDA_DEBUG(2, "%s()\n", __func__ ); @@ -315,10 +315,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self, __FILE__, __LINE__, tty->driver->name, port->count); spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) { - extra_count = 1; + if (!tty_hung_up_p(filp)) port->count--; - } spin_unlock_irqrestore(&port->lock, flags); port->blocked_open++; @@ -361,12 +359,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self, __set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); - if (extra_count) { - /* ++ is not atomic, so this should be protected - Jean II */ - spin_lock_irqsave(&port->lock, flags); + spin_lock_irqsave(&port->lock, flags); + if (!tty_hung_up_p(filp)) port->count++; - spin_unlock_irqrestore(&port->lock, flags); - } + spin_unlock_irqrestore(&port->lock, flags); port->blocked_open--; IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",