public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: torvalds@osdl.org, linux-serial@vger.kernel.org
Subject: [PATCH 59/75] tty: kref the rocket driver
Date: Fri, 02 Jan 2009 13:48:30 +0000	[thread overview]
Message-ID: <20090102134829.13472.72723.stgit@localhost.localdomain> (raw)
In-Reply-To: <20090102133822.13472.53912.stgit@localhost.localdomain>

From: Alan Cox <alan@redhat.com>

We will need this kref fitted to make full use of the port operations.

Signed-off-by: Alan Cox <alan@redhat.com>
---

 drivers/char/rocket.c |   78 ++++++++++++++++++++++++++-----------------------
 1 files changed, 41 insertions(+), 37 deletions(-)


diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index ca6fcdc..b5e5e77 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -436,15 +436,15 @@ static void rp_do_transmit(struct r_port *info)
 #endif
 	if (!info)
 		return;
-	if (!info->port.tty) {
-		printk(KERN_WARNING "rp: WARNING %s called with "
-				"info->port.tty==NULL\n", __func__);
+	tty = tty_port_tty_get(&info->port);
+
+	if (tty == NULL) {
+		printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__);
 		clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
 		return;
 	}
 
 	spin_lock_irqsave(&info->slock, flags);
-	tty = info->port.tty;
 	info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
 
 	/*  Loop sending data to FIFO until done or FIFO full */
@@ -478,6 +478,7 @@ static void rp_do_transmit(struct r_port *info)
 	}
 
 	spin_unlock_irqrestore(&info->slock, flags);
+	tty_kref_put(tty);
 
 #ifdef ROCKET_DEBUG_INTR
 	printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
@@ -504,13 +505,13 @@ static void rp_handle_port(struct r_port *info)
 				"info->flags & NOT_INIT\n");
 		return;
 	}
-	if (!info->port.tty) {
+	tty = tty_port_tty_get(&info->port);
+	if (!tty) {
 		printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
-				"info->port.tty==NULL\n");
+				"tty==NULL\n");
 		return;
 	}
 	cp = &info->channel;
-	tty = info->port.tty;
 
 	IntMask = sGetChanIntID(cp) & info->intmask;
 #ifdef ROCKET_DEBUG_INTR
@@ -542,6 +543,7 @@ static void rp_handle_port(struct r_port *info)
 		printk(KERN_INFO "DSR change...\n");
 	}
 #endif
+	tty_kref_put(tty);
 }
 
 /*
@@ -710,7 +712,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
  *  Configures a rocketport port according to its termio settings.  Called from 
  *  user mode into the driver (exception handler).  *info CD manipulation is spinlock protected.
  */
