From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752122AbbEKB72 (ORCPT ); Sun, 10 May 2015 21:59:28 -0400 Received: from cantor2.suse.de ([195.135.220.15]:48192 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750756AbbEKB7Q (ORCPT ); Sun, 10 May 2015 21:59:16 -0400 From: NeilBrown To: Mark Rutland , One Thousand Gnomes , Peter Hurley , Arnd Bergmann , Greg Kroah-Hartman , Sebastian Reichel , Rob Herring , Pavel Machek , Grant Likely , Jiri Slaby Date: Mon, 11 May 2015 11:56:14 +1000 Subject: [PATCH 1/4] TTY: use class_find_device to find port in uart_suspend/resume. Cc: GTA04 owners , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <20150511015614.5709.7099.stgit@notabene.brown> In-Reply-To: <20150511013540.5709.93626.stgit@notabene.brown> References: <20150511013540.5709.93626.stgit@notabene.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org uart_{suspend,resume}_port search the children of a uart device to find a particular tty device. This requires all the ttys to be direct children of the uart. A future patch will allow a 'tty_slave' to intervene between the port and the uart, voiding this requirement. So change to use class_find_device. This is made possible by exporting a "tty_find_device" from tty_io.c. This new "tty_find_device" is very similar to the existing tty_get_device() which has a single caller, so discard tty_get_device() and just use tty_find_device(). Signed-off-by: NeilBrown --- drivers/tty/serial/serial_core.c | 21 ++++++++------------- drivers/tty/tty_io.c | 6 +++--- include/linux/tty.h | 1 + 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index eb5b03be9dfd..3ea16f524e89 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2005,26 +2005,19 @@ struct uart_match { struct uart_driver *driver; }; -static int serial_match_port(struct device *dev, void *data) -{ - struct uart_match *match = data; - struct tty_driver *tty_drv = match->driver->tty_driver; - dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) + - match->port->line; - - return dev->devt == devt; /* Actually, only one tty per port */ -} int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport) { struct uart_state *state = drv->state + uport->line; struct tty_port *port = &state->port; struct device *tty_dev; - struct uart_match match = {uport, drv}; + dev_t devt = MKDEV(drv->tty_driver->major, + drv->tty_driver->minor_start) + + uport->line; mutex_lock(&port->mutex); - tty_dev = device_find_child(uport->dev, &match, serial_match_port); + tty_dev = tty_find_device(devt); if (device_may_wakeup(tty_dev)) { if (!enable_irq_wake(uport->irq)) uport->irq_wake = 1; @@ -2084,12 +2077,14 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport) struct uart_state *state = drv->state + uport->line; struct tty_port *port = &state->port; struct device *tty_dev; - struct uart_match match = {uport, drv}; struct ktermios termios; + dev_t devt = MKDEV(drv->tty_driver->major, + drv->tty_driver->minor_start) + + uport->line; mutex_lock(&port->mutex); - tty_dev = device_find_child(uport->dev, &match, serial_match_port); + tty_dev = tty_find_device(devt); if (!uport->suspended && device_may_wakeup(tty_dev)) { if (uport->irq_wake) { disable_irq_wake(uport->irq); diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index e5695467598f..ccb99b772965 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3077,11 +3077,11 @@ static int dev_match_devt(struct device *dev, const void *data) } /* Must put_device() after it's unused! */ -static struct device *tty_get_device(struct tty_struct *tty) +struct device *tty_find_device(dev_t devt) { - dev_t devt = tty_devnum(tty); return class_find_device(tty_class, NULL, &devt, dev_match_devt); } +EXPORT_SYMBOL(tty_find_device); /** @@ -3123,7 +3123,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx) tty->ops = driver->ops; tty->index = idx; tty_line_name(driver, idx, tty->name); - tty->dev = tty_get_device(tty); + tty->dev = tty_find_device(tty_devnum(tty)); return tty; } diff --git a/include/linux/tty.h b/include/linux/tty.h index 358a337af598..04d5f1213700 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -461,6 +461,7 @@ extern void tty_vhangup(struct tty_struct *tty); extern int tty_hung_up_p(struct file *filp); extern void do_SAK(struct tty_struct *tty); extern void __do_SAK(struct tty_struct *tty); +extern struct device *tty_find_device(dev_t devt); extern void no_tty(void); extern void tty_flush_to_ldisc(struct tty_struct *tty); extern void tty_buffer_free_all(struct tty_port *port);