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 0652ECA0EE4 for ; Tue, 26 Aug 2025 06:51:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6E26A10E5CC; Tue, 26 Aug 2025 06:51:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="nzpMLnWb"; dkim-atps=neutral Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77B7410E5CC; Tue, 26 Aug 2025 06:51:02 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 73A455C5B15; Tue, 26 Aug 2025 06:51:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9575CC113D0; Tue, 26 Aug 2025 06:50:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756191050; bh=1xqeDYgOtN+fbXijQEv4PbpP6hYNVxHLpg1R+RFdHeI=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=nzpMLnWbauEU7SotKMMyLUpd3pb8yLKUsQQ6QzFGIhe0slqdK5StmXwcvMGahXpMH T3z4uv/lxeTVe7IugmiuLHN9yO9N245LfmyppLRxbFb+iBSbc2DPZcjY2IqLHspHhx Z7f7F4afPGlSIB+5CX9FIVoQhkUyOdQGzaH8nZFch0ep23IG5E/W4dCThTOUhxE2Qh q2aWse04Appmzg4evMjmXe2uKEE0plfKASV86Sswdld5526BZFIspskidlbGCiPNRQ XI44B5kgo+JlbHm8kdjcPSRWODCKfh3yDCDy1mc0xQsK7PWNu5dAN5Dr5pGkOTIrVv W66NR3+ZeCxqA== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 26 Aug 2025 08:50:44 +0200 Message-Id: Cc: "John Hubbard" , "Alistair Popple" , "Joel Fernandes" , "Timur Tabi" , , , , Subject: Re: [PATCH v2 1/8] rust: transmute: add `from_bytes_copy` method to `FromBytes` trait From: "Benno Lossin" To: "Alexandre Courbot" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "David Airlie" , "Simona Vetter" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" X-Mailer: aerc 0.20.1 References: <20250826-nova_firmware-v2-0-93566252fe3a@nvidia.com> <20250826-nova_firmware-v2-1-93566252fe3a@nvidia.com> In-Reply-To: <20250826-nova_firmware-v2-1-93566252fe3a@nvidia.com> X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On Tue Aug 26, 2025 at 6:07 AM CEST, Alexandre Courbot wrote: > `FromBytes::from_bytes` comes with a few practical limitations: > > - It requires the bytes slice to have the same alignment as the returned > type, which might not be guaranteed in the case of a byte stream, > - It returns a reference, requiring the returned type to implement > `Clone` if one wants to keep the value for longer than the lifetime of > the slice. I think that any `Sized` type that can implement `FromBytes` also can implement `Copy`, so I don't feel like the last point is a strong one. But the unaligned byte stream is motivation enough :) > To overcome these when needed, add a `from_bytes_copy` with a default > implementation in the trait. `from_bytes_copy` returns an owned value > that is populated using an unaligned read, removing the lifetime > constraint and making it usable even on non-aligned byte slices. > > Reviewed-by: Alice Ryhl > Signed-off-by: Alexandre Courbot Reviewed-by: Benno Lossin --- Cheers, Benno > --- > rust/kernel/transmute.rs | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+)