Signed-off-by: Rhys Lloyd <[email protected]>
---
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);
}
--
2.50.1