Skip to contentSkip to conversation

Fix the TIOCGICOUNT problem for good

PATCH In review Alan Cox 5 participants 10 messages Sep 16, 2010 – Sep 20, 2010

Subsystems (9)
lore
Share & tools
lore

Alan Cox

author
#0 lore raw

cover Fix the TIOCGICOUNT problem for good

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

---

Alan Cox (3):
tty: icount changeover for other main devices
tty: Convert the USB drivers to the new icount interface
tty: Make tiocgicount a handler

 arch/ia64/hp/sim/simserial.c          |   12 -----
 drivers/char/amiserial.c              |   56 ++++++++++++++-----------
 drivers/char/cyclades.c               |   49 ++++++++++++----------
 drivers/char/ip2/ip2main.c            |   71 +++++++++++++++++++-------------
 drivers/char/mxser.c                  |   62 ++++++++++++++++------------
 drivers/char/nozomi.c                 |   37 ++++++++---------
 drivers/char/pcmcia/synclink_cs.c     |   60 ++++++++++++---------------
 drivers/char/synclink.c               |   73 +++++++++++++++------------------
 drivers/char/synclink_gt.c            |   55 +++++++++++++------------
 drivers/char/synclinkmp.c             |   61 +++++++++++++---------------
 drivers/char/tty_io.c                 |   21 +++++++++
 drivers/net/usb/hso.c                 |   35 +++++++---------
 drivers/serial/68360serial.c          |   51 +++++++++++------------
 drivers/serial/serial_core.c          |   35 +++++++---------
 drivers/usb/serial/ark3116.c          |   40 +++++++++---------
 drivers/usb/serial/ftdi_sio.c         |    1 
 drivers/usb/serial/io_edgeport.c      |   49 ++++++++++++----------
 drivers/usb/serial/io_tables.h        |    4 ++
 drivers/usb/serial/io_ti.c            |   29 ++++++++++---
 drivers/usb/serial/mos7720.c          |   50 +++++++++++++----------
 drivers/usb/serial/mos7840.c          |   50 +++++++++++++----------
 drivers/usb/serial/ssu100.c           |   46 +++++++++++----------
 drivers/usb/serial/ti_usb_3410_5052.c |   37 +++++++++++++----
 drivers/usb/serial/usb-serial.c       |   13 ++++++
 include/linux/tty_driver.h            |    9 ++++
 include/linux/usb/serial.h            |    2 +
 net/bluetooth/rfcomm/tty.c            |    4 --
 27 files changed, 561 insertions(+), 451 deletions(-)
Signature · 8 lines
Rust greets time a grave to steam, in mire gloom to no more gleam
Does care die quiet and scarred, Berry red in Barry yard ?

Rusted steel at rest dust all, old sump oil lead is my pall
long rather to linger there, cold my fire once called me fair

Who knows now when I was new, speed in flow and on I flew
I turned eyes to run and see, in steam a dream adore me
author
#1 lore raw

PATCH 1/3 tty: Make tiocgicount a handler

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.

---

 drivers/char/tty_io.c           |   21 +++++++++++++++++++++
 drivers/serial/serial_core.c    |   35 ++++++++++++++++-------------------
 drivers/usb/serial/usb-serial.c |   13 +++++++++++++
 include/linux/tty_driver.h      |    9 +++++++++
 include/linux/usb/serial.h      |    2 ++
 5 files changed, 61 insertions(+), 19 deletions(-)
drivers/char/tty_io.c +21 -0
index e185db3..6873240 100644
@@ -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:
drivers/serial/serial_core.c +16 -19
index bc6cddd..c4ea146 100644
@@ -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,
drivers/usb/serial/usb-serial.c +13 -0
index 7a2177c..e64da74 100644
@@ -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,
include/linux/tty_driver.h +9 -0
index b086779..db2d227 100644
@@ -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);
include/linux/usb/serial.h +2 -0
index 55675b1..16d682f 100644
@@ -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);
author
#2 lore raw

PATCH 2/3 tty: Convert the USB drivers to the new icount interface

In reply to Alan Cox

