Skip to content

Commit b28fcb7

Browse files
committed
sev: silence warnings under snp-only feature build
Building with default-features=false, features=["openssl","snp"] (no "sev" feature) triggers five warnings. Fix each at the source. error.rs: "use openssl::error::ErrorStack" on cfg(all(openssl, sev)). firmware/host/types/snp.rs: replace unreachable "_" arms in TcbVersion's Encoder/Decoder. launch/linux/snp.rs: tag legacy "pub struct Init" (KVM_SEV_INIT payload, only consumed via the "sev" feature path) with #[allow(dead_code)] so it compiles cleanly under snp-only. Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
1 parent f408d94 commit b28fcb7

8 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
#[cfg(feature = "openssl")]
3+
#[cfg(all(feature = "openssl", feature = "sev"))]
44
use openssl::error::ErrorStack;
55
use std::{
66
array::TryFromSliceError,

src/firmware/host/types/snp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ impl Encoder<Generation> for TcbVersion {
527527
let buffer = match generation {
528528
Generation::Milan | Generation::Genoa => self.to_legacy_bytes(),
529529
Generation::Turin | Generation::Venice => self.to_turin_bytes(),
530-
_ => {
530+
#[cfg(feature = "sev")]
531+
Generation::Naples | Generation::Rome => {
531532
return Err(std::io::Error::new(
532533
std::io::ErrorKind::Unsupported,
533534
"Unsupported Processor Generation for TCB writing",
@@ -548,7 +549,8 @@ impl Decoder<Generation> for TcbVersion {
548549
Generation::Turin | Generation::Venice => {
549550
Ok(TcbVersion::from_turin_bytes(&reader.read_bytes()?))
550551
}
551-
_ => Err(std::io::Error::new(
552+
#[cfg(feature = "sev")]
553+
Generation::Naples | Generation::Rome => Err(std::io::Error::new(
552554
std::io::ErrorKind::Unsupported,
553555
"Unsupported Processor Generation for TCB parsing",
554556
)),

src/launch/linux/sev.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ use std::{
1111

1212
/// Initialize the SEV platform context.
1313
#[repr(C)]
14+
#[allow(dead_code)]
1415
pub struct Init;
1516

1617
/// Initialize the SEV-ES platform context.
1718
#[repr(C)]
19+
#[allow(dead_code)]
1820
pub struct EsInit;
1921

2022
#[derive(Clone, Copy)]

src/launch/linux/snp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::marker::PhantomData;
99
/// Initialize the SEV-SNP platform in KVM.
1010
#[derive(Default)]
1111
#[repr(C, packed)]
12+
#[allow(dead_code)]
1213
pub struct Init {
1314
/// Reserved space, must be always set to 0 when issuing the ioctl.
1415
flags: u64,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub mod error;
111111
/// Module for Encoding and Decoding types.
112112
pub mod parser;
113113

114+
#[cfg(feature = "sev")]
114115
use crate::parser::Decoder;
115116

116117
#[cfg(all(feature = "sev", feature = "dangerous_hw_tests"))]

src/util/parser_helper/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ mod read_ext;
44

55
mod write_ext;
66

7+
#[allow(unused_imports)]
78
pub(crate) use read_ext::ReadExt;
89

10+
#[allow(unused_imports)]
911
pub(crate) use write_ext::WriteExt;

src/util/parser_helper/read_ext.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::parser::Decoder;
44
use std::io::Read;
55

6+
#[allow(dead_code)]
67
pub trait ReadExt: Read {
78
/// Convenience: read a value with unit params.
89
fn read_bytes<T>(&mut self) -> Result<T, std::io::Error>

src/util/parser_helper/write_ext.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::parser::Encoder;
33
use std::io::Write;
44

5+
#[allow(dead_code)]
56
pub trait WriteExt: Write {
67
/// Write a value using its Encoder implementation and the provided params
78
fn write_bytes<T, P>(&mut self, value: T, params: P) -> Result<(), std::io::Error>

0 commit comments

Comments
 (0)