All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hugo Villeneuve" <hugo@hugovil.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: max310x: simplify clock management with devm_clk_get_optional_enabled()
Date: Wed, 02 Dec 2026 16:40:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-246237@kernel.org> (raw)
In-Reply-To: <20261202162824.34779-1-hugo@hugovil.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] serial: max310x: use-after-free in max310x_remove() [1]
--

commit b2a072021bb98e40adfb8c4e05317de478392670
Author: Hugo Villeneuve <hugo@hugovil.com>

serial: max310x: simplify clock management with devm_clk_get_optional_enabled()

This commit replaces devm_clk_get_optional() and manual clock enable and
disable calls with devm_clk_get_optional_enabled().

> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index de8a1f05cf30e..8a71127c29210 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c

[ ... ]

> @@ -2105,8 +2094,6 @@ static void max310x_remove(struct device *dev)
>  
>  		max310x_power(&s->p[i].port, 0);
>  	}
> -
> -	clk_disable_unprepare(s->clk);
>  }

[Severity: Critical]
This problem wasn't introduced by this patch, but can max310x_remove()
cause a use-after-free on struct max310x_port [1] by cancelling the
port work items before calling uart_remove_one_port()?

drivers/tty/serial/max310x.c:max310x_remove() {
	for (i = 0; i < s->devtype->nr; i++) {
		hrtimer_cancel(&s->p[i].tx_delay_tmr);
		cancel_work_sync(&s->p[i].rts_work);
		cancel_work_sync(&s->p[i].tx_work);
		cancel_work_sync(&s->p[i].md_work);
		cancel_work_sync(&s->p[i].rs_work);

		if (test_and_clear_bit(s->p[i].port.line, max310x_lines))
			uart_remove_one_port(&max310x_uart, &s->p[i].port);
    ...
}

Because the UART port is still registered and the devm-managed IRQ is
still active when cancel_work_sync() runs, concurrent tty operations or
interrupts can requeue the work items before uart_remove_one_port()
completes:

CPU0                              CPU1
max310x_remove()
  cancel_work_sync(&s->p[i].tx_work)
                                  max310x_start_tx()
                                    schedule_work(&one->tx_work)
  uart_remove_one_port()
devres_release_all()
  kfree(s)
                                  max310x_tx_proc()  <-- use-after-free

[1] https://sashiko.dev/#/bug/linux-5f8166f2-80f6-4ce1-9c42-cff293ba7fbc

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202162824.34779-1-hugo@hugovil.com?part=1

      reply	other threads:[~2026-12-02 16:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 16:28 [PATCH] serial: max310x: simplify clock management with devm_clk_get_optional_enabled() Hugo Villeneuve
2026-12-02 16:40 ` sashiko-bot [this message]

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-246237@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hugo@hugovil.com \
    --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.