All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Alan Cox <alan@linux.intel.com>, Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 24/49] tty: Make tiocgicount a handler
Date: Fri, 22 Oct 2010 11:21:03 -0700	[thread overview]
Message-ID: <1287771688-14805-24-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20101022175112.GC13489@kroah.com>

From: Alan Cox <alan@linux.intel.com>

Dan Rosenberg noted that various drivers return the struct with uncleared
fields. Instead of spending forever trying to stomp all the drivers that
get it wrong (and every new driver) do the job in one place.

This first patch adds the needed operations and hooks them up, including
the needed USB midlayer and serial core plumbing.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/char/tty_io.c           |   21 +++++++++++++++++++++
 drivers/serial/serial_core.c    |   37 +++++++++++++++++--------------------
 drivers/usb/serial/usb-serial.c |   13 +++++++++++++
 include/linux/tty_driver.h      |    9 +++++++++
 include/linux/usb/serial.h      |    2 ++
 5 files changed, 62 insertions(+), 20 deletions(-)

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index e185db3..c05c5af 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -96,6 +96,7 @@
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/seq_file.h>
+#include <linux/serial.h>
 
 #include <linux/uaccess.h>
 #include <asm/system.h>
@@ -2511,6 +2512,20 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
 	return tty->ops->tiocmset(tty, file, set, clear);
 }
 
