All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v5 1/4] tty: serdev: Add mutex lock
Date: Thu, 22 Oct 2026 12:19:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-181426@kernel.org> (raw)
In-Reply-To: <20261022-rust_serdev_probe_refactor-v5-1-a27d862a415a@posteo.de>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] tty: serdev: returning -EALREADY in ttyport_open() breaks hci_mrvl probe
- [High] tty: serdev: late close in serdev_device_remove() and missed driver unbind
--

commit 792f1e31002a2c366a7d3535ec38a8a39ce21b0c
Author: Markus Probst <markus.probst@posteo.de>

tty: serdev: Add mutex lock

This commit adds mutexes to serialize serport state changes and receive
buffer handling in serdev-ttyport. It also rejects repeated opens with
-EALREADY, ignores redundant closes, and warns if a device is left open on
removal.

> diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
> index 7500efcdfc218..77e8e1d4d2a66 100644
> --- a/drivers/tty/serdev/core.c
> +++ b/drivers/tty/serdev/core.c
> @@ -142,6 +142,11 @@ void serdev_device_remove(struct serdev_device *serdev)
>  	struct serdev_controller *ctrl = serdev->ctrl;
>  
>  	device_unregister(&serdev->dev);
> +
> +	/* Warn if driver did not close the serial device. */
> +	if (ctrl->ops->close && WARN_ON(ctrl->ops->close(ctrl)))
> +		pm_runtime_put(&ctrl->dev);
> +
>  	ctrl->serdev = NULL;
>  }
>  EXPORT_SYMBOL_GPL(serdev_device_remove);

[Severity: High]
Is it safe to call ctrl->ops->close(ctrl) after device_unregister(&serdev->dev)
has already completed?

In serdev_device_remove(), device_unregister(&serdev->dev) calls device_del(),
which unbinds the driver via serdev_drv_remove() and runs
device_unbind_cleanup() (releasing devres resources and clearing drvdata),
followed by put_device(&serdev->dev), which invokes serdev_device_release()
and frees serdev:

drivers/tty/serdev/core.c:serdev_device_release() {
	struct serdev_device *serdev = to_serdev_device(dev);
	kfree(serdev);
}

When a driver leaves the port open across remove, SERPORT_ACTIVE remains set
and ctrl->serdev points to the freed serdev_device throughout
device_unbind_cleanup() and put_device() until ctrl->ops->close(ctrl) clears
SERPORT_ACTIVE. Could a concurrent ttyport_receive_buf() or
ttyport_write_wakeup() during this window dereference the freed ctrl->serdev
or invoke serdev->ops callbacks with NULL or freed drvdata?

Also, serdev_device_remove() is only called when unregistering the
serdev_device itself, not when unbinding a driver via serdev_drv_remove():

drivers/tty/serdev/core.c:serdev_drv_remove() {
	const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver);
	if (sdrv->remove)
		sdrv->remove(to_serdev_device(dev));
}

If a driver leaves the device open on unbind (or after a failed probe),
wouldn't SERPORT_ACTIVE stay set while drvdata is cleared, leaving the port
open and causing any subsequent re-probe to fail in serdev_device_open() with
-EALREADY?

[ ... ]

> diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
> index bab1b143b8a68..7d2d50d7e1a48 100644
> --- a/drivers/tty/serdev/serdev-ttyport.c
> +++ b/drivers/tty/serdev/serdev-ttyport.c

[ ... ]

> @@ -99,14 +103,23 @@ static int ttyport_open(struct serdev_controller *ctrl)
>  	struct ktermios ktermios;
>  	int ret;
>  
> +	mutex_lock(&serport->lock);
> +
> +	if (test_bit(SERPORT_ACTIVE, &serport->flags)) {
> +		ret = -EALREADY;
> +		goto err_flags_unlock;
> +	}

[Severity: High]
Won't returning -EALREADY here cause a regression when probing Marvell
Bluetooth serdev devices in drivers/bluetooth/hci_mrvl.c?

During mrvl_serdev_probe(), hci_uart_register_device() calls
hci_uart_register_device_priv(), which opens hu->serdev before invoking the
protocol open callback p->open(hu):

drivers/bluetooth/hci_serdev.c:hci_uart_register_device_priv() {
	...
	err = serdev_device_open(hu->serdev);
	if (err)
		goto err_rwsem;

	err = p->open(hu);
	if (err)
		goto err_open;
	...
}

In drivers/bluetooth/hci_mrvl.c, mrvl_open() then calls
serdev_device_open(hu->serdev) a second time:

drivers/bluetooth/hci_mrvl.c:mrvl_open() {
	...
	if (hu->serdev) {
		ret = serdev_device_open(hu->serdev);
		if (ret)
			goto err;
	}
	...
}

With ttyport_open() returning -EALREADY when SERPORT_ACTIVE is already set,
won't mrvl_open() fail unconditionally and abort mrvl_serdev_probe()?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261022-rust_serdev_probe_refactor-v5-0-a27d862a415a@posteo.de?part=1

  reply	other threads:[~2026-10-22 12:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 11:51 [PATCH v5 0/4] rust: serdev: Refactor Markus Probst
2026-10-22 11:51 ` [PATCH v5 1/4] tty: serdev: Add mutex lock Markus Probst
2026-10-22 12:19   ` sashiko-bot [this message]
2026-10-22 11:51 ` [PATCH v5 2/4] tty: serdev: Export functions to pause receive_buf callback calls Markus Probst
2026-10-22 11:59   ` sashiko-bot
2026-10-22 11:51 ` [PATCH v5 3/4] rust: serdev: Replace `active` mutex with receive pause Markus Probst
2026-10-22 12:04   ` sashiko-bot
2026-10-22 12:14     ` Markus Probst
2026-10-22 11:51 ` [PATCH v5 4/4] rust: serdev: Simplify callbacks Markus Probst
2026-10-22 12:00   ` sashiko-bot

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-181426@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-serial@vger.kernel.org \
    --cc=markus.probst@posteo.de \
    --cc=ojeda@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.