public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_dw: Do not reclock if already at correct rate
@ 2024-02-22 19:26 Peter Collingbourne
  2024-02-23 15:04 ` Andy Shevchenko
  2024-03-02 21:01 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Collingbourne @ 2024-02-22 19:26 UTC (permalink / raw)
  To: Ilpo Järvinen, Andy Shevchenko, Greg Kroah-Hartman,
	Jiri Slaby, Heikki Krogerus
  Cc: Peter Collingbourne, linux-kernel, linux-serial, stable

When userspace opens the console, we call set_termios() passing a
termios with the console's configured baud rate. Currently this causes
dw8250_set_termios() to disable and then re-enable the UART clock at
the same frequency as it was originally. This can cause corruption
of any concurrent console output. Fix it by skipping the reclocking
if we are already at the correct rate.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I2e3761d239cbf29ed41412e5338f30bffe1efc70
Fixes: 4e26b134bd17 ("serial: 8250_dw: clock rate handling for all ACPI platforms")
Cc: stable@vger.kernel.org
---
 drivers/tty/serial/8250/8250_dw.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 2d1f350a4bea..c1d43f040c43 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -357,9 +357,9 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 	long rate;
 	int ret;
 
-	clk_disable_unprepare(d->clk);
 	rate = clk_round_rate(d->clk, newrate);
-	if (rate > 0) {
+	if (rate > 0 && p->uartclk != rate) {
+		clk_disable_unprepare(d->clk);
 		/*
 		 * Note that any clock-notifer worker will block in
 		 * serial8250_update_uartclk() until we are done.
@@ -367,8 +367,8 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 		ret = clk_set_rate(d->clk, newrate);
 		if (!ret)
 			p->uartclk = rate;
+		clk_prepare_enable(d->clk);
 	}
-	clk_prepare_enable(d->clk);
 
 	dw8250_do_set_termios(p, termios, old);
 }
-- 
2.44.0.rc1.240.g4c46232300-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_dw: Do not reclock if already at correct rate
  2024-02-22 19:26 [PATCH] serial: 8250_dw: Do not reclock if already at correct rate Peter Collingbourne
@ 2024-02-23 15:04 ` Andy Shevchenko
  2024-03-02 21:01 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2024-02-23 15:04 UTC (permalink / raw)
  To: Peter Collingbourne
  Cc: Ilpo Järvinen, Greg Kroah-Hartman, Jiri Slaby,
	Heikki Krogerus, linux-kernel, linux-serial, stable

On Thu, Feb 22, 2024 at 11:26:34AM -0800, Peter Collingbourne wrote:
> When userspace opens the console, we call set_termios() passing a
> termios with the console's configured baud rate. Currently this causes
> dw8250_set_termios() to disable and then re-enable the UART clock at
> the same frequency as it was originally. This can cause corruption
> of any concurrent console output. Fix it by skipping the reclocking
> if we are already at the correct rate.

Makes sense to me from code perspective.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_dw: Do not reclock if already at correct rate
  2024-02-22 19:26 [PATCH] serial: 8250_dw: Do not reclock if already at correct rate Peter Collingbourne
  2024-02-23 15:04 ` Andy Shevchenko
@ 2024-03-02 21:01 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2024-03-02 21:01 UTC (permalink / raw)
  To: Peter Collingbourne
  Cc: Ilpo Järvinen, Andy Shevchenko, Jiri Slaby, Heikki Krogerus,
	linux-kernel, linux-serial, stable

On Thu, Feb 22, 2024 at 11:26:34AM -0800, Peter Collingbourne wrote:
> When userspace opens the console, we call set_termios() passing a
> termios with the console's configured baud rate. Currently this causes
> dw8250_set_termios() to disable and then re-enable the UART clock at
> the same frequency as it was originally. This can cause corruption
> of any concurrent console output. Fix it by skipping the reclocking
> if we are already at the correct rate.
> 
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Link: https://linux-review.googlesource.com/id/I2e3761d239cbf29ed41412e5338f30bffe1efc70

Again, why the link?  What does that help with?  Our tools add a Link:
tag to this public email thread, not a google gerrit instance.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-02 21:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22 19:26 [PATCH] serial: 8250_dw: Do not reclock if already at correct rate Peter Collingbourne
2024-02-23 15:04 ` Andy Shevchenko
2024-03-02 21:01 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox