Skip to contentSkip to conversation

TTY/serial driver fixes for .38

PATCH New Greg KH 3 participants 8 messages Jan 31, 2011 – Feb 11, 2011

Subsystems (2)
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 TTY/serial driver fixes for .38

Here are a few tty and serial fixes for your .38 tree.

Note, you will get a conflict in drivers/tty/tty_io.c with this pull, if you like, I can provide a fixed up merge with this, but the fix should be pretty easy to detect and fix up if you want to do it yourself.

There are a few bug fixes here that a number of people have reported, and some build warning fixes as well.

Please pull from:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/tty-2.6.git/ tty-linus

All of these patches have been in the -mm and -next trees for the past week or so.

Patches will be sent to the linux-kernel mailing list, if anyone wants to see them.

thanks,

greg k-h

------------

 drivers/tty/n_hdlc.c       |   90 ++++++++++++++++++++++----------------------
 drivers/tty/serial/8250.c  |    3 +-
 drivers/tty/serial/Kconfig |    1 +
 drivers/tty/tty_io.c       |    4 +-
 drivers/tty/vt/vt.c        |   11 ++++-
 5 files changed, 58 insertions(+), 51 deletions(-)

---------------

Dave Airlie (1):
vt: fix issue when fbcon wants to takeover a second time.

Kay Sievers (1):
tty: use for_each_console() and WARN() on sysfs failures

Paul Fulghum (1):
n_hdlc: fix read and write locking

Pavel Machek (1):
serial: unbreak billionton CF card

Randy Dunlap (1):
tty/serial: fix apbuart build

#1 lore raw

PATCH 1/5 vt: fix issue when fbcon wants to takeover a second time.

From: Dave Airlie <[email protected]>

With framebuffer handover and multiple GPUs, we get into a position where the fbcon unbinds the vesafb framebuffer for GPU 1, but we still have a radeon framebuffer bound from GPU 0, so we don't unregister the console driver. Then when we tried to bind the new radeon framebuffer for GPU1 we never get to the bind call as we fail due to the console being registered already.

This changes the return value to -EBUSY when the driver is already registered and continues to bind for -EBUSY.

---
 drivers/tty/vt/vt.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/tty/vt/vt.c +7 -2
index 76407ec..4f6ae05 100644
@@ -3545,7 +3545,7 @@ int register_con_driver(const struct consw *csw, int first, int last)
 
 		/* already registered */
 		if (con_driver->con == csw)
-			retval = -EINVAL;
+			retval = -EBUSY;
 	}
 
 	if (retval)
@@ -3656,7 +3656,12 @@ int take_over_console(const struct consw *csw, int first, int last, int deflt)
 	int err;
 
 	err = register_con_driver(csw, first, last);
-
+	/* if we get an busy error we still want to bind the console driver
+	 * and return success, as we may have unbound the console driver
+	 * but not unregistered it.
+	*/
+	if (err == -EBUSY)
+		err = 0;
 	if (!err)
 		bind_con_driver(csw, first, last, deflt);
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/5 tty: use for_each_console() and WARN() on sysfs failures

In reply to Greg KH

From: Kay Sievers <[email protected]>

This fixes the build warnings in the tty code, and uses the proper function for iterating over the console devices.

---
 drivers/tty/tty_io.c |    4 ++--
 drivers/tty/vt/vt.c  |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/tty/tty_io.c +2 -2
