Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796404966; b=bJVYfAUtoWsxPjIlm73BH24kUzPZ4rFayIj/xYyVE7dpNpfsC7AqUylMae0owmmE8YTE z/TrjuCiDvAkfoP1PNdxNJrZ0u86fH4kOJwIjpgpwF7p/5cyXUGM5eqOEqw9tGXOyzXVF plvZzjGOodo3n25Sr6of3wVTCKGDwC79f0uGRauTDAYGS9gA+fJG0TMMtVxZcy/6YWnk+ 3s5aXGvbUxnVf5EO8S7G8AKhKaptT3rBM3r41yd7vOt6P+vvRljCvni3yeOIp3c20nwZ8 MwMwwur3RHbl9jJmxn9ZlA7HNFixKWST3k9KzgLh/psQfaZe+s9r42NggyZzKovmNCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404966; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ftTs+yBLDrj5t1GNTtJihgWQENW6OeJargVkwGzCk5E=; b=D3yDXiTYf6EmHWD7Hn06mq0M0CsHzd3Ji8mg8fxxBeeUgHRKeeeuT2DvwD0JQ/WMIvFU FSJSMP5tdRmZhnXOj5pENbBaOdDj3a7Wte49O2a5FXAJjK6DhvVEk35s+8Iw6WRbTSnJo gGC9xbQfJTgotxdoOqksdkDXJMFRSaONDVkS4/hq2oeX4cGhP2riNOYU4ks+7+2W1ZL5Q QFeIWGAC+yF0qnjC9VvNkKssdPSTSwV+xzBICIpaj7XafhGg8cAOdxm3Hl9Dyp2oGvI/w vjZ+S+rcz7Y5f+e9xmHIae91IWSkKQhpwf2MdmyCDIpbeEUQo2keuLpaTrwzfL7Fk3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GbyfIlM1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37C9F606A32C for ; Fri, 4 Dec 2026 17:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GbyfIlM1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC1471F0093B; Fri, 4 Dec 2026 17:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796404965; bh=ftTs+yBLDrj5t1GNTtJihgWQENW6OeJargVkwGzCk5E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GbyfIlM1MECkw1sDW4wzThsNQJ6X/yGwCW1fBRu+gIRJ1C4bIjgdWf8R9T6Bh5xNd pR/Gln5E5TWwlV8xQBcOvn+4uiZ81/mwr0INJd/PMJNMHE3d98IPrwzYAtQCbnd+BC GqnUxH1ceoPF69FuVW/ZywNUAJobey6mSXnGHPcWzXwL4gJPfF8TjlUIrYPz8kj3Im lHeNTHLxIt7VzCfGrGR2VG/3Ym+IwL9elX87d5LsZoI4iRKhfXIUM1V0gnzGUh/LUf 8TkLEpg0qStAMY30ZgmtPxXweSeAr0IcXP82qP0my6LcfVl/K7RJEIQD5jWpJF+gmB iu+1u2//w5DzQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND v6 1/4] tty: serdev: Add mutex lock Reply-To: sashiko-reviews@lists.linux.dev To: "Markus Probst" Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net In-Reply-To: <20261204-rust_serdev_probe_refactor-v6-1-0e12b6e6853b@posteo.de> References: <20261204-rust_serdev_probe_refactor-v6-0-0e12b6e6853b@posteo.de> <20261204-rust_serdev_probe_refactor-v6-1-0e12b6e6853b@posteo.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:22:45 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] tty: serdev: returning -EALREADY in ttyport_open() breaks hci_mrvl probe - [Medium] tty: serdev: fallback close runs after serdev free and misses driver unbind - [Medium] tty: serdev: serdev_tty_port_register() calls mutex_init() after client_ops - [Low] tty: serdev: data race from __test_and_clear_bit() in ttyport_close() - [Low] tty: serdev: dev_WARN() used instead of dev_warn() in serdev_device_remove() -- commit 7655d9d3e9b00ecf625ad8092540311e1db4b89e Author: Markus Probst tty: serdev: Add mutex lock This commit adds mutexes to serdev-ttyport to serialize open, close, and receive paths, returns -EALREADY on duplicate open, makes close idempotent, and closes leaked devices in serdev_device_remove(). > diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c > index 7500efcdfc218..86d9cf8215edc 100644 > --- a/drivers/tty/serdev/core.c > +++ b/drivers/tty/serdev/core.c > @@ -142,6 +142,13 @@ void serdev_device_remove(struct serdev_device *serd= ev) > struct serdev_controller *ctrl =3D serdev->ctrl; > =20 > device_unregister(&serdev->dev); > + > + /* Warn if driver did not close the serial device. */ > + if (ctrl->ops->close && ctrl->ops->close(ctrl)) { > + dev_WARN(&ctrl->dev, "Child driver did not close the serial device"); [Severity: Low] As reported by Greg Kroah-Hartman on v4 [1], should this use dev_warn() instead of dev_WARN()? dev_WARN() expands to WARN(1, ...), which prints a backtrace and triggers panic_on_warn; dev_warn() (with a trailing newline) logs a normal warning. > + pm_runtime_put(&ctrl->dev); > + } > + > ctrl->serdev =3D NULL; > } [Severity: Medium] Can this trigger a use-after-free on serdev when a child driver leaves the port open? For direct callers of serdev_device_remove() such as dell-uart-backlight, device_unregister(&serdev->dev) drops the last reference and frees serdev via serdev_device_release() before ctrl->ops->close(ctrl) clears SERPORT_ACTIVE and before ctrl->serdev is set to NULL: CPU0 CPU1 serdev_device_remove() device_unregister(&serdev->dev) device_del(&serdev->dev) put_device(&serdev->dev) kfree(serdev) ttyport_receive_buf() serdev_controller_receive_buf() serdev->ops->receive_buf(...) <-- use-after-free ctrl->ops->close(ctrl) ctrl->serdev =3D NULL Splitting device_unregister() into device_del(), the fallback close and ctrl->serdev =3D NULL, and finally put_device() keeps serdev alive until callbacks stop. Separately, driver unbind (such as sysfs unbind or rmmod) runs serdev_drv_remove() and device_unbind_cleanup() without calling serdev_device_remove(), so an unclosed port stays active and subsequent re-probes fail permanently with -EALREADY. Handling the fallback on BUS_NOTIFY_UNBOUND_DRIVER would run after devres_release_all() on unbind as well. [ ... ] > diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/ser= dev-ttyport.c > index b6638f9f40d2d..17c18d4b0cb8f 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 *ct= rl) > struct ktermios ktermios; > int ret; > =20 > + mutex_lock(&serport->lock); > + > + if (test_bit(SERPORT_ACTIVE, &serport->flags)) { > + ret =3D -EALREADY; > + goto err_flags_unlock; > + } [Severity: High] Does returning -EALREADY here break probing of Marvell serdev Bluetooth devices in drivers/bluetooth/hci_mrvl.c? During mrvl_serdev_probe(), hci_uart_register_device_priv() calls serdev_device_open(hu->serdev) and then invokes mrvl_open(), which calls serdev_device_open(hu->serdev) a second time and fails probe on any error. hci_mrvl.c (including its duplicate close in mrvl_close()) would need to be updated before rejecting duplicate opens with -EALREADY. [ ... ] > -static void ttyport_close(struct serdev_controller *ctrl) > +static bool ttyport_close(struct serdev_controller *ctrl) > { > struct serport *serport =3D serdev_controller_get_drvdata(ctrl); > - struct tty_struct *tty =3D serport->tty; > + struct tty_struct *tty; > + > + guard(mutex)(&serport->lock); > =20 > - clear_bit(SERPORT_ACTIVE, &serport->flags); > + tty =3D serport->tty; > + > + scoped_guard(mutex, &serport->receive_lock) > + if (!__test_and_clear_bit(SERPORT_ACTIVE, &serport->flags)) > + return false; [Severity: Low] Does switching to non-atomic __test_and_clear_bit() introduce a data race on serport->flags? ttyport_close() clears SERPORT_ACTIVE before tty->ops->close() stops TX interrupts, while ttyport_write_wakeup() and ttyport_write_buf() read serport->flags with test_bit() without holding serport->lock or serport->receive_lock. This triggers KCSAN data-race reports under CONFIG_KCSAN_STRICT=3Dy and performs a plain non-atomic write on architectures using generic non-atomic bitops. Using test_and_clear_bit() avoids the race and matches set_bit() in ttyport_open(). [ ... ] > @@ -290,6 +317,9 @@ struct device *serdev_tty_port_register(struct tty_po= rt *port, > port->client_ops =3D &client_ops; > port->client_data =3D ctrl; > =20 > + mutex_init(&serport->lock); > + mutex_init(&serport->receive_lock); [Severity: Medium] Can ttyport_receive_buf() lock serport->receive_lock before mutex_init() runs? UART drivers such as ip22zilog_probe() register their RX IRQ before uart_add_one_port(), and uart_configure_port() enables RX interrupts before serdev_tty_port_register() runs. Incoming RX bytes schedule flush_to_ldisc(), which only holds buf->lock (not port->mutex) and enters ttyport_receive_buf() before SERPORT_ACTIVE is checked: CPU0 CPU1 serdev_tty_port_register() port->client_ops =3D &client_ops port->client_data =3D ctrl flush_to_ldisc() ttyport_receive_buf() mutex_lock(&serport->receive_lock) <-- uninitialized mutex mutex_init(&serport->lock) mutex_init(&serport->receive_lock) Locking an uninitialized mutex or racing with mutex_init() triggers lockdep/debug-mutex warnings and can corrupt mutex state. Initializing both mutexes (and setting port->client_data) before assigning port->client_ops avoids the race. [1] https://lore.kernel.org/r/2026101758-confidant-comprised-e1c0@gregkh --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-rust_serde= v_probe_refactor-v6-0-0e12b6e6853b@posteo.de?part=3D1