From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Quaternions" <krakow20@gmail.com>
Cc: <rust-for-linux@vger.kernel.org>,
"Joel Fernandes" <joelagnelf@nvidia.com>
Subject: Re: [PATCH] gpu: nova-core: define named constants for magic numbers
Date: Fri, 11 Jul 2025 21:18:04 +0900 [thread overview]
Message-ID: <DB97X8JAJFI4.3G1I8ZPC1MWLS@nvidia.com> (raw)
In-Reply-To: <20250711113327.39201-2-krakow20@gmail.com>
On Fri Jul 11, 2025 at 8:33 PM JST, Quaternions wrote:
> Signed-off-by: Rhys Lloyd <krakow20@gmail.com>
> ---
> drivers/gpu/nova-core/vbios.rs | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
> index 5b5d9f38cbb3..d456c494374d 100644
> --- a/drivers/gpu/nova-core/vbios.rs
> +++ b/drivers/gpu/nova-core/vbios.rs
> @@ -364,8 +364,9 @@ struct BitHeader {
> }
>
> impl BitHeader {
> + const MIN_LEN: usize = 12;
> fn new(data: &[u8]) -> Result<Self> {
> - if data.len() < 12 {
> + if data.len() < Self::MIN_LEN {
> return Err(EINVAL);
> }
Mmm looking at the these functions makes me think that maybe we should
rather:
- Make `BitHeader` (and the other structs affected by this patch)
`#[repr(C)]`,
- Wait until the `FromBytes` patchset lands [1],
- ... and simply implement `FromBytes` on these structures to replace
this code, which is basically a little-endian deserializer. Since Nova
has no plan to run on big-endian targets at the moment, this should
work fine, and removes the need to define constants for the sizes of
these types and use indices that are always error-prone.
Or at the very least, we make these structs `#[repr(C)]` and change the
implementation to be done in terms of `size_of` and `offset_of`, which,
while more verbose, also promises better correctness.
[1] https://lore.kernel.org/rust-for-linux/20250624042802.105623-1-christiansantoslima21@gmail.com/
next prev parent reply other threads:[~2025-07-11 12:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 11:33 [PATCH] gpu: nova-core: fix bounds check In PmuLookupTableEntry::new, data is sliced from 2..6, but the bounds check data.len() < 5 does not satisfy those bounds Quaternions
2025-07-11 11:33 ` [PATCH] gpu: nova-core: define named constants for magic numbers Quaternions
2025-07-11 12:18 ` Alexandre Courbot [this message]
2025-07-14 15:26 ` Joel Fernandes
2025-07-11 11:54 ` [PATCH] gpu: nova-core: fix bounds check In PmuLookupTableEntry::new, data is sliced from 2..6, but the bounds check data.len() < 5 does not satisfy those bounds Greg KH
2025-07-11 12:04 ` Alexandre Courbot
2025-07-11 12:20 ` Alexandre Courbot
2025-07-11 14:32 ` Rhys Lloyd
2025-07-11 14:55 ` Miguel Ojeda
2025-07-11 12:12 ` Miguel Ojeda
-- strict thread matches above, loose matches on Subject: below --
2025-07-13 2:51 [PATCH] gpu: nova-core: fix bounds check in PmuLookupTableEntry::new Rhys Lloyd
2025-07-13 2:51 ` [PATCH] gpu: nova-core: define named constants for magic numbers Rhys Lloyd
2025-07-14 3:11 ` Alexandre Courbot
2025-07-14 6:10 ` Rhys Lloyd
2025-07-11 14:29 [PATCH] gpu: nova-core: fix bounds check in PmuLookupTableEntry::new Rhys Lloyd
2025-07-11 14:29 ` [PATCH] gpu: nova-core: define named constants for magic numbers Rhys Lloyd
2025-07-11 9:30 [PATCH] gpu: nova-core: fix bounds check In PmuLookupTableEntry::new, data is sliced from 2..6, but the bounds check data.len() < 5 does not satisfy those bounds Quaternions
2025-07-11 9:30 ` [PATCH] gpu: nova-core: define named constants for magic numbers Quaternions
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DB97X8JAJFI4.3G1I8ZPC1MWLS@nvidia.com \
--to=acourbot@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=krakow20@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.