From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Hurley Subject: [PATCH tty-next 1/1] tty: Prevent tty_port destruction if tty not released Date: Wed, 18 Sep 2013 20:42:39 -0400 Message-ID: <1379551359-15000-2-git-send-email-peter@hurleysoftware.com> References: <1379551359-15000-1-git-send-email-peter@hurleysoftware.com> Return-path: Received: from mailout01.c08.mtsvc.net ([205.186.168.189]:34114 "EHLO mailout01.c08.mtsvc.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751737Ab3ISAnK (ORCPT ); Wed, 18 Sep 2013 20:43:10 -0400 In-Reply-To: <1379551359-15000-1-git-send-email-peter@hurleysoftware.com> Sender: linux-serial-owner@vger.kernel.org List-Id: linux-serial@vger.kernel.org To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Peter Hurley If the tty driver mistakenly drops the last port reference before the tty has been released, issue a diagnostic and abort the port destruction. This will leak memory and may zombify the port, but might otherwise keep the machine in runnable state. Signed-off-by: Peter Hurley --- drivers/tty/tty_port.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index 9857f7e..c94d234 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c @@ -140,6 +140,10 @@ EXPORT_SYMBOL(tty_port_destroy); static void tty_port_destructor(struct kref *kref) { struct tty_port *port = container_of(kref, struct tty_port, kref); + + /* check if last port ref was dropped before tty release */ + if (WARN_ON(port->itty)) + return; if (port->xmit_buf) free_page((unsigned long)port->xmit_buf); tty_port_destroy(port); -- 1.8.1.2