All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH 05/24] serial: 8250: clear subdriver state on port unregister
Date: Tue, 27 Oct 2026 11:30:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-186444@kernel.org> (raw)
In-Reply-To: <20261027-tty-llm-v1-5-99b0202ae546@linuxfoundation.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serial: 8250: clear rxtrig, break_ctl, attr_group, rs485 gpios on unregister
--

commit 84854ce6768bb6d9f299a8c1baf6b88228a5ea32
Author: Joshua Rogers <linux@joshua.hu>

serial: 8250: clear subdriver state on port unregister

This commit clears subdriver-copied callbacks and per-driver fields on
struct uart_8250_port and calls serial8250_set_defaults() in
serial8250_unregister_port() before re-registering the port as a fallback
ISA port.

> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 0951d3e42e1f3..673fde55828a9 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -956,7 +956,35 @@ void serial8250_unregister_port(struct uart_8250_port *uart)
>  		uart->port.dev = &serial8250_isa_devs->dev;
>  		uart->port.port_id = uart->port.line;
>  		uart->capabilities = 0;
> +
> +		/*
> +		 * Clear subdriver-owned state copied by
> +		 * serial8250_register_8250_port() to prevent dangling
> +		 * pointers after the original driver module is unloaded.
> +		 */
> +		uart->port.private_data = NULL;
> +		uart->port.set_termios = NULL;
> +		uart->port.set_ldisc = NULL;
> +		uart->port.get_mctrl = NULL;
> +		uart->port.set_mctrl = NULL;
> +		uart->port.get_divisor = NULL;
> +		uart->port.set_divisor = NULL;
> +		uart->port.startup = NULL;
> +		uart->port.shutdown = NULL;
> +		uart->port.throttle = NULL;
> +		uart->port.unthrottle = NULL;
> +		uart->port.handle_break = NULL;
> +		uart->port.rs485_config = NULL;
> +		memset(&uart->port.rs485, 0, sizeof(uart->port.rs485));
> +		memset(&uart->port.rs485_supported, 0,
> +		       sizeof(uart->port.rs485_supported));
> +		uart->gpios = NULL;
> +		uart->dma = NULL;
> +		uart->rs485_start_tx = NULL;
> +		uart->rs485_stop_tx = NULL;

[Severity: High]
Should serial8250_unregister_port() also clear get_rxtrig, set_rxtrig,
break_ctl, attr_group, rs485_term_gpio, and rs485_rx_during_tx_gpio on
uart->port?

During registration, __serial8250_register_8250_port() in
drivers/tty/serial/8250/8250_core.c conditionally copies get_rxtrig,
set_rxtrig, and break_ctl from the subdriver template:

	if (up->port.get_rxtrig)
		uart->port.get_rxtrig = up->port.get_rxtrig;
	if (up->port.set_rxtrig)
		uart->port.set_rxtrig = up->port.set_rxtrig;
	if (up->port.startup)
		uart->port.startup = up->port.startup;
	if (up->port.shutdown)
		uart->port.shutdown = up->port.shutdown;
	if (up->port.break_ctl)
		uart->port.break_ctl = up->port.break_ctl;

When a modular subdriver such as mxpcie8250_probe() in
drivers/tty/serial/8250/8250_mxpcie.c registers a port with a type that sets
uart->port.attr_group = &serial8250_dev_attr_group via
serial8250_config_port() -> register_dev_spec_attr_grp(), unbinding the
subdriver leaves attr_group, get_rxtrig, and set_rxtrig set on the fallback
ISA port. When uart_add_one_port() -> serial_core_add_one_port() re-adds the
fallback port, it re-attaches uport->attr_group (exposing rx_trig_bytes in
sysfs), and reading or writing rx_trig_bytes calls rx_trig_bytes_show() or
rx_trig_bytes_store() in drivers/tty/serial/8250/8250_port.c:

	if (uport->get_rxtrig)
		rxtrig_bytes = uport->get_rxtrig(uport);
	else
		rxtrig_bytes = do_serial8250_get_rxtrig(port);

If 8250_mxpcie was unloaded, this calls into freed module text; if the
device was only unbound, mxpcie8250_set_rxtrig() dereferences NULL from
dev_get_drvdata(port->dev) on &serial8250_isa_devs->dev and accesses
unmapped port->membase.