Simple pasting job using the new ops function. Also fix a couple of devices directly returning the internal struct (which happens at this point to match for the fields that matter but isn't correct or futureproof)

---

 drivers/net/usb/hso.c                 |   35 +++++++++++------------
 drivers/usb/serial/ark3116.c          |   40 ++++++++++++++------------
 drivers/usb/serial/ftdi_sio.c         |    1 +
 drivers/usb/serial/io_edgeport.c      |   49 ++++++++++++++++++--------------
 drivers/usb/serial/io_tables.h        |    4 +++
 drivers/usb/serial/io_ti.c            |   29 +++++++++++++++----
 drivers/usb/serial/mos7720.c          |   50 +++++++++++++++++++--------------
 drivers/usb/serial/mos7840.c          |   50 +++++++++++++++++++--------------
 drivers/usb/serial/ssu100.c           |   46 +++++++++++++++++-------------
 drivers/usb/serial/ti_usb_3410_5052.c |   37 +++++++++++++++++++-----
 10 files changed, 203 insertions(+), 138 deletions(-)
drivers/net/usb/hso.c +16 -19
index 4f123f8..e18ef9d 100644
@@ -1636,11 +1636,11 @@ hso_wait_modem_status(struct hso_serial *serial, unsigned long arg)
  * NB: both 1->0 and 0->1 transitions are counted except for
  *     RI where only 0->1 is counted.
  */
-static int hso_get_count(struct hso_serial *serial,
-			  struct serial_icounter_struct __user *icnt)
+static int hso_get_count(struct tty_struct *tty,
+		  struct serial_icounter_struct *icount)
 {
-	struct serial_icounter_struct icount;
 	struct uart_icount cnow;
+	struct hso_serial *serial = get_serial_by_tty(tty);
 	struct hso_tiocmget  *tiocmget = serial->tiocmget;
 
 	if (!tiocmget)
@@ -1649,19 +1649,19 @@ static int hso_get_count(struct hso_serial *serial,
 	memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
 	spin_unlock_irq(&serial->serial_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;
 }
 
 
@@ -1753,10 +1753,6 @@ static int hso_serial_ioctl(struct tty_struct *tty, struct file *file,
 	case TIOCMIWAIT:
 		ret = hso_wait_modem_status(serial, arg);
 		break;
-
-	case TIOCGICOUNT:
-		ret = hso_get_count(serial, uarg);
-		break;
 	default:
 		ret = -ENOIOCTLCMD;
 		break;
@@ -3289,6 +3285,7 @@ static const struct tty_operations hso_serial_ops = {
 	.chars_in_buffer = hso_serial_chars_in_buffer,
 	.tiocmget = hso_serial_tiocmget,
 	.tiocmset = hso_serial_tiocmset,
+	.get_icount = hso_get_count,
 	.unthrottle = hso_unthrottle
 };
 
drivers/usb/serial/ark3116.c +21 -19
index 4e41a2a..8f1d4fb 100644
@@ -411,6 +411,26 @@ err_out:
 	return result;
 }
 
+static int ark3116_get_icount(struct tty_struct *tty,
+					struct serial_icounter_struct *icount)
+{
+	struct usb_serial_port *port = tty->driver_data;
+	struct ark3116_private *priv = usb_get_serial_port_data(port);
+	struct async_icount cnow = priv->icount;
+	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 0;
+}
+
 static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
 			 unsigned int cmd, unsigned long arg)
 {
@@ -460,25 +480,6 @@ static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
 				return 0;
 		}
 		break;
-	case TIOCGICOUNT: {
-		struct serial_icounter_struct icount;
-		struct async_icount cnow = priv->icount;
-		memset(&icount, 0, sizeof(icount));
-		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;
-		if (copy_to_user(user_arg, &icount, sizeof(icount)))
-			return -EFAULT;
-		return 0;
-	}
 	}
 
 	return -ENOIOCTLCMD;
@@ -736,6 +737,7 @@ static struct usb_serial_driver ark3116_device = {
 	.ioctl =		ark3116_ioctl,
 	.tiocmget =		ark3116_tiocmget,
 	.tiocmset =		ark3116_tiocmset,
+	.get_icount =		ark3116_get_icount,
 	.open =			ark3116_open,
 	.close =		ark3116_close,
 	.break_ctl = 		ark3116_break_ctl,
drivers/usb/serial/ftdi_sio.c +1 -0
index 1f30a01..5002f1f 100644
@@ -2167,6 +2167,7 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
 	 * - mask passed in arg for lines of interest
 	 *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
 	 * Caller should use TIOCGICOUNT to see which one it was.
+	 * (except that the driver doesn't support it !)
 	 *
 	 * This code is borrowed from linux/drivers/char/serial.c
 	 */
drivers/usb/serial/io_edgeport.c +27 -22

79 lines not on this page · raw message

drivers/usb/serial/io_tables.h +4 -0
index feb56a4..6ab2a3f 100644
@@ -123,6 +123,7 @@ static struct usb_serial_driver edgeport_2port_device = {
 	.set_termios		= edge_set_termios,
 	.tiocmget		= edge_tiocmget,
 	.tiocmset		= edge_tiocmset,
+	.get_icount		= edge_get_icount,
 	.write			= edge_write,
 	.write_room		= edge_write_room,
 	.chars_in_buffer	= edge_chars_in_buffer,
@@ -152,6 +153,7 @@ static struct usb_serial_driver edgeport_4port_device = {
 	.set_termios		= edge_set_termios,
 	.tiocmget		= edge_tiocmget,
 	.tiocmset		= edge_tiocmset,
+	.get_icount		= edge_get_icount,
 	.write			= edge_write,
 	.write_room		= edge_write_room,
 	.chars_in_buffer	= edge_chars_in_buffer,
@@ -181,6 +183,7 @@ static struct usb_serial_driver edgeport_8port_device = {
 	.set_termios		= edge_set_termios,
 	.tiocmget		= edge_tiocmget,
 	.tiocmset		= edge_tiocmset,
+	.get_icount		= edge_get_icount,
 	.write			= edge_write,
 	.write_room		= edge_write_room,
 	.chars_in_buffer	= edge_chars_in_buffer,
@@ -209,6 +212,7 @@ static struct usb_serial_driver epic_device = {
 	.set_termios		= edge_set_termios,
 	.tiocmget		= edge_tiocmget,
 	.tiocmset		= edge_tiocmset,
+	.get_icount		= edge_get_icount,
 	.write			= edge_write,
 	.write_room		= edge_write_room,
 	.chars_in_buffer	= edge_chars_in_buffer,
drivers/usb/serial/io_ti.c +22 -7
index baf7037..22506b0 100644
@@ -2506,6 +2506,27 @@ static int edge_tiocmget(struct tty_struct *tty, struct file *file)
 	return result;
 }
 
+static int edge_get_icount(struct tty_struct *tty,
+				struct serial_icounter_struct *icount)
+{
+	struct usb_serial_port *port = tty->driver_data;
+	struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+	struct async_icount *ic = &edge_port->icount;
+
+	icount->cts = ic->cts;
+	icount->dsr = ic->dsr;
+	icount->rng = ic->rng;
+	icount->dcd = ic->dcd;
+	icount->tx = ic->tx;
+        icount->rx = ic->rx;
+        icount->frame = ic->frame;
+        icount->parity = ic->parity;
+        icount->overrun = ic->overrun;
+        icount->brk = ic->brk;
+        icount->buf_overrun = ic->buf_overrun;
+	return 0;
+}
+
 static int get_serial_info(struct edgeport_port *edge_port,
 				struct serial_struct __user *retinfo)
 {
@@ -2568,13 +2589,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
 		}
 		/* not reached */
 		break;
-	case TIOCGICOUNT:
-		dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
-		     port->number, edge_port->icount.rx, edge_port->icount.tx);
-		if (copy_to_user((void __user *)arg, &edge_port->icount,
-				sizeof(edge_port->icount)))
-			return -EFAULT;
-		return 0;
 	}
 	return -ENOIOCTLCMD;
 }
@@ -2754,6 +2768,7 @@ static struct usb_serial_driver edgeport_1port_device = {
 	.set_termios		= edge_set_termios,
 	.tiocmget		= edge_tiocmget,
 	.tiocmset		= edge_tiocmset,
+	.get_icount		= edge_get_icount,
 	.write			= edge_write,
 	.write_room		= edge_write_room,
 	.chars_in_buffer	= edge_chars_in_buffer,
drivers/usb/serial/mos7720.c +29 -21

77 lines not on this page · raw message

drivers/usb/serial/mos7840.c +29 -21

74 lines not on this page · raw message

drivers/usb/serial/ssu100.c +25 -21

64 lines not on this page · raw message

drivers/usb/serial/ti_usb_3410_5052.c +29 -8
index 90979a1..a5b3684 100644
@@ -108,6 +108,8 @@ static void ti_throttle(struct tty_struct *tty);
 static void ti_unthrottle(struct tty_struct *tty);
 static int ti_ioctl(struct tty_struct *tty, struct file *file,
 		unsigned int cmd, unsigned long arg);
+static int ti_get_icount(struct tty_struct *tty,
+		struct serial_icounter_struct *icount);
 static void ti_set_termios(struct tty_struct *tty,
 		struct usb_serial_port *port, struct ktermios *old_termios);
 static int ti_tiocmget(struct tty_struct *tty, struct file *file);
@@ -237,6 +239,7 @@ static struct usb_serial_driver ti_1port_device = {
 	.set_termios		= ti_set_termios,
 	.tiocmget		= ti_tiocmget,
 	.tiocmset		= ti_tiocmset,
+	.get_icount		= ti_get_icount,
 	.break_ctl		= ti_break,
 	.read_int_callback	= ti_interrupt_callback,
 	.read_bulk_callback	= ti_bulk_in_callback,
@@ -265,6 +268,7 @@ static struct usb_serial_driver ti_2port_device = {
 	.set_termios		= ti_set_termios,
 	.tiocmget		= ti_tiocmget,
 	.tiocmset		= ti_tiocmset,
+	.get_icount		= ti_get_icount,
 	.break_ctl		= ti_break,
 	.read_int_callback	= ti_interrupt_callback,
 	.read_bulk_callback	= ti_bulk_in_callback,
@@ -788,6 +792,31 @@ static void ti_unthrottle(struct tty_struct *tty)
 	}
 }
 
+static int ti_get_icount(struct tty_struct *tty,
+		struct serial_icounter_struct *icount)
+{
+	struct usb_serial_port *port = tty->driver_data;
+	struct ti_port *tport = usb_get_serial_port_data(port);
+	struct async_icount cnow = tport->tp_icount;
+	
+	dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
+		__func__, port->number,
+		cnow.rx, cnow.tx);
+
+	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 0;
+}
 
 static int ti_ioctl(struct tty_struct *tty, struct file *file,
 	unsigned int cmd, unsigned long arg)
@@ -830,14 +859,6 @@ static int ti_ioctl(struct tty_struct *tty, struct file *file,
 			cprev = cnow;
 		}
 		break;
-	case TIOCGICOUNT:
-		dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
-				__func__, port->number,
-				tport->tp_icount.rx, tport->tp_icount.tx);
-		if (copy_to_user((void __user *)arg, &tport->tp_icount,
-					sizeof(tport->tp_icount)))
-			return -EFAULT;
-		return 0;
 	}
 	return -ENOIOCTLCMD;
 }
author
#3 lore raw

PATCH 3/3 tty: icount changeover for other main devices

In reply to Alan Cox

Again basically cut and paste

---

 arch/ia64/hp/sim/simserial.c      |   12 +-----
 drivers/char/amiserial.c          |   56 ++++++++++++++++------------
 drivers/char/cyclades.c           |   49 +++++++++++++------------
 drivers/char/ip2/ip2main.c        |   71 ++++++++++++++++++++++--------------
 drivers/char/mxser.c              |   62 ++++++++++++++++++-------------
 drivers/char/nozomi.c             |   37 +++++++++----------
 drivers/char/pcmcia/synclink_cs.c |   60 ++++++++++++++----------------
 drivers/char/synclink.c           |   73 +++++++++++++++++--------------------
 drivers/char/synclink_gt.c        |   55 +++++++++++++++-------------
 drivers/char/synclinkmp.c         |   61 ++++++++++++++-----------------
 drivers/serial/68360serial.c      |   51 +++++++++++++-------------
 net/bluetooth/rfcomm/tty.c        |    4 --
 12 files changed, 297 insertions(+), 294 deletions(-)
arch/ia64/hp/sim/simserial.c +1 -11
index 1e8d71a..13633da 100644
@@ -395,7 +395,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
 {
 	if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
 	    (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
-	    (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
+	    (cmd != TIOCMIWAIT)) {
 		if (tty->flags & (1 << TTY_IO_ERROR))
 		    return -EIO;
 	}
@@ -433,16 +433,6 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
 		case TIOCMIWAIT:
 			printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n");
 			return 0;
-		/*
-		 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
-		 * Return: write counters to the user passed counter struct
-		 * NB: both 1->0 and 0->1 transitions are counted except for
-		 *     RI where only 0->1 is counted.
-		 */
-		case TIOCGICOUNT:
-			printk(KERN_INFO "rs_ioctl: TIOCGICOUNT called\n");
-			return 0;
-
 		case TIOCSERGWILD:
 		case TIOCSERSWILD:
 			/* "setserial -W" is called in Debian boot */
drivers/char/amiserial.c +31 -25

74 lines not on this page · raw message

drivers/char/cyclades.c +26 -23

67 lines not on this page · raw message

drivers/char/ip2/ip2main.c +43 -28

95 lines not on this page · raw message

drivers/char/mxser.c +35 -27

86 lines not on this page · raw message

drivers/char/nozomi.c +18 -19
index 817169c..dd3f9b1 100644
@@ -1804,24 +1804,24 @@ static int ntty_cflags_changed(struct port *port, unsigned long flags,
 	return ret;
 }
 
-static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp)
+static int ntty_tiocgicount(struct tty_struct *tty,
+				struct serial_icounter_struct *icount)
 {
+	struct port *port = tty->driver_data;
 	const struct async_icount cnow = port->tty_icount;
-	struct serial_icounter_struct icount;
-
-	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(argp, &icount, sizeof(icount)) ? -EFAULT : 0;
+
+	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 0;
 }
 
 static int ntty_ioctl(struct tty_struct *tty, struct file *file,
@@ -1840,9 +1840,7 @@ static int ntty_ioctl(struct tty_struct *tty, struct file *file,
 		rval = wait_event_interruptible(port->tty_wait,
 				ntty_cflags_changed(port, arg, &cprev));
 		break;
-	} case TIOCGICOUNT:
-		rval = ntty_ioctl_tiocgicount(port, argp);
-		break;
+	}
 	default:
 		DBG1("ERR: 0x%08X, %d", cmd, cmd);
 		break;
@@ -1922,6 +1920,7 @@ static const struct tty_operations tty_ops = {
 	.chars_in_buffer = ntty_chars_in_buffer,
 	.tiocmget = ntty_tiocmget,
 	.tiocmset = ntty_tiocmset,
+	.get_icount = ntty_tiocgicount,
 	.install = ntty_install,
 	.cleanup = ntty_cleanup,
 };
drivers/char/pcmcia/synclink_cs.c +27 -33

85 lines not on this page · raw message

drivers/char/synclink.c +34 -39

104 lines not on this page · raw message

drivers/char/synclink_gt.c +29 -26

91 lines not on this page · raw message

drivers/char/synclinkmp.c +28 -33

91 lines not on this page · raw message

drivers/serial/68360serial.c +25 -26

69 lines not on this page · raw message

net/bluetooth/rfcomm/tty.c +0 -4
index befc3a5..84c2a4d 100644
@@ -844,10 +844,6 @@ static int rfcomm_tty_ioctl(struct tty_struct *tty, struct file *filp, unsigned
 		BT_DBG("TIOCMIWAIT");
 		break;
 
-	case TIOCGICOUNT:
-		BT_DBG("TIOCGICOUNT");
-		break;
-
 	case TIOCGSERIAL:
 		BT_ERR("TIOCGSERIAL is not supported");
 		return -ENOIOCTLCMD;
#4 lore raw
In reply to Alan Cox
Quoted 3 lines · Alan Cox

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

Looks good. But is it ok if I keep the one driver patch I have now for .36 and queue this up for .37? I'll handle the merge conflicts myself.

thanks,

greg k-h

#5 lore raw
Quoted 7 lines · On Thu, 16 Sep 2010 11:44:46 -0700 Greg KH <[email protected]> wrote:
Quoted 3 lines · Alan Cox

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

Looks good. But is it ok if I keep the one driver patch I have now for .36 and queue this up for .37? I'll handle the merge conflicts myself.

Probably sensible given the closeness of .36 and the scale of changes

maintainer
#6 lore raw
In reply to Alan Cox

From: Alan Cox <[email protected]>
Date: Thu, 16 Sep 2010 18:21:06 +0100

Quoted 10 lines

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

---

Alan Cox (3):
tty: icount changeover for other main devices
tty: Convert the USB drivers to the new icount interface
tty: Make tiocgicount a handler

This is a good plan for the next merge window, but for the current -rc series and -stable we'd better just fix the individual cases.

#7 lore raw
Quoted 9 lines · David Miller

From: Alan Cox <[email protected]>
Date: Thu, 16 Sep 2010 18:21:06 +0100

Quoted 6 lines

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

---

Quoted 7 lines
Quoted 4 lines

Alan Cox (3):
tty: icount changeover for other main devices
tty: Convert the USB drivers to the new icount interface
tty: Make tiocgicount a handler

This is a good plan for the next merge window, but for the current -rc series and -stable we'd better just fix the individual cases.

Agreed, that's the plan now.

thanks,

greg k-h

#8 lore raw
In reply to Alan Cox
Quoted 3 lines · Alan Cox

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

Btw, I wonder if all the standard tty ioctls should get similar treatment. That way we have a nice enough skeleton of what needs to be implemented in every tty driver instead of passing down the raw ioctl method.

author
#9 lore raw
Quoted 10 lines · On Sat, 18 Sep 2010 11:58:20 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 4 lines · Alan Cox

Remembering to clear fields is something driver authors are simply never going to remember to get right every new driver. Instead take the problem away from them and give them a simple interface to do the job.

Btw, I wonder if all the standard tty ioctls should get similar treatment. That way we have a nice enough skeleton of what needs to be implemented in every tty driver instead of passing down the raw ioctl method.

They have pretty much entirely now - TIOCMIWAIT is the main one that hasn't been done, but that really wants a generic implementation in tty_port that most drivers could then use.

Alan