stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Daniel Winkler <danielwinkler@google.com>,
	Serge Semin <Sergey.Semin@baikalelectronics.ru>,
	Claire Chang <tientzu@chromium.org>
Subject: [PATCH 4.4 33/54] serial: 8250_mtk: Fix high-speed baud rates clamping
Date: Thu, 30 Jul 2020 10:05:12 +0200	[thread overview]
Message-ID: <20200730074422.798025996@linuxfoundation.org> (raw)
In-Reply-To: <20200730074421.203879987@linuxfoundation.org>

From: Serge Semin <Sergey.Semin@baikalelectronics.ru>

commit 551e553f0d4ab623e2a6f424ab5834f9c7b5229c upstream.

Commit 7b668c064ec3 ("serial: 8250: Fix max baud limit in generic 8250
port") fixed limits of a baud rate setting for a generic 8250 port.
In other words since that commit the baud rate has been permitted to be
within [uartclk / 16 / UART_DIV_MAX; uartclk / 16], which is absolutely
normal for a standard 8250 UART port. But there are custom 8250 ports,
which provide extended baud rate limits. In particular the Mediatek 8250
port can work with baud rates up to "uartclk" speed.

Normally that and any other peculiarity is supposed to be handled in a
custom set_termios() callback implemented in the vendor-specific
8250-port glue-driver. Currently that is how it's done for the most of
the vendor-specific 8250 ports, but for some reason for Mediatek a
solution has been spread out to both the glue-driver and to the generic
8250-port code. Due to that a bug has been introduced, which permitted the
extended baud rate limit for all even for standard 8250-ports. The bug
has been fixed by the commit 7b668c064ec3 ("serial: 8250: Fix max baud
limit in generic 8250 port") by narrowing the baud rates limit back down to
the normal bounds. Unfortunately by doing so we also broke the
Mediatek-specific extended bauds feature.

A fix of the problem described above is twofold. First since we can't get
back the extended baud rate limits feature to the generic set_termios()
function and that method supports only a standard baud rates range, the
requested baud rate must be locally stored before calling it and then
restored back to the new termios structure after the generic set_termios()
finished its magic business. By doing so we still use the
serial8250_do_set_termios() method to set the LCR/MCR/FCR/etc. registers,
while the extended baud rate setting procedure will be performed later in
the custom Mediatek-specific set_termios() callback. Second since a true
baud rate is now fully calculated in the custom set_termios() method we
need to locally update the port timeout by calling the
uart_update_timeout() function. After the fixes described above are
implemented in the 8250_mtk.c driver, the Mediatek 8250-port should
get back to normally working with extended baud rates.

Link: https://lore.kernel.org/linux-serial/20200701211337.3027448-1-danielwinkler@google.com

Fixes: 7b668c064ec3 ("serial: 8250: Fix max baud limit in generic 8250 port")
Reported-by: Daniel Winkler <danielwinkler@google.com>
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Cc: stable <stable@vger.kernel.org>
Tested-by: Claire Chang <tientzu@chromium.org>
Link: https://lore.kernel.org/r/20200714124113.20918-1-Sergey.Semin@baikalelectronics.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/tty/serial/8250/8250_mtk.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -47,8 +47,21 @@ mtk8250_set_termios(struct uart_port *po
 	struct uart_8250_port *up =
 		container_of(port, struct uart_8250_port, port);
 
+	/*
+	 * Store the requested baud rate before calling the generic 8250
+	 * set_termios method. Standard 8250 port expects bauds to be
+	 * no higher than (uartclk / 16) so the baud will be clamped if it
+	 * gets out of that bound. Mediatek 8250 port supports speed
+	 * higher than that, therefore we'll get original baud rate back
+	 * after calling the generic set_termios method and recalculate
+	 * the speed later in this method.
+	 */
+	baud = tty_termios_baud_rate(termios);
+
 	serial8250_do_set_termios(port, termios, old);
 
+	tty_termios_encode_baud_rate(termios, baud, baud);
+
 	/*
 	 * Mediatek UARTs use an extra highspeed register (UART_MTK_HIGHS)
 	 *
@@ -91,6 +104,11 @@ mtk8250_set_termios(struct uart_port *po
 	 */
 	spin_lock_irqsave(&port->lock, flags);
 
+	/*
+	 * Update the per-port timeout.
+	 */
+	uart_update_timeout(port, termios->c_cflag, baud);
+
 	/* set DLAB we have cval saved in up->lcr from the call to the core */
 	serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB);
 	serial_dl_write(up, quot);



  parent reply	other threads:[~2020-07-30  8:13 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30  8:04 [PATCH 4.4 00/54] 4.4.232-rc1 review Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 01/54] pinctrl: amd: fix npins for uart0 in kerncz_groups Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 02/54] mac80211: allow rx of mesh eapol frames with default rx key Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 03/54] scsi: scsi_transport_spi: Fix function pointer check Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 04/54] xtensa: fix __sync_fetch_and_{and,or}_4 declarations Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 05/54] xtensa: update *pos in cpuinfo_op.next Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 06/54] drivers/net/wan/lapbether: Fixed the value of hard_header_len Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 07/54] net: sky2: initialize return of gm_phy_read Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 08/54] drm/nouveau/i2c/g94-: increase NV_PMGR_DP_AUXCTL_TRANSACTREQ timeout Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 09/54] SUNRPC reverting d03727b248d0 ("NFSv4 fix CLOSE not waiting for direct IO compeletion") Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 10/54] perf/core: Fix locking for children siblings group read Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 11/54] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 12/54] ALSA: info: Drop WARN_ON() from buffer NULL sanity check Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 13/54] ASoC: rt5670: Correct RT5670_LDO_SEL_MASK Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 14/54] btrfs: fix double free on ulist after backref resolution failure Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 15/54] x86/fpu: Disable bottom halves while loading FPU registers Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 16/54] btrfs: fix mount failure caused by race with umount Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 17/54] hippi: Fix a size used in a pci_free_consistent() in an error handling path Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 18/54] ax88172a: fix ax88172a_unbind() failures Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 19/54] net: dp83640: fix SIOCSHWTSTAMP to update the struct with actual configuration Greg Kroah-Hartman