Similarly, if the fallback port is later configured or its serial8250_ports
slot is reused by another subdriver that does not set break_ctl (or if the
previous subdriver used UPIO_AU, where set_io_from_upio() does not reset
serial_in and serial_out), serial8250_break_ctl() will invoke the previous
subdriver's dangling break_ctl callback.

In addition, __serial8250_register_8250_port() calls uart_get_rs485_mode()
in drivers/tty/serial/serial_core.c, which allocates devm-managed GPIO
descriptors on the subdriver's device:

	desc = devm_gpiod_get_optional(dev, "rs485-term", GPIOD_OUT_LOW);
	if (IS_ERR(desc))
		return dev_err_probe(dev, PTR_ERR(desc), "Cannot get rs485-term-gpios\n");
	port->rs485_term_gpio = desc;
	...
	desc = devm_gpiod_get_optional(dev, "rs485-rx-during-tx", dflags);
	if (IS_ERR(desc))
		return dev_err_probe(dev, PTR_ERR(desc), "Cannot get rs485-rx-during-tx-gpios\n");
	port->rs485_rx_during_tx_gpio = desc;

When the subdriver unbinds, devres frees these descriptors, but
rs485_term_gpio and rs485_rx_during_tx_gpio remain non-NULL. If a subsequent
RS485-capable subdriver without a firmware node (!dev_fwnode(dev)) reuses
the slot, uart_get_rs485_mode() returns early without overwriting those
fields, and uart_set_rs485_termination() or uart_set_rs485_rx_during_tx()
will pass the freed gpio_desc pointers to gpiod_set_value_cansleep().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027-tty-llm-v1-0-99b0202ae546@linuxfoundation.org?part=5

  parent reply	other threads:[~2026-10-27 11:30 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 11:06 [PATCH 00/24] tty/serial: a bunch of llm-found fixes Greg Kroah-Hartman
2026-10-27 11:06 ` [PATCH 01/24] vt: serialise the producers of the flip buffer Greg Kroah-Hartman
2026-10-27 11:14   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 02/24] serial: core: respect runtime PM when sending x_char Greg Kroah-Hartman
2026-10-27 11:16   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 03/24] serial: 8250: don't wait for the em485 timers locked Greg Kroah-Hartman
2026-10-27 11:39   ` Ilpo Järvinen
2026-10-27 11:46   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 04/24] serial: 8250: don't report a wakeup to a closed tty Greg Kroah-Hartman
2026-10-27 11:16   ` sashiko-bot
2026-10-27 11:43   ` Ilpo Järvinen
2026-10-27 11:06 ` [PATCH 05/24] serial: 8250: clear subdriver state on port unregister Greg Kroah-Hartman
2026-10-27 11:16   ` Jiri Slaby
2026-10-27 15:28     ` James Hilliard
2026-10-27 11:30   ` sashiko-bot [this message]
2026-10-27 11:06 ` [PATCH 06/24] serial: 8250: add bounds check for line array in setup_serial() Greg Kroah-Hartman
2026-10-27 11:12   ` sashiko-bot
2026-10-27 11:19     ` Jiri Slaby
2026-10-27 11:57   ` Ilpo Järvinen
2026-10-27 11:06 ` [PATCH 07/24] serial: 8250: hold hash_mutex across irq_info lookup and linking Greg Kroah-Hartman
2026-10-27 11:12   ` sashiko-bot
2026-10-27 12:00   ` Ilpo Järvinen
2026-10-27 11:06 ` [PATCH 08/24] serial: 8250: cancel overrun backoff work on port shutdown and unregister Greg Kroah-Hartman
2026-10-27 11:27   ` sashiko-bot
2026-10-27 12:15   ` Ilpo Järvinen
2026-10-27 11:06 ` [PATCH 09/24] serial: 8250: 8250_bcm7271: fix DMA address truncation to 32 bits Greg Kroah-Hartman
2026-10-27 11:10   ` sashiko-bot
2026-10-27 12:18   ` Ilpo Järvinen
2026-10-27 15:10   ` Andy Shevchenko
2026-10-27 16:41     ` Florian Fainelli
2026-10-27 17:14       ` Andy Shevchenko
2026-10-27 17:19         ` Florian Fainelli
2026-10-27 18:37           ` Arnd Bergmann
2026-10-27 11:06 ` [PATCH 10/24] serial: 8250: pericom: validate port offset against BAR length Greg Kroah-Hartman
2026-10-27 11:12   ` sashiko-bot
2026-10-27 15:13   ` Andy Shevchenko
2026-10-27 11:06 ` [PATCH 11/24] serial: 8250: cap OxSemi Tornado UART count against BAR size Greg Kroah-Hartman
2026-10-27 11:18   ` sashiko-bot
2026-10-27 11:23   ` Jiri Slaby
2026-10-27 11:33     ` Greg Kroah-Hartman
2026-10-27 12:24   ` Ilpo Järvinen
2026-10-27 14:29   ` Maciej W. Rozycki
2026-10-27 15:23     ` Andy Shevchenko
2026-10-27 21:13       ` Maciej W. Rozycki
2026-10-28 10:52     ` Cameron Williams
2026-10-28 15:10       ` Maciej W. Rozycki
2026-10-27 11:06 ` [PATCH 12/24] serial: 8250: dfl: add bounds check for device-provided regshift Greg Kroah-Hartman
2026-10-27 11:17   ` sashiko-bot
2026-10-27 15:36   ` Andy Shevchenko
2026-10-27 11:06 ` [PATCH 13/24] serial: 8250: dfl: validate MMIO resource size and regshift Greg Kroah-Hartman
2026-10-27 11:26   ` sashiko-bot
2026-10-27 12:30   ` Ilpo Järvinen
2026-10-27 15:38   ` Andy Shevchenko
2026-10-27 11:06 ` [PATCH 14/24] serial: 8250: ioc3: store registered line number in driver data Greg Kroah-Hartman
2026-10-27 11:11   ` sashiko-bot
2026-10-27 11:27     ` Jiri Slaby
2026-10-27 12:38   ` Ilpo Järvinen
2026-10-27 13:10     ` Greg Kroah-Hartman
2026-10-28 15:37   ` kernel test robot
2026-10-27 11:06 ` [PATCH 15/24] serial: 8250: omap: acquire rx_dma_lock in DMA completion callback Greg Kroah-Hartman
2026-10-27 11:13   ` sashiko-bot
2026-10-27 12:52   ` Ilpo Järvinen
2026-10-27 11:06 ` [PATCH 16/24] serial: 8250_lpss: don't divide by 0 above 6.25 Mbaud Greg Kroah-Hartman
2026-10-27 11:18   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 17/24] serial: 8250_mxpcie: handle hangup during break Greg Kroah-Hartman
2026-10-27 11:18   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 18/24] serial: fsl_lpuart: fix tty ref of wakeup event Greg Kroah-Hartman
2026-10-27 11:11   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 19/24] serial: imx: fix the tty reference of the " Greg Kroah-Hartman
2026-10-27 11:12   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 20/24] serial: rda: free the interrupt on shutdown Greg Kroah-Hartman
2026-10-27 11:10   ` sashiko-bot
2026-10-27 12:38   ` Manivannan Sadhasivam
2026-10-27 11:06 ` [PATCH 21/24] serial: samsung: don't leak the tty on an RX IRQ Greg Kroah-Hartman
2026-10-27 11:11   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 22/24] serial: samsung: put the previous baud clock Greg Kroah-Hartman
2026-10-27 11:13   ` sashiko-bot
2026-10-27 11:06 ` [PATCH 23/24] serial: st-asc: don't report a wakeup to a closed tty Greg Kroah-Hartman
2026-10-27 11:12   ` sashiko-bot
2026-10-27 15:51   ` Andy Shevchenko
2026-10-27 11:06 ` [PATCH 24/24] serial: stm32: " Greg Kroah-Hartman
2026-10-27 11:15   ` sashiko-bot
2026-10-27 13:02   ` Ilpo Järvinen
2026-10-29  5:54     ` Jiri Slaby
2026-10-27 15:06 ` [PATCH 00/24] tty/serial: a bunch of llm-found fixes Andy Shevchenko
2026-10-27 15:50   ` Greg Kroah-Hartman
2026-10-27 16:32     ` Andy Shevchenko

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=sashiko-outbox-186444@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.