From: Rhys Lloyd <krakow20@gmail.com>
To: dakr@kernel.org, acourbot@nvidia.com
Cc: airlied@gmail.com, simona@ffwll.ch,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Rhys Lloyd <krakow20@gmail.com>
Subject: [PATCH] gpu: nova-core: define named constants for magic numbers
Date: Sat, 12 Jul 2025 19:51:10 -0700 [thread overview]
Message-ID: <20250713025108.9364-4-krakow20@gmail.com> (raw)
In-Reply-To: <20250713025108.9364-2-krakow20@gmail.com>
Introduce an associated constant `MIN_LEN` for each struct that checks
the length of the input data in its constructor against a magic number.
Signed-off-by: Rhys Lloyd <krakow20@gmail.com>
---
Changes in v2:
- Add commit description
- Fix author to match SoB
- Add base commit
---
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);
}
@@ -467,8 +468,9 @@ struct PciRomHeader {
}
impl PciRomHeader {
+ const MIN_LEN: usize = 26;
fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> {
- if data.len() < 26 {
+ if data.len() < Self::MIN_LEN {
// Need at least 26 bytes to read pciDataStrucPtr and sizeOfBlock.
return Err(EINVAL);
}
@@ -772,10 +774,11 @@ fn into_image(self) -> Result<BiosImage> {
BiosImage::try_from(self)
}
+ const MIN_LEN: usize = 26;
/// Creates a new BiosImageBase from raw byte data.
fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> {
// Ensure we have enough data for the ROM header.
- if data.len() < 26 {
+ if data.len() < Self::MIN_LEN {
dev_err!(pdev.as_ref(), "Not enough data for ROM header\n");
return Err(EINVAL);
}
@@ -900,8 +903,9 @@ struct PmuLookupTableEntry {
}
impl PmuLookupTableEntry {
+ const MIN_LEN: usize = 6;
fn new(data: &[u8]) -> Result<Self> {
- if data.len() < 6 {
+ if data.len() < Self::MIN_LEN {
return Err(EINVAL);
}
@@ -928,8 +932,9 @@ struct PmuLookupTable {
}
impl PmuLookupTable {
+ const MIN_LEN: usize = 4;
fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> {
- if data.len() < 4 {
+ if data.len() < Self::MIN_LEN {
return Err(EINVAL);
}
base-commit: 215a3f91713383a3c0d2da82d223a608a3c17ac1
prerequisite-patch-id: d80f92d314a0693d4c89ffb7810d9ab6990336fa
--
2.50.1
next prev parent reply other threads:[~2025-07-13 2:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-13 2:51 [PATCH] gpu: nova-core: fix bounds check in PmuLookupTableEntry::new Rhys Lloyd
2025-07-13 2:51 ` Rhys Lloyd [this message]
2025-07-14 3:11 ` [PATCH] gpu: nova-core: define named constants for magic numbers Alexandre Courbot
2025-07-14 6:10 ` Rhys Lloyd
2025-07-14 3:06 ` [PATCH] gpu: nova-core: fix bounds check in PmuLookupTableEntry::new Alexandre Courbot
2025-07-17 5:15 ` Alexandre Courbot
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=20250713025108.9364-4-krakow20@gmail.com \
--to=krakow20@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®