Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chengfeng Ye" <nicoyip.dev@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH] tty: Serialize saved termios access with device registration
Date: Sat, 26 Sep 2026 18:52:30 +0000	[thread overview]
Message-ID: <20260926185231.344DA1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260926184154.3017929-1-nicoyip.dev@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] tty: mixing goto-based error handling with scoped cleanup helpers
--

commit 6bd1bebdb72fb484cd4c55333cfb5b66866fd06e
Author: Chengfeng Ye <nicoyip.dev@gmail.com>

tty: Serialize saved termios access with device registration

tty_register_device_attr() frees saved termios data when reusing a minor
number without serializing with tty_init_termios() or tty_save_termios().
The tty_mutex held by the open and close paths does not protect against
this registration-side free.

> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index 48569035da56e..26bdc4560a4c8 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
[ ... ]
> @@ -3242,10 +3247,12 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
>  		 * Free any saved termios data so that the termios state is
>  		 * reset when reusing a minor number.
>  		 */
> -		tp = driver->termios[index];
> -		if (tp) {
> -			driver->termios[index] = NULL;
> -			kfree(tp);
> +		scoped_guard(mutex, &tty_termios_mutex) {
> +			tp = driver->termios[index];
> +			if (tp) {
> +				driver->termios[index] = NULL;
> +				kfree(tp);
> +			}
>  		}
>  
>  		retval = tty_cdev_add(driver, devt, index, 1);

[Severity: Low]
Does this violate the guidelines against mixing goto-based error handling
with scope-based cleanup helpers?

tty_register_device_attr() already uses explicit goto labels for error
cleanup:

err_del:
	device_del(dev);
err_put:
	put_device(dev);

Mixing these paradigms can create confusing ownership semantics and
increases the risk of resource leaks or double-free bugs during future
refactorings.

Could the function be completely converted to scope-based cleanup first,
or could this patch use traditional locking (mutex_lock/mutex_unlock)
instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260926184154.3017929-1-nicoyip.dev@gmail.com?part=1

  reply	other threads:[~2026-09-26 18:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26 18:41 [PATCH] tty: Serialize saved termios access with device registration Chengfeng Ye
2026-09-26 18:52 ` sashiko-bot [this message]
2026-09-30  9:20 ` Johan Hovold
2026-09-30 16:27   ` Chengfeng Ye

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=20260926185231.344DA1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=nicoyip.dev@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox