<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/gpu/nova-core/num.rs, branch v6.19.11</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-11-14T11:25:15+00:00</updated>
<entry>
<title>gpu: nova-core: num: add functions to safely convert a const value to a smaller type</title>
<updated>2025-11-14T11:25:15+00:00</updated>
<author>
<name>Alexandre Courbot</name>
<email>acourbot@nvidia.com</email>
</author>
<published>2025-11-10T13:34:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=89605daa1ee0de634d7f2ee6370363cfaa8c9499'/>
<id>urn:sha1:89605daa1ee0de634d7f2ee6370363cfaa8c9499</id>
<content type='text'>
There are times where we need to store a constant value defined as a
larger type (e.g. through a binding) into a smaller type, knowing
that the value will fit. Rust, unfortunately, only provides us with the
`as` operator for that purpose, the use of which is discouraged as it
silently strips data.

Extend the `num` module with functions allowing to perform the
conversion infallibly, at compile time.

Example:

    const FOO_VALUE: u32 = 1;

    // `FOO_VALUE` fits into a `u8`, so the conversion is valid.
    let foo = num::u32_to_u8::&lt;{ FOO_VALUE }&gt;();

We are going to use this feature extensively in Nova.

Reviewed-by: Mikko Perttunen &lt;mperttunen@nvidia.com&gt;
[acourbot@nvidia.com: fix mistake in example pointed out by Mikko.]
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Message-ID: &lt;20251110-gsp_boot-v9-3-8ae4058e3c0e@nvidia.com&gt;
</content>
</entry>
<entry>
<title>gpu: nova-core: replace use of `as` with functions from `num`</title>
<updated>2025-11-07T23:22:45+00:00</updated>
<author>
<name>Alexandre Courbot</name>
<email>acourbot@nvidia.com</email>
</author>
<published>2025-10-27T14:12:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=84e2b401bcc551e7c2e1a995f90cce421bce5bfd'/>
<id>urn:sha1:84e2b401bcc551e7c2e1a995f90cce421bce5bfd</id>
<content type='text'>
Use the newly-introduced `num` module to replace the use of `as`
wherever it is safe to do. This ensures that a given conversion cannot
lose data if its source or destination type ever changes.

Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
[acourbot@nvidia.com: fix merge conflicts after rebase.]
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Message-ID: &lt;20251029-nova-as-v3-5-6a30c7333ad9@nvidia.com&gt;
</content>
</entry>
<entry>
<title>gpu: nova-core: add functions and traits for lossless integer conversions</title>
<updated>2025-11-07T23:22:36+00:00</updated>
<author>
<name>Alexandre Courbot</name>
<email>acourbot@nvidia.com</email>
</author>
<published>2025-10-16T02:55:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5525ac03ca7adec61d39f3fd3a143b5e294bdff7'/>
<id>urn:sha1:5525ac03ca7adec61d39f3fd3a143b5e294bdff7</id>
<content type='text'>
The core library's `From` implementations do not cover conversions
that are not portable or future-proof. For instance, even though it is
safe today, `From&lt;usize&gt;` is not implemented for `u64` because of the
possibility to support larger-than-64bit architectures in the future.

However, the kernel supports a narrower set of architectures, and in the
case of Nova we only support 64-bit. This makes it helpful and desirable
to provide more infallible conversions, lest we need to rely on the `as`
keyword and carry the risk of silently losing data.

Thus, introduce a new module `num` that provides safe const functions
performing more conversions allowed by the build target, as well as
`FromSafeCast` and `IntoSafeCast` traits that are just extensions of
`From` and `Into` to conversions that are known to be lossless.

Suggested-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/rust-for-linux/DDK4KADWJHMG.1FUPL3SDR26XF@kernel.org/
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
[acourbot@nvidia.com: fix merge conflicts after rebase.]
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Message-ID: &lt;20251029-nova-as-v3-4-6a30c7333ad9@nvidia.com&gt;
</content>
</entry>
</feed>
