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=1796404431; b=OZZfvrZ7h6Gv/ji2bZT0QZrwMhFWZOIJvU2n+hUKREXSmsM2QBxCjQxJ56VZ0VrN4P59 EnkzV+W0ZTqxJy2qn04PSmLVgU9cR39D+p7S208c/I0ywOhDieKk4TQz3PaXoTXcCossO GwH8pMD48F5UCWoOKgUdEpHqXPsadIndBiY//hOlcYH2/tEt4ymt9iKdOH3Bkq58KKBZk SjW+l+tiQ/T43i7h8jLEPjOhgBiFe2R5UpOf8z8x3CpJTqQ3DpvBp7nw/u1sxNwYzsGZZ +nR0vqN8zt1+U8E2NR8lDT6iqR1N50f1GDLHl7sSmdxVO8OGGp9U+z3l4ZmifeqKCGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404431; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=luxJ2qWcpjy/TAYAQwe2bpY8U/13STpKZLhAQglGQW8=; b=SbHzchqMMkQI1718NlclL2OpyUXpRkva6F0w//9lTIB7We29pMhgk7kLZzV1cuTpRa/W omzS74hxQOacq47uSoA+sK+5zFU2fG2N7Sj+jPodvielPPatDe7xam+eL+J9GW5Byc5AM zRDG6R1mK1rMdDNTxtWqNfvJx19FGriTqUXdIHKiAmtE6ktSSsWHGmU8zD9v40NjI+w0P 4X+ABjzHrnV/xGUURK9HkVYWG87ruR0svfc5q/e/iZYuL3pNuTyp/++l3W9AvbnOcjVzL P14v7c7yKjAxGDUi6pFTtP2d7rg/lWK/dWkfixh1Lf81hPTWosS60gJaKStB5USjdRQ== 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="PMqS3/1M"; 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 75A71606A322 for ; Fri, 4 Dec 2026 17:13:51 +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=PMqS3/1M Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29C5C1F00A14; Fri, 4 Dec 2026 17:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796404431; bh=luxJ2qWcpjy/TAYAQwe2bpY8U/13STpKZLhAQglGQW8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PMqS3/1M6OWk3AVB7D4zgjdMjbgKUjGS1SXD1ftXwBD3t+a4Iyucr3AlnEpCFR7eU XK7rmpmYSCBR21rbfEOEBSZSnrOg6QVzTDgLC0cXrCqCfFBoQXL6S5JZPUMSUEz30s /BGSl294XuENNFYuVEgXxuq/f66Fm3XxybKCbEPhlaGI26gucYI7dtAUuRusWFxSvk wy7nlTncF/CLUJYmwRPGGkpWY99HcOvtI9EocX5RVsNxvUHKOLlgjP3WqJVr+dOim6 3o9YLV+zfDkVubOUJh35h/nrN87hbDvSAHmUMeOmLtWo4jekD5yf6gA7a/U9jssCDC Cele2J0lQsUMg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND v6 4/4] rust: serdev: Simplify callbacks 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-4-0e12b6e6853b@posteo.de> References: <20261204-rust_serdev_probe_refactor-v6-0-0e12b6e6853b@posteo.de> <20261204-rust_serdev_probe_refactor-v6-4-0e12b6e6853b@posteo.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:13:50 +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 2 potential issues to consider: - [Low] rust: serdev: missing safety comments on PrivateData drop order and OpenGuard - [Low] rust: serdev: unnecessary unsafe blocks in PrivateData::driver_data() -- commit 291367d86a907a67ebd9525dcf9dbb55c3c6c67c Author: Markus Probst rust: serdev: Simplify callbacks This commit initializes the driver's private data directly on PrivateData via pin-init and introduces OpenGuard to close the serdev device on drop. > diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs > index 559d142ce5573..3f9165e167764 100644 > --- a/rust/kernel/serdev.rs > +++ b/rust/kernel/serdev.rs [ ... ] > @@ -92,24 +88,36 @@ unsafe fn unregister(sdrv: &Opaque)= { > } > } > =20 > +struct OpenGuard<'bound> { > + sdev: &'bound Device, > +} > + > +impl Drop for OpenGuard<'_> { > + fn drop(&mut self) { > + // SAFETY: > + // - `self.sdev.as_raw()` is guaranteed to be a pointer to a val= id > + // `struct serdev_device`. > + // - The existence of self proves that the device is open. > + unsafe { bindings::serdev_device_close(self.sdev.as_raw()) }; > + } > +} > + > #[doc(hidden)] > -#[pin_data(PinnedDrop)] > +#[pin_data] > pub struct PrivateData<'bound, T: Driver> { > - sdev: &'bound Device, > #[pin] > - driver: UnsafeCell>>, > - open: UnsafeCell, > + driver: T::Data<'bound>, > + open: OpenGuard<'bound>, > } [Severity: Low] Should PrivateData document that driver must be declared before open for drop-order safety? Adapter::probe_callback() initializes open before driver in try_pin_init!(), the reverse of PrivateData's field order. Reordering the fields to match would close the device before T::Data drops, causing a NULL pointer dereference of serport->tty if T::Data's Drop calls Device methods. Also, OpenGuard::drop() relies on the device being open whenever an OpenGua= rd exists, so OpenGuard could use an # Invariants doc section and a matching INVARIANT comment where it is constructed in probe_callback(). > =20 > -#[pinned_drop] > -impl PinnedDrop for PrivateData<'_, T> { > - fn drop(self: Pin<&mut Self>) { > - // SAFETY: We have exclusive access to `self.open`. > - if unsafe { *self.open.get() } { > - // SAFETY: `self.sdev.as_raw()` is guaranteed to be a pointe= r to a valid > - // `struct serdev_device`. > - unsafe { bindings::serdev_device_close(self.sdev.as_raw()) }; > - } > +impl<'bound, T: Driver> PrivateData<'bound, T> { > + #[inline] > + fn driver_data(self: Pin<&Self>) -> Pin<&T::Data<'bound>> { > + // SAFETY: We treat the result as pinned. > + let inner =3D unsafe { Pin::into_inner_unchecked(self) }; > + > + // SAFETY: `self.driver` is pinned. > + unsafe { Pin::new_unchecked(&inner.driver) } > } > } [Severity: Low] Can driver_data() avoid both unsafe blocks by using pin-init's generated with_project_ref() projection? Because PrivateData is #[pin_data] with #[pin] on driver, self.with_project_ref(|this| this.driver) projects Pin<&Self> to Pin<&T::Data<'bound>> safely without Pin::into_inner_unchecked() or Pin::new_unchecked(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-rust_serde= v_probe_refactor-v6-0-0e12b6e6853b@posteo.de?part=3D4