From patchwork Mon Aug 22 22:39:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 74470 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1797325qga; Mon, 22 Aug 2016 15:39:54 -0700 (PDT) X-Received: by 10.98.131.8 with SMTP id h8mr47371679pfe.124.1471905593982; Mon, 22 Aug 2016 15:39:53 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si266756pax.227.2016.08.22.15.39.53; Mon, 22 Aug 2016 15:39:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756936AbcHVWjf (ORCPT + 27 others); Mon, 22 Aug 2016 18:39:35 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:33469 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754801AbcHVWj1 (ORCPT ); Mon, 22 Aug 2016 18:39:27 -0400 Received: by mail-oi0-f65.google.com with SMTP id s207so1161194oie.0; Mon, 22 Aug 2016 15:39:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HgyH6wkTS/JudbbKU0n3RrnLlwzWi6evQfJsIIrFNEs=; b=c5y9FPOg+mMnFT7zXiASx7R04XXiWuYg9a4c7oXe0T6Yv05m0+1xMxiCYyyNKr4NZ4 ElEez5B0Dw6DPdO9LQoQPWvgGc1JW3fY+sJ4FSunVuKwyg1D05Q/GckVwglmdrNDuEwk DrfLoLHQT20P8QfoAfIrFt4PdGA3oRQGQSL9qMZ5GnPZ2a34HeEmDuXDUQrFQXmFiUX7 Z/8XrtP8CB02+qIBfRlUIj8sjbe0dw5lJe7hLs5jd3Idol8l6kMe0yfqJV1Fu4ZLUAbu e7JqOM0kwRKO+c2Nv4UYNHWQCT/4cYw2AQiQcTXYi4IUX1rUR5IpjNCAWzkcv3NziuN7 cH4g== X-Gm-Message-State: AEkoouvRBk7F6hD0ksC/FEAMRYwPgsNqz6cLMYSDQygRmdfTQuujdOmmxRKLfZDRilKM1A== X-Received: by 10.202.67.215 with SMTP id q206mr667693oia.142.1471905552288; Mon, 22 Aug 2016 15:39:12 -0700 (PDT) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id g56sm153539otc.15.2016.08.22.15.39.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Aug 2016 15:39:11 -0700 (PDT) From: Rob Herring To: Alan Cox Cc: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Hurley Subject: [PATCH 2/2] tty: serial_core: convert uart_close to use tty_port_close Date: Mon, 22 Aug 2016 17:39:10 -0500 Message-Id: <20160822223910.24453-2-robh@kernel.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160822223910.24453-1-robh@kernel.org> References: <20160822223910.24453-1-robh@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org tty_port_close handles much of the common parts of tty close. Convert uart_close to use it and move the serial_core specific parts into tty_port.shutdown function. This will be needed to use tty_port functions directly from in kernel clients. This change causes ops->stop_rx() to be called after uart_wait_until_sent() is called which I think should be fine. Otherwise, the sequence of the close should be the same. Cc: Alan Cox Cc: Peter Hurley Signed-off-by: Rob Herring --- drivers/tty/serial/serial_core.c | 56 ++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) -- 2.9.3 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 0468725..e183d2e 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1461,7 +1461,6 @@ static void uart_close(struct tty_struct *tty, struct file *filp) { struct uart_state *state = tty->driver_data; struct tty_port *port; - struct uart_port *uport; if (!state) { struct uart_driver *drv = tty->driver->driver_state; @@ -1477,56 +1476,36 @@ static void uart_close(struct tty_struct *tty, struct file *filp) port = &state->port; pr_debug("uart_close(%d) called\n", tty->index); - if (tty_port_close_start(port, tty, filp) == 0) - return; + tty_port_close(tty->port, tty, filp); +} - mutex_lock(&port->mutex); - uport = uart_port_check(state); +static void uart_tty_port_shutdown(struct tty_port *port) +{ + struct uart_state *state = container_of(port, struct uart_state, port); + struct uart_port *uport = uart_port_check(state); + spin_lock_irq(&uport->lock); /* * At this point, we stop accepting input. To do this, we * disable the receive line status interrupts. */ - if (tty_port_initialized(port) && - !WARN(!uport, "detached port still initialized!\n")) { - spin_lock_irq(&uport->lock); - uport->ops->stop_rx(uport); - spin_unlock_irq(&uport->lock); - /* - * Before we drop DTR, make sure the UART transmitter - * has completely drained; this is especially - * important if there is a transmit FIFO! - */ - uart_wait_until_sent(tty, uport->timeout); - } + WARN(!uport, "detached port still initialized!\n"); - uart_shutdown(tty, state); - tty_port_tty_set(port, NULL); + uport->ops->stop_rx(uport); - spin_lock_irq(&port->lock); + spin_unlock_irq(&uport->lock); - if (port->blocked_open) { - spin_unlock_irq(&port->lock); - if (port->close_delay) - msleep_interruptible(jiffies_to_msecs(port->close_delay)); - spin_lock_irq(&port->lock); - } else if (uport && !uart_console(uport)) { - spin_unlock_irq(&port->lock); - uart_change_pm(state, UART_PM_STATE_OFF); - spin_lock_irq(&port->lock); - } - spin_unlock_irq(&port->lock); - tty_port_set_active(port, 0); + uart_port_shutdown(port); /* - * Wake up anyone trying to open this port. + * It's possible for shutdown to be called after suspend if we get + * a DCD drop (hangup) at just the right time. Clear suspended bit so + * we don't try to resume a port that has been shutdown. */ - wake_up_interruptible(&port->open_wait); + tty_port_set_suspended(port, 0); - mutex_unlock(&port->mutex); + uart_change_pm(state, UART_PM_STATE_OFF); - tty_ldisc_flush(tty); - tty->closing = 0; } static void uart_wait_until_sent(struct tty_struct *tty, int timeout) @@ -2446,6 +2425,7 @@ static const struct tty_port_operations uart_port_ops = { .carrier_raised = uart_carrier_raised, .dtr_rts = uart_dtr_rts, .activate = uart_port_activate, + .shutdown = uart_tty_port_shutdown, }; /** @@ -2762,6 +2742,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) uport->cons = drv->cons; uport->minor = drv->tty_driver->minor_start + uport->line; + port->console = uart_console(uport); + /* * If this port is a console, then the spinlock is already * initialised.