index 464d09d..dae6fc9 100644
@@ -3257,7 +3257,7 @@ static ssize_t show_cons_active(struct device *dev,
 	ssize_t count = 0;
 
 	acquire_console_sem();
-	for (c = console_drivers; c; c = c->next) {
+	for_each_console(c) {
 		if (!c->device)
 			continue;
 		if (!c->write)
@@ -3306,7 +3306,7 @@ int __init tty_init(void)
 	if (IS_ERR(consdev))
 		consdev = NULL;
 	else
-		device_create_file(consdev, &dev_attr_active);
+		WARN_ON(device_create_file(consdev, &dev_attr_active) < 0);
 
 #ifdef CONFIG_VT
 	vty_init(&console_fops);
drivers/tty/vt/vt.c +1 -1
index 4f6ae05..9550618 100644
@@ -2994,7 +2994,7 @@ int __init vty_init(const struct file_operations *console_fops)
 	if (IS_ERR(tty0dev))
 		tty0dev = NULL;
 	else
-		device_create_file(tty0dev, &dev_attr_active);
+		WARN_ON(device_create_file(tty0dev, &dev_attr_active) < 0);
 
 	vcs_init();
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/5 serial: unbreak billionton CF card

In reply to Greg KH

From: Pavel Machek <[email protected]>

Unbreak Billionton CF bluetooth card. This actually fixes a regression on zaurus.

---
 drivers/tty/serial/8250.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/tty/serial/8250.c +2 -1
index b25e6e4..3975df6 100644
@@ -236,7 +236,8 @@ static const struct serial8250_config uart_config[] = {
 		.fifo_size	= 128,
 		.tx_loadsz	= 128,
 		.fcr		= UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
-		.flags		= UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
+		/* UART_CAP_EFR breaks billionon CF bluetooth card. */
+		.flags		= UART_CAP_FIFO | UART_CAP_SLEEP,
 	},
 	[PORT_16654] = {
 		.name		= "ST16654",
Signature · 1 line
1.7.1
#6 lore raw

PATCH 4/5 n_hdlc: fix read and write locking

In reply to Greg KH

From: Paul Fulghum <[email protected]>

Fix locking in read and write code of n_hdlc line discipline.

2.6.36 replaced lock_kernel() with tty_lock(). The tty mutex is not dropped automatically when the thread sleeps like the BKL. This results in a blocked read or write holding the tty mutex and stalling operations by other devices that use the tty mutex.

A review of n_hdlc read and write code shows:
1. neither BKL or tty mutex are required for correct operation
2. read can block while read data is available if data is posted between availability check and call to interruptible_sleep_on()
3. write does not set process state to TASK_INTERRUPTIBLE on each pass through the processing loop which can cause unneeded scheduling of the thread

The unnecessary tty mutex references have been removed.

Read changed to use same code as n_tty read
for completing reads and blocking.

Write corrected to set process state to TASK_INTERRUPTIBLE on each pass through processing loop.

---
 drivers/tty/n_hdlc.c |   90 +++++++++++++++++++++++++-------------------------
 1 files changed, 45 insertions(+), 45 deletions(-)
drivers/tty/n_hdlc.c +45 -45
index 47d3228..52fc0c9 100644
@@ -581,8 +581,9 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
 			   __u8 __user *buf, size_t nr)
 {
 	struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
-	int ret;
+	int ret = 0;
 	struct n_hdlc_buf *rbuf;
+	DECLARE_WAITQUEUE(wait, current);
 
 	if (debuglevel >= DEBUG_LEVEL_INFO)	
 		printk("%s(%d)n_hdlc_tty_read() called\n",__FILE__,__LINE__);
@@ -598,57 +599,55 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
 		return -EFAULT;
 	}
 
-	tty_lock();
+	add_wait_queue(&tty->read_wait, &wait);
 
 	for (;;) {
 		if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
-			tty_unlock();
-			return -EIO;
+			ret = -EIO;
+			break;
 		}
+		if (tty_hung_up_p(file))
+			break;
 
-		n_hdlc = tty2n_hdlc (tty);
-		if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
-			 tty != n_hdlc->tty) {
-			tty_unlock();
-			return 0;
-		}
+		set_current_state(TASK_INTERRUPTIBLE);
 
 		rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
-		if (rbuf)
+		if (rbuf) {
+			if (rbuf->count > nr) {
+				/* too large for caller's buffer */
+				ret = -EOVERFLOW;
+			} else {
+				if (copy_to_user(buf, rbuf->buf, rbuf->count))
+					ret = -EFAULT;
+				else
+					ret = rbuf->count;
+			}
+
+			if (n_hdlc->rx_free_buf_list.count >
+			    DEFAULT_RX_BUF_COUNT)
+				kfree(rbuf);
+			else
+				n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, rbuf);
 			break;
+		}
 			
 		/* no data */
 		if (file->f_flags & O_NONBLOCK) {
-			tty_unlock();
-			return -EAGAIN;
+			ret = -EAGAIN;
+			break;
 		}
-			
-		interruptible_sleep_on (&tty->read_wait);
+
+		schedule();
+
 		if (signal_pending(current)) {
-			tty_unlock();
-			return -EINTR;
+			ret = -EINTR;
+			break;
 		}
 	}
