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 15EF7222575; Sun, 26 Oct 2025 15:40:28 +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=1761493229; cv=none; b=s3aEdlNgWMHoyk9ZbEG6gqeljxdcoL9HDH3NTr/R9dRZFShqVZfu1P/Aulg1H7meqsFX2jvpTKtqvORwQBZqmAzE5d+0QzSbBrlup8AGw8BJWerY1qNw4vXxQFpqTqSPdjcLlOB0beGJ+KsGg2KbxafqSHYkd4u5R49ykoNa1dQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761493229; c=relaxed/simple; bh=Uoe39sFfetOX6jVITj8hHI6x03aa5uDVa6LdEIv4+uU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K3z93SbafdgPLyVKG6DvpHFKR4LaRRBtElCQFS6AafY+KIJd6ylBmogkVAsQDAWr4IVDD9bZocasMgpY2JnWBPN+rP9EsgWVz8JbPuKlR7Lbtp4Tv6lSHsnBhNJkXJVhO4JRe0KlmJAzGcUgaxje8zpmkJKN2QRdGNMd4wK8vjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U+VQTDqk; 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="U+VQTDqk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8CACC4CEE7; Sun, 26 Oct 2025 15:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761493228; bh=Uoe39sFfetOX6jVITj8hHI6x03aa5uDVa6LdEIv4+uU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=U+VQTDqkZ3hzOceFaBFu0AwHhUCsIQnvsZn+DSmOXxUCUhy6qZ1P+7DjoD7Kg62ek oEQaEyUO3EhLSmcT96kuaP3PWUc94qhoOvs8LV1DwWJGMS8BBoVtokSNRXVoowT0uN tvtuuvjyr7N6uRXfsiuxjpHoBjsIsNOjXvOYQqUxztB4J+af1sT/9BO8k669ynyDas GTEUeefeqmzyu764mVNdUZIuWP6d3UWlWoEa6W1R0fGQlTbr2t7L5inp40vWOioeFM qIzZwydw7s+SmgyYxLS0l8lymycdQcnflZJvZpoJEF+co392rFRFBWRmN2qiEbAkFU 7R2uVYEZD1dIA== Message-ID: Date: Sun, 26 Oct 2025 16:40:23 +0100 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 5/7] gpu: nova-core: add extra conversion functions and traits To: Alexandre Courbot Cc: Alice Ryhl , David Airlie , Simona Vetter , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , John Hubbard , Alistair Popple , Joel Fernandes , Timur Tabi , Edwin Peer , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org References: <20251026-nova-as-v1-0-60c78726462d@nvidia.com> <20251026-nova-as-v1-5-60c78726462d@nvidia.com> From: Danilo Krummrich Content-Language: en-US In-Reply-To: <20251026-nova-as-v1-5-60c78726462d@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/26/25 3:39 PM, Alexandre Courbot wrote: > +#[cfg(CONFIG_32BIT)] > +/// Infallibly converts a `usize` to `u32` on 32-bit platforms. > +/// > +/// This conversion is always lossless on 32-bit platforms, where a `usize` is the same size as a > +/// `u32`. > +/// > +/// Prefer this over the `as` keyword to ensure no lossy conversions are performed. > +/// > +/// This is for use from a `const` context. For non `const` use, prefer the [`FromAs`] and > +/// [`IntoAs`] traits. > +pub(crate) const fn usize_as_u32(value: usize) -> u32 { > + kernel::static_assert!(size_of::() >= size_of::()); > + > + value as u32 > +} Given that nova-core depends on CONFIG_64BIT, I assume you added this predicting that we'll move this to the kernel crate. For core code (and maybe other drivers) I think we also want the same thing for signed types, but I think it's also fine to add them when moving things into the kernel crate.