2020-07-30  8:04 ` [PATCH 4.4 20/54] net: smc91x: Fix possible memory leak in smc_drv_probe() Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 21/54] scripts/decode_stacktrace: strip basepath from all paths Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 22/54] regmap: dev_get_regmap_match(): fix string comparison Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 23/54] usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init() Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 24/54] arm64: Use test_tsk_thread_flag() for checking TIF_SINGLESTEP Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 25/54] x86: math-emu: Fix up cmp insn for clang ias Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 26/54] Revert "cifs: Fix the target file was deleted when rename failed." Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 27/54] staging: wlan-ng: properly check endpoint types Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 28/54] staging: comedi: addi_apci_1032: check INSN_CONFIG_DIGITAL_TRIG shift Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 29/54] staging: comedi: ni_6527: fix INSN_CONFIG_DIGITAL_TRIG support Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 30/54] staging: comedi: addi_apci_1500: check INSN_CONFIG_DIGITAL_TRIG shift Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 31/54] staging: comedi: addi_apci_1564: " Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 32/54] serial: 8250: fix null-ptr-deref in serial8250_start_tx() Greg Kroah-Hartman
2020-07-30  8:05 ` Greg Kroah-Hartman [this message]
2020-07-30  8:05 ` [PATCH 4.4 34/54] mm/memcg: fix refcount error while moving and swapping Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 35/54] parisc: Add atomic64_set_release() define to avoid CPU soft lockups Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 36/54] ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 37/54] ath9k: Fix regression with Atheros 9271 Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 38/54] AX.25: Fix out-of-bounds read in ax25_connect() Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 39/54] AX.25: Prevent out-of-bounds read in ax25_sendmsg() Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 40/54] net-sysfs: add a newline when printing tx_timeout by sysfs Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 41/54] net: udp: Fix wrong clean up for IS_UDPLITE macro Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 42/54] AX.25: Prevent integer overflows in connect and sendmsg Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 43/54] tcp: allow at most one TLP probe per flight Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 44/54] rxrpc: Fix sendmsg() returning EPIPE due to recvmsg() returning ENODATA Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 45/54] ip6_gre: fix null-ptr-deref in ip6gre_init_net() Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 46/54] drivers/net/wan/x25_asy: Fix to make it work Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 47/54] Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 48/54] regmap: debugfs: check count when read regmap file Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 49/54] xfs: set format back to extents if xfs_bmap_extents_to_btree Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 50/54] tools/lib/subcmd/pager.c: do not alias select() params Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 51/54] perf: Make perf able to build with latest libbfd Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 52/54] perf tools: Fix snprint warnings for gcc 8 Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 53/54] perf annotate: Use asprintf when formatting objdump command line Greg Kroah-Hartman
2020-07-30  8:05 ` [PATCH 4.4 54/54] perf probe: Fix to check blacklist address correctly Greg Kroah-Hartman
2020-07-30 16:46 ` [PATCH 4.4 00/54] 4.4.232-rc1 review Guenter Roeck
2020-07-31 12:41 ` Jon Hunter
2020-07-31 12:47 ` Naresh Kamboju

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=20200730074422.798025996@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=danielwinkler@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tientzu@chromium.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;
as well as URLs for NNTP newsgroup(s).