-static void configure_r_port(struct r_port *info,
+static void configure_r_port(struct tty_struct *tty, struct r_port *info,
 			     struct ktermios *old_termios)
 {
 	unsigned cflag;
@@ -718,7 +720,7 @@ static void configure_r_port(struct r_port *info,
 	unsigned rocketMode;
 	int bits, baud, divisor;
 	CHANNEL_t *cp;
-	struct ktermios *t = info->port.tty->termios;
+	struct ktermios *t = tty->termios;
 
 	cp = &info->channel;
 	cflag = t->c_cflag;
@@ -751,7 +753,7 @@ static void configure_r_port(struct r_port *info,
 	}
 
 	/* baud rate */
-	baud = tty_get_baud_rate(info->port.tty);
+	baud = tty_get_baud_rate(tty);
 	if (!baud)
 		baud = 9600;
 	divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
@@ -769,7 +771,7 @@ static void configure_r_port(struct r_port *info,
 	sSetBaud(cp, divisor);
 
 	/* FIXME: Should really back compute a baud rate from the divisor */
-	tty_encode_baud_rate(info->port.tty, baud, baud);
+	tty_encode_baud_rate(tty, baud, baud);
 
 	if (cflag & CRTSCTS) {
 		info->intmask |= DELTA_CTS;
@@ -794,15 +796,15 @@ static void configure_r_port(struct r_port *info,
 	 * Handle software flow control in the board
 	 */
 #ifdef ROCKET_SOFT_FLOW
-	if (I_IXON(info->port.tty)) {
+	if (I_IXON(tty)) {
 		sEnTxSoftFlowCtl(cp);
-		if (I_IXANY(info->port.tty)) {
+		if (I_IXANY(tty)) {
 			sEnIXANY(cp);
 		} else {
 			sDisIXANY(cp);
 		}
-		sSetTxXONChar(cp, START_CHAR(info->port.tty));
-		sSetTxXOFFChar(cp, STOP_CHAR(info->port.tty));
+		sSetTxXONChar(cp, START_CHAR(tty));
+		sSetTxXOFFChar(cp, STOP_CHAR(tty));
 	} else {
 		sDisTxSoftFlowCtl(cp);
 		sDisIXANY(cp);
@@ -814,24 +816,24 @@ static void configure_r_port(struct r_port *info,
 	 * Set up ignore/read mask words
 	 */
 	info->read_status_mask = STMRCVROVRH | 0xFF;
-	if (I_INPCK(info->port.tty))
+	if (I_INPCK(tty))
 		info->read_status_mask |= STMFRAMEH | STMPARITYH;
-	if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
+	if (I_BRKINT(tty) || I_PARMRK(tty))
 		info->read_status_mask |= STMBREAKH;
 
 	/*
 	 * Characters to ignore
 	 */
 	info->ignore_status_mask = 0;
-	if (I_IGNPAR(info->port.tty))
+	if (I_IGNPAR(tty))
 		info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
-	if (I_IGNBRK(info->port.tty)) {
+	if (I_IGNBRK(tty)) {
 		info->ignore_status_mask |= STMBREAKH;
 		/*
 		 * If we're ignoring parity and break indicators,
 		 * ignore overruns too.  (For real raw support).
 		 */
-		if (I_IGNPAR(info->port.tty))
+		if (I_IGNPAR(tty))
 			info->ignore_status_mask |= STMRCVROVRH;
 	}
 
@@ -1015,7 +1017,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
 		info->xmit_buf = (unsigned char *) page;
 
 	tty->driver_data = info;
-	info->port.tty = tty;
+	tty_port_tty_set(&info->port, tty);
 
 	if (info->port.count++ == 0) {
 		atomic_inc(&rp_num_ports_open);
@@ -1062,15 +1064,15 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
 		 * Set up the tty->alt_speed kludge
 		 */
 		if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
-			info->port.tty->alt_speed = 57600;
+			tty->alt_speed = 57600;
 		if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
-			info->port.tty->alt_speed = 115200;
+			tty->alt_speed = 115200;
 		if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
-			info->port.tty->alt_speed = 230400;
+			tty->alt_speed = 230400;
 		if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
-			info->port.tty->alt_speed = 460800;
+			tty->alt_speed = 460800;
 
-		configure_r_port(info, NULL);
+		configure_r_port(tty, info, NULL);
 		if (tty->termios->c_cflag & CBAUD) {
 			sSetDTR(cp);
 			sSetRTS(cp);
@@ -1227,7 +1229,7 @@ static void rp_set_termios(struct tty_struct *tty,
 	/* Or CMSPAR */
 	tty->termios->c_cflag &= ~CMSPAR;
 
-	configure_r_port(info, old_termios);
+	configure_r_port(tty, info, old_termios);
 
 	cp = &info->channel;
 
@@ -1352,7 +1354,8 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
 	return 0;
 }
 
-static int set_config(struct r_port *info, struct rocket_config __user *new_info)
+static int set_config(struct tty_struct *tty, struct r_port *info,
+					struct rocket_config __user *new_info)
 {
 	struct rocket_config new_serial;
 
@@ -1364,7 +1367,7 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
 		if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
 			return -EPERM;
 		info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
-		configure_r_port(info, NULL);
+		configure_r_port(tty, info, NULL);
 		return 0;
 	}
 
@@ -1373,15 +1376,15 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
 	info->port.closing_wait = new_serial.closing_wait;
 
 	if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
-		info->port.tty->alt_speed = 57600;
+		tty->alt_speed = 57600;
 	if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
-		info->port.tty->alt_speed = 115200;
+		tty->alt_speed = 115200;
 	if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
-		info->port.tty->alt_speed = 230400;
+		tty->alt_speed = 230400;
 	if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
-		info->port.tty->alt_speed = 460800;
+		tty->alt_speed = 460800;
 
-	configure_r_port(info, NULL);
+	configure_r_port(tty, info, NULL);
 	return 0;
 }
 
@@ -1466,7 +1469,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
 		ret = get_config(info, argp);
 		break;
 	case RCKP_SET_CONFIG:
-		ret = set_config(info, argp);
+		ret = set_config(tty, info, argp);
 		break;
 	case RCKP_GET_PORTS:
 		ret = get_ports(info, argp);
@@ -1658,7 +1661,7 @@ static void rp_hangup(struct tty_struct *tty)
 
 	info->port.count = 0;
 	info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
-	info->port.tty = NULL;
+	tty_port_tty_set(&info->port, NULL);
 
 	cp = &info->channel;
 	sDisRxFIFO(cp);
@@ -1778,7 +1781,8 @@ static int rp_write(struct tty_struct *tty,
 
 	/*  Write remaining data into the port's xmit_buf */
 	while (1) {
-		if (!info->port.tty)		/* Seemingly obligatory check... */
+		/* Hung up ? */
+		if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags))
 			goto end;
 		c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
 		c = min(c, XMIT_BUF_SIZE - info->xmit_head);


  parent reply	other threads:[~2009-01-02 13:48 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-02 13:40 [PATCH 00/75] TTY updates for 2.6.29-rc Alan Cox
2009-01-02 13:40 ` [PATCH 01/75] Blackfin Serial Driver: updates kgdb over Blackfin serial driver with kgdb framework Alan Cox
2009-01-02 13:40 ` [PATCH 02/75] Blackfin Serial Driver: fix bug - SIR driver stop receiving randomly Alan Cox
2009-01-02 13:40 ` [PATCH 03/75] Blackfin Serial Driver: Clean serial console and early prink code Alan Cox
2009-01-02 13:40 ` [PATCH 04/75] Blackfin Serial Driver: Fix bug - BF527-EZKIT unable to receive large files over UART in DMA mode Alan Cox
2009-01-02 13:40 ` [PATCH 05/75] Blackfin Serial Driver: Remove BI status for known_good_char Alan Cox
2009-01-02 13:40 ` [PATCH 06/75] n_tty: Fix loss of echoed characters and remove bkl from n_tty Alan Cox
2009-01-02 13:41 ` [PATCH 07/75] n_tty: clean up coding style Alan Cox
2009-01-02 13:41 ` [PATCH 08/75] Remove devpts_root global Alan Cox
2009-01-02 13:41 ` [PATCH 09/75] Per-mount allocated_ptys Alan Cox
2009-01-02 19:47   ` Michał Mirosław
2009-01-02 13:41 ` [PATCH 10/75] Per-mount 'config' object Alan Cox
2009-01-02 13:41 ` [PATCH 11/75] Extract option parsing to new function Alan Cox
2009-01-02 13:41 ` [PATCH 12/75] Add DEVPTS_MULTIPLE_INSTANCES config token Alan Cox
2009-01-02 13:42 ` [PATCH 13/75] Define mknod_ptmx() Alan Cox
2009-01-02 13:42 ` [PATCH 14/75] Define get_init_pts_sb() Alan Cox
2009-01-02 13:42 ` [PATCH 15/75] Enable multiple instances of devpts Alan Cox
2009-01-02 13:42 ` [PATCH 16/75] Document usage of multiple-instances " Alan Cox
2009-01-02 13:42 ` [PATCH 17/75] devpts: Coding style clean up Alan Cox
2009-01-02 13:42 ` [PATCH 18/75] sierra: Fix formatting Alan Cox
2009-01-02 13:43 ` [PATCH 19/75] tty: Fix sparse static warning for tty_driver_lookup_tty Alan Cox
2009-01-02 13:43 ` [PATCH 20/75] pty: simplify resize Alan Cox
2009-01-02 13:43 ` [PATCH 21/75] n_tty: Fix handling of control characters and continuations Alan Cox
2009-01-02 13:43 ` [PATCH 22/75] n_tty: Fix hanfling of buffer full corner cases Alan Cox
2009-01-02 13:43 ` [PATCH 23/75] n_tty: Output bells immediately on a full buffer Alan Cox
2009-01-02 13:44 ` [PATCH 24/75] tty: Fix close races in USB serial Alan Cox
2009-01-02 13:44 ` [PATCH 25/75] devpts: fix unused function warning Alan Cox
2009-01-02 13:44 ` [PATCH 26/75] Convert the oxsemi tornado special cases to use the quirk interface and not Alan Cox
2009-01-02 13:44 ` [PATCH 27/75] And here's a patch (to be applied on top of the last) which prevents Alan Cox
2009-01-02 13:44 ` [PATCH 28/75] Add device function for USB serial console Alan Cox
2009-01-02 13:44 ` [PATCH 29/75] CRED: Wrap task credential accesses in the devpts filesystem Alan Cox
2009-01-02 13:44 ` [PATCH 30/75] tty: Fix PPP hang under load Alan Cox
2009-01-02 13:45 ` [PATCH 31/75] tty_port: Add a port level carrier detect operation Alan Cox
2009-01-02 13:45 ` [PATCH 32/75] rio: Kill off ckmalloc Alan Cox
2009-01-02 13:45 ` [PATCH 33/75] tty: Pull the dtr raise into tty port Alan Cox
2009-01-02 13:45 ` [PATCH 34/75] isicom: redo locking to use tty port locks Alan Cox
2009-01-02 13:45 ` [PATCH 35/75] tty: relock generic_serial Alan Cox
2009-01-02 13:45 ` [PATCH 36/75] tty: rocketport uses different port flags to everyone else Alan Cox
2009-01-02 13:45 ` [PATCH 37/75] tty: relock riscom8 using port locks Alan Cox
2009-01-02 13:45 ` [PATCH 38/75] tty: relock the mxser driver Alan Cox
2009-01-02 13:46 ` [PATCH 39/75] tty: Introduce a tty_port generic block_til_ready Alan Cox
2009-01-02 13:46 ` [PATCH 40/75] tty: Rework istallion to use the tty port changes Alan Cox
2009-01-02 13:46 ` [PATCH 41/75] tty: rework stallion to use the tty_port bits Alan Cox
2009-01-02 13:46 ` [PATCH 42/75] tty: ESP has been broken for locking etc forver Alan Cox
2009-01-02 13:46 ` [PATCH 43/75] tty: tty port zero baud open Alan Cox
2009-01-02 13:46 ` [PATCH 44/75] tty: Introduce some close helpers for ports Alan Cox
2009-01-02 13:46 ` [PATCH 45/75] serial: set correct baud_base for Oxford Semiconductor Ltd EXSYS EX-41092 Dual 16950 Serial adapter Alan Cox
2009-01-02 13:47 ` [PATCH 46/75] tty: USB tty devices can block in tcdrain when unplugged Alan Cox
2009-01-02 13:47 ` [PATCH 47/75] tty: N_TTY SIGIO only works for read Alan Cox
2009-01-02 13:47 ` [PATCH 48/75] tty: PTYs set TTY_DO_WRITE_WAKEUP when they don't need to Alan Cox
2009-01-02 13:47 ` [PATCH 49/75] tty: Remove some pointless casts Alan Cox
2009-01-02 13:47 ` [PATCH 50/75] tty: kref nozomi Alan Cox
2009-01-02 13:47 ` [PATCH 51/75] hso: net driver using tty without locking Alan Cox
2009-01-02 13:47 ` [PATCH 52/75] tty: Fix the HSO termios handling a bit Alan Cox
2009-01-02 13:47 ` [PATCH 53/75] tty: Modem functions for the HSO driver Alan Cox
2009-01-02 13:47 ` [PATCH 54/75] tty: relock epca Alan Cox
2009-01-02 13:48 ` [PATCH 55/75] tty: refcount the epca driver Alan Cox
2009-01-02 13:48 ` [PATCH 56/75] tty: Make epca use the port helpers Alan Cox
2009-01-02 13:48 ` [PATCH 57/75] tty: Redo the rocket driver locking Alan Cox
2009-01-02 13:48 ` [PATCH 58/75] tty: make rocketport use standard port->flags Alan Cox
2009-01-02 13:48 ` Alan Cox [this message]
2009-01-02 13:48 ` [PATCH 60/75] tty: use port methods for the rocket driver Alan Cox
2009-01-02 13:48 ` [PATCH 61/75] synclink_cs: Convert to tty_port Alan Cox
2009-01-02 13:48 ` [PATCH 62/75] tty: Drop the lock_kernel in the private ioctl hook Alan Cox
2009-01-02 13:49 ` [PATCH 63/75] serial: RS485 ioctl structure uses __u32 include linux/types.h Alan Cox
2009-01-02 13:49 ` [PATCH 64/75] __FUNCTION__ is gcc-specific, use __func__ Alan Cox
2009-01-02 13:49 ` [PATCH 65/75] tty: We want the port object to be persistent Alan Cox
2009-01-02 13:49 ` [PATCH 66/75] fix for tty-serial-move-port Alan Cox
2009-01-02 13:49 ` [PATCH 67/75] 8250: Don't clobber spinlocks Alan Cox
2009-01-02 13:49 ` [PATCH 68/75] 8250: Serial driver changes to support future Cavium OCTEON serial patches Alan Cox
2009-01-02 13:49 ` [PATCH 69/75] Serial: Allow port type to be specified when calling serial8250_register_port Alan Cox
2009-01-02 13:50 ` [PATCH 70/75] Serial: UART driver changes for Cavium OCTEON Alan Cox
2009-01-02 13:50 ` [PATCH 71/75] drivers/char/cyclades.c: cy_pci_probe: fix error path Alan Cox
2009-01-02 13:50 ` [PATCH 72/75] tty: Fix an ircomm warning and note another bug Alan Cox
2009-01-05 17:42   ` Wolfram Sang
2009-01-05 18:01     ` Alan Cox
2009-01-02 13:50 ` [PATCH 73/75] hso modem detect fix patch against Alan Cox'es tty tree Alan Cox
2009-01-02 13:50 ` [PATCH 74/75] hso maintainers update patch Alan Cox
2009-01-02 13:50 ` [PATCH 75/75] serial_8250: support for Sealevel Systems Model 7803 COMM+8 Alan Cox

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=20090102134829.13472.72723.stgit@localhost.localdomain \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=linux-serial@vger.kernel.org \
    --cc=torvalds@osdl.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox