From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 376C1137930; Wed, 26 Mar 2025 20:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743019233; cv=none; b=Y2Ambe/gWxH3a1vVtsWy4WMds47n3VP4feQO1RUjqQI2Dw9ly5UtJLrn443G+EbJOp2qsSS3pMEhNYeA4HKB7+YyWpmjZknOylOiaViHVUMoSj9Ugry4hCOaPrZ+F9FCEnl5II0Wj35G9sHa0Z8qcTsqZctzIeO/Rn1repo6vFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743019233; c=relaxed/simple; bh=bvMdOWoWq0TBIL9gpxTw+jRmtDhjTC4zq9zMiMKAk0Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ecXqZGIpcRY1K8/2J2ckihFzMgw4x0/WmMjVRWIQTxsQ9DFX/Qk72N8lNFfVbxzrFd9P/QfWXe8fcUJ2u1551wRe9cWcfqNSErudu2qb/JdnvMXVZk5kuAP2J9Br84hvKtREmh5rSVy21tuzv1vDh8PpYKLNhAUXJw2O0c8FLho= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Coz3br1C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Coz3br1C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B9D8C4CEE2; Wed, 26 Mar 2025 20:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743019232; bh=bvMdOWoWq0TBIL9gpxTw+jRmtDhjTC4zq9zMiMKAk0Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Coz3br1C085AjKg3xpEu3rqJOSHK4+9FHNRPrwigy2X+ZSLurJxOOx8bi6irynCeN Jk3QfzJoZpmz7BnBy2Fyj7sU68qAZhxCpbCrsDPouLni+XXcl5sN8xFHotAEy5IeBf N4SC0tRAJNR34XzWtelXMe5InrO3ipA2XNQdyrtb6bBU5MiSDw1u6pBmzEb0MKSu0F /4FOGMFT+bbQyqe1HaWzkhP66gSQMUbYhjc3fd4cbKvvhgxeLLbMdcM1n4Om0kojCo c3oeg0tPGGladfi9fiQIPJx4I5NZmS9M/IOt9vpyjkuOD++cmRNNSUsiI9GSWAYy9S 3kF2HnsBEUJWg== Date: Wed, 26 Mar 2025 15:00:31 -0500 From: Rob Herring To: Remo Senekowitsch Cc: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Dirk Behme , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Saravana Kannan , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH 02/10] rust: Add an Integer trait Message-ID: <20250326200031.GA2787672-robh@kernel.org> References: <20250326171411.590681-1-remo@buenzli.dev> <20250326171411.590681-3-remo@buenzli.dev> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250326171411.590681-3-remo@buenzli.dev> On Wed, Mar 26, 2025 at 06:13:41PM +0100, Remo Senekowitsch wrote: > From: "Rob Herring (Arm)" > > Add an "Integer" trait similar to crate::num::Integer. This is useful > for implementing generic methods which operate on different sizes of > integers. One example is reading DT/ACPI firmware properties. > > This was originally proposed by Alice Ryhl[1]. > > [1] https://lore.kernel.org/rust-for-linux/CAH5fLgiXPZqKpWSSNdx-Ww-E9h2tOLcF3_8Y4C_JQ0eU8EMwFw@mail.gmail.com/ > > Suggested-by: Alice Ryhl > Signed-off-by: Rob Herring (Arm) This needs your Signed-off-by too because you are sending it. > --- > rust/kernel/types.rs | 22 +++++++++++++++++++++- > 1 file changed, 21 insertions(+), 1 deletion(-) > > diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs > index 2bbaab83b..21647b7ba 100644 > --- a/rust/kernel/types.rs > +++ b/rust/kernel/types.rs > @@ -3,10 +3,11 @@ > //! Kernel types. > > use crate::init::{self, PinInit}; > +use crate::transmute::{AsBytes, FromBytes}; > use core::{ > cell::UnsafeCell, > marker::{PhantomData, PhantomPinned}, > - mem::{ManuallyDrop, MaybeUninit}, > + mem::{size_of, ManuallyDrop, MaybeUninit}, > ops::{Deref, DerefMut}, > ptr::NonNull, > }; > @@ -553,6 +554,25 @@ pub enum Either { > Right(R), > } > > +/// Trait defined for all integer types similar to `crate::num::Integer` > +pub trait Integer: FromBytes + AsBytes + Copy { > + /// Size of the integer in bytes > + const SIZE: usize; > +} > + > +macro_rules! impl_int { > + ($($typ:ty),* $(,)?) => {$( > + impl Integer for $typ { > + const SIZE: usize = size_of::(); > + } > + )*}; > +} > + > +impl_int! { > + u8, u16, u32, u64, usize, > + i8, i16, i32, i64, isize, > +} > + > /// Zero-sized type to mark types not [`Send`]. > /// > /// Add this type as a field to your struct if your type should not be sent to a different task. > -- > 2.49.0 >