From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15A7AFCC073 for ; Fri, 6 Mar 2026 20:40:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7AE9110E3F8; Fri, 6 Mar 2026 20:40:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="twajuNQM"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C9DE10E3F8 for ; Fri, 6 Mar 2026 20:40:22 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 6C8086001D; Fri, 6 Mar 2026 20:40:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A6A9C4CEF7; Fri, 6 Mar 2026 20:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772829621; bh=s4RDs0Sy8yYTYYQcL6MMYKDtq50LSWwy8CeiXluWEkg=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=twajuNQM4icDyMkN9QMukT/ei+/6SKyeXSIe7jnVpq44xni17dXCaFXBgUNiY8sVD ddGPXIafwTVIzVqrX3VEqW2c1PhfYIsUL+laaCCh11NacnaHAi2ncNEQAtfUoONqQ9 262P7xc5hYBr/zGz3cRLGVuai6sQg0oetZFtKut6nf5cWkPnvPAaOR8I7vPFCBlNZs nFjH5PrPZ1ISoCgOySMen/k9D5U6U1gQ4raD4s2CCjE6fwIcD2vo1FoksKxFxtJ2Va ZiydTLoDiFF7Vg7U3Bh7mUm2Wpi9uZSXy6CUk29bfqDyo1vt0ZCVzDghEWuvfsxXsR Y5pv0BiF4dB+A== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 06 Mar 2026 21:40:14 +0100 Message-Id: Subject: Re: [PATCH v2 3/4] rust: add basic serial device bus abstractions Cc: "Rob Herring" , "Greg Kroah-Hartman" , "Jiri Slaby" , "Miguel Ojeda" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Kari Argillander" , "Rafael J. Wysocki" , "Viresh Kumar" , "Boqun Feng" , "David Airlie" , "Simona Vetter" , , , , , , To: "Markus Probst" From: "Danilo Krummrich" References: <20260306-rust_serdev-v2-0-e9b23b42b255@posteo.de> <20260306-rust_serdev-v2-3-e9b23b42b255@posteo.de> In-Reply-To: <20260306-rust_serdev-v2-3-e9b23b42b255@posteo.de> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Fri Mar 6, 2026 at 8:35 PM CET, Markus Probst wrote: > + extern "C" fn receive_buf_callback( > + sdev: *mut bindings::serdev_device, > + buf: *const u8, > + length: usize, > + ) -> usize { > + // SAFETY: The serial device bus only ever calls the receive buf= callback with a valid > + // pointer to a `struct serdev_device`. > + // > + // INVARIANT: `sdev` is valid for the duration of `receive_buf_c= allback()`. > + let sdev =3D unsafe { &*sdev.cast::= >() }; > + > + // SAFETY: `receive_buf_callback` is only ever called after a su= ccessful call to > + // `probe_callback`, hence it's guaranteed that `Device::set_drv= data()` has been called > + // and stored a `Pin>`. > + let data =3D unsafe { sdev.as_ref().drvdata_borrow::() }; > + > + // SAFETY: > + // - The serial device bus only ever calls the receive buf callb= ack with a valid pointer to > + // a `struct serdev_device`. > + // - `receive_buf_callback` is only ever called after a successf= ul call to > + // `probe_callback`, hence it's guaranteed that `sdev.private_= data` is a pointer > + // to a valid `PrivateData`. > + let private_data =3D unsafe { &*(*sdev.as_raw()).private_data.ca= st::() }; > + > + private_data.probe_complete.complete_all(); Will do a full review pass later on, but one quick question in advance: What is this used for? It is completed here and in probe(), but I don't see= it ever being used to actually wait. > + > + // SAFETY: No one has exclusive access to `private_data.error`. > + if unsafe { *private_data.error.get() } { > + return length; > + } > + > + // SAFETY: `buf` is guaranteed to be non-null and has the size o= f `length`. > + let buf =3D unsafe { core::slice::from_raw_parts(buf, length) }; > + > + T::receive(sdev, data, buf) > + } > +}