All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jason77.wang@gmail.com>
To: gregkh@suse.de, alan@linux.intel.com, arnd@arndb.de, sbrabec@suse.cz
Cc: linux-serial@vger.kernel.org
Subject: [PATCH RESEND 2/2] serial-core: restore termios settings when resume console ports
Date: Sat, 21 Aug 2010 15:14:42 +0800	[thread overview]
Message-ID: <1282374882-6651-3-git-send-email-jason77.wang@gmail.com> (raw)
In-Reply-To: <1282374882-6651-2-git-send-email-jason77.wang@gmail.com>

The commit 4547be7 rewrites suspend and resume functions. According
to this rewrite, when a serial port is a printk console device and
can suspend(without set no_console_suspend flag), it will definitely
call set_termios function during its resume, but parameter termios
isn't initialized, this will pass an unpredictable config to the
serial port. If this serial port is not a userspace opened tty device
, a suspend and resume action will make this serial port unusable.
I.E. ttyS0 is a printk console device, ttyS1 or keyboard+display is
userspace tty device, a suspend/resume action will make ttyS0
unusable.

If a serial port is both a printk console device and an opened tty
device, this issue can be overcome because it will call set_termios
again with the correct parameter in the uart_change_speed function.

Refer to the deleted content of commit 4547be7, revert parts relate
to restore settings into parameter termios. It is safe because if
a serial port is a printk console only device, the only meaningful
field in termios is c_cflag and its old config is saved in
uport->cons->cflag, if this port is also an opened tty device,
it will clear uport->cons->cflag in the uart_open and the old config
is saved in tty->termios.

Signed-off-by: Jason Wang <jason77.wang@gmail.com>
---
 drivers/serial/serial_core.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index ff21200..bc6cddd 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -2066,6 +2066,18 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
 	 * Re-enable the console device after suspending.
 	 */
 	if (console_suspend_enabled && uart_console(uport)) {
+		/*
+		 * First try to use the console cflag setting.
+		 */
+		memset(&termios, 0, sizeof(struct ktermios));
+		termios.c_cflag = uport->cons->cflag;
+
+		/*
+		 * If that's unset, use the tty termios setting.
+		 */
+		if (port->tty && port->tty->termios && termios.c_cflag == 0)
+			termios = *(port->tty->termios);
+
 		uart_change_pm(state, 0);
 		uport->ops->set_termios(uport, &termios, NULL);
 		console_start(uport->cons);
-- 
1.5.6.5


  reply	other threads:[~2010-08-21  7:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21  7:14 [PATCH RESEND 0/2] two serial_core suspend/resume fixes Jason Wang
2010-08-21  7:14 ` [PATCH RESEND 1/2] serial-core: skip call set_termios/console_start when no_console_suspend Jason Wang
2010-08-21  7:14   ` Jason Wang [this message]
2010-08-23 20:06 ` [PATCH RESEND 0/2] two serial_core suspend/resume fixes Stanislav Brabec
     [not found]   ` <AANLkTikZgAMvODoFB9O9Mrb98f_xMatQfkb+2dgcrGJn@mail.gmail.com>
2010-08-24  9:01     ` Stanislav Brabec
2010-08-25  3:29       ` wanghui
2010-08-25 10:51         ` Stanislav Brabec
2010-08-25 20:00           ` Stanislav Brabec
2010-08-26  8:50             ` Jason Wang
2010-08-29 22:17               ` Stanislav Brabec
2010-08-30  5:59                 ` Jason Wang
2010-08-26  8:36           ` Jason Wang
2010-08-26 10:55             ` Stanislav Brabec

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=1282374882-6651-3-git-send-email-jason77.wang@gmail.com \
    --to=jason77.wang@gmail.com \
    --cc=alan@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@suse.de \
    --cc=linux-serial@vger.kernel.org \
    --cc=sbrabec@suse.cz \
    /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.