From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (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 AC8F9269AF8; Tue, 25 Mar 2025 22:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742940705; cv=none; b=q2hHuVG97OnxOA2y/6FIknlUkGPpH6bGv14vnqg5OrQMc2aeHBysbO2Y1yv6/dikm9wBu1vuiCvNNBK5g6gNaACSSS78r/9NE6WypkhJvB4WM+GY5idmx7ky+sE44d+GC5j0YXSMCaVy3zR2seNtELzLVyu0Q1PKfGeR6RHODkk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742940705; c=relaxed/simple; bh=INtxnLlua0m5+riRrCQCNfpZkOBwhMZMhtFEG3oNA9M=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VM7eXcZqT7qh+1jACOhm2M39hm2pdSkciC+yU+OmSbohTxPmDyQ6E5VsMVIKk543hIvLMPJfR28q7ljPUEBsqS02h4epRFpFskyzETtbSK3bwWbwk6rjX+RbECEzeTCnddtV2PMEVg4a2g1Upd/H1qpSBygruVrBYuUmTsATVic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=Znt9efbO; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="Znt9efbO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742940696; x=1743199896; bh=jMMA8zQorl8Tfb7BH49RE8xPD4Fjn3HXBR627pProcA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Znt9efbO5eyaROb7dMqTfzYXCP0EPddfjrbSr5TYhf67lh7PlD+HzDFoAgW3FCWcl UhMt7ieP8Xng5o1UHsVJ15IHrfRCnuHKni5ksbFlJULfyJMGfMs/ujvgnj3w6ITxV8 e5HUtJhaWhST3TDk1ezjmyXBqQ7ZQIgx24Z/cHcCRgom7LTbPtoVPD4MMqPjQvWTUY ftXO/4TJo02vKzm907Kg6RhBarJ9GRjlbuVc3uVixaZQAEY940aUNBZzKIfNa1TPNc cQhXavsmny6cEvvvZTkvIuHqr937iMeNh1QGMuR9SFnZH7b4NeL/BTQb5buXFtbIG0 NwpD4q2IYg9cA== Date: Tue, 25 Mar 2025 22:11:27 +0000 To: Tamir Duberstein , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori From: Benno Lossin Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org Subject: Re: [PATCH v7 7/7] rust: enable `clippy::ref_as_ptr` lint Message-ID: In-Reply-To: <20250325-ptr-as-ptr-v7-7-87ab452147b9@gmail.com> References: <20250325-ptr-as-ptr-v7-0-87ab452147b9@gmail.com> <20250325-ptr-as-ptr-v7-7-87ab452147b9@gmail.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 193ea9b5afc3597accae5dbd9f02f4fdde8ca624 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=utf-8 Content-Transfer-Encoding: quoted-printable On Tue Mar 25, 2025 at 9:07 PM CET, Tamir Duberstein wrote: > diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs > index 40034f77fc2f..6233af50bab7 100644 > --- a/rust/kernel/str.rs > +++ b/rust/kernel/str.rs > @@ -29,7 +29,7 @@ pub const fn is_empty(&self) -> bool { > #[inline] > pub const fn from_bytes(bytes: &[u8]) -> &Self { > // SAFETY: `BStr` is transparent to `[u8]`. > - unsafe { &*(bytes as *const [u8] as *const BStr) } > + unsafe { &*(core::mem::transmute::<*const [u8], *const Self>(byt= es)) } Hmm I'm not sure about using `transmute` here. Yes the types are transparent, but I don't think that we should use it here. > } > =20 > /// Strip a prefix from `self`. Delegates to [`slice::strip_prefix`]= . > @@ -290,7 +290,7 @@ pub const fn from_bytes_with_nul(bytes: &[u8]) -> Res= ult<&Self, CStrConvertError > #[inline] > pub unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) ->= &mut CStr { > // SAFETY: Properties of `bytes` guaranteed by the safety precon= dition. > - unsafe { &mut *(bytes as *mut [u8] as *mut CStr) } > + unsafe { &mut *(core::mem::transmute::<*mut [u8], *mut Self>(byt= es)) } > } > =20 > /// Returns a C pointer to the string. > diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs > index 80a9782b1c6e..c042b1fe499e 100644 > --- a/rust/kernel/uaccess.rs > +++ b/rust/kernel/uaccess.rs > @@ -242,7 +242,7 @@ pub fn read_raw(&mut self, out: &mut [MaybeUninit= ]) -> Result { > pub fn read_slice(&mut self, out: &mut [u8]) -> Result { > // SAFETY: The types are compatible and `read_raw` doesn't write= uninitialized bytes to > // `out`. > - let out =3D unsafe { &mut *(out as *mut [u8] as *mut [MaybeUnini= t]) }; > + let out =3D unsafe { &mut *(core::mem::transmute::<*mut [u8], *m= ut [MaybeUninit]>(out)) }; I have a patch that adds a `cast_slice_mut` method that could be used here, so I can fix it in that series. But let's not use `transmute` here either. --- Cheers, Benno > self.read_raw(out) > } > =20