-		
-	if (rbuf->count > nr)
-		/* frame too large for caller's buffer (discard frame) */
-		ret = -EOVERFLOW;
-	else {
-		/* Copy the data to the caller's buffer */
-		if (copy_to_user(buf, rbuf->buf, rbuf->count))
-			ret = -EFAULT;
-		else
-			ret = rbuf->count;
-	}
-	
-	/* return HDLC buffer to free list unless the free list */
-	/* count has exceeded the default value, in which case the */
-	/* buffer is freed back to the OS to conserve memory */
-	if (n_hdlc->rx_free_buf_list.count > DEFAULT_RX_BUF_COUNT)
-		kfree(rbuf);
-	else	
-		n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf);
-	tty_unlock();
+
+	remove_wait_queue(&tty->read_wait, &wait);
+	__set_current_state(TASK_RUNNING);
+
 	return ret;
 	
 }	/* end of n_hdlc_tty_read() */
@@ -691,14 +690,15 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
 		count = maxframe;
 	}
 	
-	tty_lock();
-
 	add_wait_queue(&tty->write_wait, &wait);
-	set_current_state(TASK_INTERRUPTIBLE);
+
+	for (;;) {
+		set_current_state(TASK_INTERRUPTIBLE);
 	
-	/* Allocate transmit buffer */
-	/* sleep until transmit buffer available */		
-	while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) {
+		tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list);
+		if (tbuf)
+			break;
+
 		if (file->f_flags & O_NONBLOCK) {
 			error = -EAGAIN;
 			break;
@@ -719,7 +719,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
 		}
 	}
 
-	set_current_state(TASK_RUNNING);
+	__set_current_state(TASK_RUNNING);
 	remove_wait_queue(&tty->write_wait, &wait);
 
 	if (!error) {		
@@ -731,7 +731,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
 		n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
 		n_hdlc_send_frames(n_hdlc,tty);
 	}
-	tty_unlock();
+
 	return error;
 	
 }	/* end of n_hdlc_tty_write() */
Signature · 1 line
1.7.1
#7 lore raw

PATCH 5/5 tty/serial: fix apbuart build

In reply to Greg KH

From: Randy Dunlap <[email protected]>

Fix build errors by selecting SERIAL_CORE:

ERROR: "uart_register_driver" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_write_wakeup" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_update_timeout" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_get_divisor" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_get_baud_rate" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_add_one_port" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_unregister_driver" [drivers/tty/serial/apbuart.ko] undefined!
ERROR: "uart_remove_one_port" [drivers/tty/serial/apbuart.ko] undefined!

---
 drivers/tty/serial/Kconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/tty/serial/Kconfig +1 -0
index b1682d7..2b83346 100644
@@ -1518,6 +1518,7 @@ config SERIAL_BCM63XX_CONSOLE
 config SERIAL_GRLIB_GAISLER_APBUART
 	tristate "GRLIB APBUART serial support"
 	depends on OF
+	select SERIAL_CORE
 	---help---
 	Add support for the GRLIB APBUART serial port.
 
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH 3/5] serial: unbreak billionton CF card

In reply to Greg Kroah-Hartman
Quoted 4 lines · On Mon, 31 Jan 2011 08:31:08 -0800 Greg Kroah-Hartman <[email protected]> wrote:

From: Pavel Machek <[email protected]>

Unbreak Billionton CF bluetooth card. This actually fixes a regression on zaurus.

It also unbreaks a pile of other chips.

Properly this should be a revert of commit 7a56aa45982bb87bfca98a2832b5ae782c03364a as far as I can see.

#5 lore raw

Re: [PATCH 3/5] serial: unbreak billionton CF card

Hi!

Quoted 9 lines
Quoted 4 lines

From: Pavel Machek <[email protected]>

Unbreak Billionton CF bluetooth card. This actually fixes a regression on zaurus.

It also unbreaks a pile of other chips.

Properly this should be a revert of commit 7a56aa45982bb87bfca98a2832b5ae782c03364a as far as I can see.

Well, IIRC (sorry, offline) that commit added two flags and only one was harmful for me... so I only removed one.

Also I guess comment explaining what is going on there would is good.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html