+static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
+{
+	int retval = -EINVAL;
+	struct serial_icounter_struct icount;
+	memset(&icount, 0, sizeof(icount));
+	if (tty->ops->get_icount)
+		retval = tty->ops->get_icount(tty, &icount);
+	if (retval != 0)
+		return retval;
+	if (copy_to_user(arg, &icount, sizeof(icount)))
+		return -EFAULT;
+	return 0;
+}
+
 struct tty_struct *tty_pair_get_tty(struct tty_struct *tty)
 {
 	if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -2631,6 +2646,12 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	case TIOCMBIC:
 	case TIOCMBIS:
 		return tty_tiocmset(tty, file, cmd, p);
+	case TIOCGICOUNT:
+		retval = tty_tiocgicount(tty, p);
+		/* For the moment allow fall through to the old method */
+        	if (retval != -EINVAL)
+			return retval;
+		break;
 	case TCFLSH:
 		switch (arg) {
 		case TCIFLUSH:
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index bc6cddd..c4ea146 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1074,10 +1074,10 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
  * NB: both 1->0 and 0->1 transitions are counted except for
  *     RI where only 0->1 is counted.
  */
-static int uart_get_count(struct uart_state *state,
-			  struct serial_icounter_struct __user *icnt)
+static int uart_get_icount(struct tty_struct *tty,
+			  struct serial_icounter_struct *icount)
 {
-	struct serial_icounter_struct icount;
+	struct uart_state *state = tty->driver_data;
 	struct uart_icount cnow;
 	struct uart_port *uport = state->uart_port;
 
@@ -1085,19 +1085,19 @@ static int uart_get_count(struct uart_state *state,
 	memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
 	spin_unlock_irq(&uport->lock);
 
-	icount.cts         = cnow.cts;
-	icount.dsr         = cnow.dsr;
-	icount.rng         = cnow.rng;
-	icount.dcd         = cnow.dcd;
-	icount.rx          = cnow.rx;
-	icount.tx          = cnow.tx;
-	icount.frame       = cnow.frame;
-	icount.overrun     = cnow.overrun;
-	icount.parity      = cnow.parity;
-	icount.brk         = cnow.brk;
-	icount.buf_overrun = cnow.buf_overrun;
+	icount->cts         = cnow.cts;
+	icount->dsr         = cnow.dsr;
+	icount->rng         = cnow.rng;
+	icount->dcd         = cnow.dcd;
+	icount->rx          = cnow.rx;
+	icount->tx          = cnow.tx;
+	icount->frame       = cnow.frame;
+	icount->overrun     = cnow.overrun;
+	icount->parity      = cnow.parity;
+	icount->brk         = cnow.brk;
+	icount->buf_overrun = cnow.buf_overrun;
 
-	return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0;
+	return 0;
 }
 
 /*
@@ -1150,10 +1150,6 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
 	case TIOCMIWAIT:
 		ret = uart_wait_modem_status(state, arg);
 		break;
-
-	case TIOCGICOUNT:
-		ret = uart_get_count(state, uarg);
-		break;
 	}
 
 	if (ret != -ENOIOCTLCMD)
@@ -2295,6 +2291,7 @@ static const struct tty_operations uart_ops = {
 #endif
 	.tiocmget	= uart_tiocmget,
 	.tiocmset	= uart_tiocmset,
+	.get_icount	= uart_get_icount,
 #ifdef CONFIG_CONSOLE_POLL
 	.poll_init	= uart_poll_init,
 	.poll_get_char	= uart_poll_get_char,
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7a2177c..e64da74 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -519,6 +519,18 @@ static int serial_tiocmset(struct tty_struct *tty, struct file *file,
 	return -EINVAL;
 }
 
+static int serial_get_icount(struct tty_struct *tty,
+				struct serial_icounter_struct *icount)
+{
+	struct usb_serial_port *port = tty->driver_data;
+
+	dbg("%s - port %d", __func__, port->number);
+
+	if (port->serial->type->get_icount)
+		return port->serial->type->get_icount(tty, icount);
+	return -EINVAL;
+}
+
 /*
  * We would be calling tty_wakeup here, but unfortunately some line
  * disciplines have an annoying habit of calling tty->write from
@@ -1195,6 +1207,7 @@ static const struct tty_operations serial_ops = {
 	.chars_in_buffer =	serial_chars_in_buffer,
 	.tiocmget =		serial_tiocmget,
 	.tiocmset =		serial_tiocmset,
+	.get_icount = 		serial_get_icount,
 	.cleanup = 		serial_cleanup,
 	.install = 		serial_install,
 	.proc_fops =		&serial_proc_fops,
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index b086779..db2d227 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -224,6 +224,12 @@
  *	unless the tty also has a valid tty->termiox pointer.
  *
  *	Optional: Called under the termios lock
+ *
+ * int (*get_icount)(struct tty_struct *tty, struct serial_icounter *icount);
+ *
+ *	Called when the device receives a TIOCGICOUNT ioctl. Passed a kernel
+ *	structure to complete. This method is optional and will only be called
+ *	if provided (otherwise EINVAL will be returned).
  */
 
 #include <linux/fs.h>
@@ -232,6 +238,7 @@
 
 struct tty_struct;
 struct tty_driver;
+struct serial_icounter_struct;
 
 struct tty_operations {
 	struct tty_struct * (*lookup)(struct tty_driver *driver,
@@ -268,6 +275,8 @@ struct tty_operations {
 			unsigned int set, unsigned int clear);
 	int (*resize)(struct tty_struct *tty, struct winsize *ws);
 	int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
+	int (*get_icount)(struct tty_struct *tty,
+				struct serial_icounter_struct *icount);
 #ifdef CONFIG_CONSOLE_POLL
 	int (*poll_init)(struct tty_driver *driver, int line, char *options);
 	int (*poll_get_char)(struct tty_driver *driver, int line);
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 55675b1..16d682f 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -271,6 +271,8 @@ struct usb_serial_driver {
 	int  (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int  (*tiocmset)(struct tty_struct *tty, struct file *file,
 			 unsigned int set, unsigned int clear);
+	int  (*get_icount)(struct tty_struct *tty,
+			struct serial_icounter_struct *icount);
 	/* Called by the tty layer for port level work. There may or may not
 	   be an attached tty at this point */
 	void (*dtr_rts)(struct usb_serial_port *port, int on);
-- 
1.7.2


  parent reply	other threads:[~2010-10-22 18:21 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-22 17:51 [GIT PATCH] TTY/Serial merge for .37-rc1 Greg KH
2010-10-22 18:20 ` [PATCH 01/49] tty: add tty_struct->dev pointer to corresponding device instance Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 02/49] serport: place serport serio device correctly in the device tree Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 03/49] serial: mfd: snprintf() returns largish values Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 04/49] serial: Add CONSOLE_POLL support for uartlite Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 05/49] tty: Remove __GFP_NOFAIL from tty_add_file() Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 06/49] ioctl: Use asm-generic/ioctls.h on arm (enables termiox) Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 07/49] ioctl: Use asm-generic/ioctls.h on avr32 " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 08/49] ioctl: Use asm-generic/ioctls.h on cris " Greg Kroah-Hartman
2010-10-25 14:10   ` Jesper Nilsson
2010-10-22 18:20 ` [PATCH 09/49] ioctl: Use asm-generic/ioctls.h on frv " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 10/49] ioctl: Use asm-generic/ioctls.h on h8300 " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 11/49] ioctl: Use asm-generic/ioctls.h on ia64 " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 12/49] ioctl: Use asm-generic/ioctls.h on m32r " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 13/49] ioctl: Use asm-generic/ioctls.h on m68k " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 14/49] ioctl: Use asm-generic/ioctls.h on mn10300 " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 15/49] ioctl: Use asm-generic/ioctls.h on s390 " Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 16/49] serial-core: skip call set_termios/console_start when no_console_suspend Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 17/49] serial-core: restore termios settings when resume console ports Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 18/49] add ttyprintk driver Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 19/49] Char: mxser, call pci_disable_device from probe/remove Greg Kroah-Hartman
2010-10-22 18:20 ` [PATCH 20/49] tty_io: check return code of tty_register_device Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 21/49] serial: mrst_max3110: some code cleanup Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 22/49] serial: mrst_max3110: Make the IRQ option runtime Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 23/49] serial: max3107: Fix memory leaks when returning on error Greg Kroah-Hartman
2010-10-22 18:21 ` Greg Kroah-Hartman [this message]
2010-10-22 18:21 ` [PATCH 25/49] tty: Convert the USB drivers to the new icount interface Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 26/49] tty: icount changeover for other main devices Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 27/49] tty: Fix warning left over from TIOCGICOUNT changes Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 28/49] tty: Add a new file /proc/tty/consoles Greg Kroah-Hartman
2010-10-23 11:24   ` Jiri Slaby
2010-10-23 11:40   ` Jiri Slaby
2010-10-23 11:51     ` Al Viro
2010-10-23 12:00       ` Jiri Slaby
2010-10-23 12:26         ` Al Viro
2010-10-23 15:46           ` Greg KH
2010-10-23 16:53             ` Greg KH
2010-10-23 17:03               ` Greg KH
2010-10-23 12:04       ` Al Viro
2010-10-25  7:51     ` Dr. Werner Fink
2010-10-27  0:50       ` Al Viro
2010-10-27  9:27         ` Dr. Werner Fink
2010-10-27  9:51           ` Jiri Slaby
2010-10-27 11:31             ` Dr. Werner Fink
2010-10-23 11:46   ` Christoph Hellwig
2010-10-22 18:21 ` [PATCH 29/49] vcs: add poll/fasync support Greg Kroah-Hartman
2010-11-10  0:12   ` Kay Sievers
2010-11-10  1:26     ` Nicolas Pitre
2010-11-10  1:42       ` Kay Sievers
2010-11-10  6:33         ` Nicolas Pitre
2010-11-10  9:35           ` Kay Sievers
2010-10-22 18:21 ` [PATCH 30/49] vcs: invoke the vt update callback when /dev/vcs* is written to Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 31/49] tty: MAINTAINERS: add drivers/serial/jsm/ as maintained driver Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 32/49] serial: 8250: Don't delay after transmitter is ready Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 33/49] serial: mark the 8250 driver as maintained Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 34/49] serial: Factor out uart_poll_timeout() from 8250 driver Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 35/49] altera_uart: Add support for polling mode (IRQ-less) Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 36/49] altera_uart: Add support for getting mapbase and IRQ from resources Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 37/49] altera_uart: Add support for different address strides Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 38/49] altera_uart: Make it possible to use Altera UART and 8250 ports together Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 39/49] altera_uart: Fixup type usage of port flags Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 40/49] altera_uart: Fix missing prototype for registering an early console Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 41/49] altera_uart: Don't use plain integer as NULL pointer Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 42/49] 8250: allow platforms to override PM hook Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 43/49] Alchemy: Add UART PM methods Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 44/49] jsm: Remove the uart port on errors Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 45/49] serial: mfd: add more baud rates support Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 46/49] serial/imx: check that the buffer is non-empty before sending it out Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 47/49] serial: abstraction for 8250 legacy ports Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 48/49] serial: bfin_sport_uart: speed up sport RX sample rate to be 3% faster Greg Kroah-Hartman
2010-10-22 18:21 ` [PATCH 49/49] serial8250: ratelimit "too much work" error Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1287771688-14805-24-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=alan@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.