summaryrefslogtreecommitdiff
path: root/drivers/gpu/nova-core/gsp/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nova-core/gsp/commands.rs')
-rw-r--r--drivers/gpu/nova-core/gsp/commands.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 0425c65b5d6f..8f270eca33be 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -2,7 +2,9 @@
use core::{
array,
- convert::Infallible, //
+ convert::Infallible,
+ ffi::FromBytesUntilNulError,
+ str::Utf8Error, //
};
use kernel::{
@@ -30,7 +32,6 @@ use crate::{
},
},
sbuffer::SBufferIter,
- util,
};
/// The `GspSetSystemInfo` command.
@@ -142,7 +143,7 @@ impl CommandToGsp for SetRegistry {
}
/// Message type for GSP initialization done notification.
-struct GspInitDone {}
+struct GspInitDone;
// SAFETY: `GspInitDone` is a zero-sized type with no bytes, therefore it
// trivially has no uninitialized bytes.
@@ -151,13 +152,13 @@ unsafe impl FromBytes for GspInitDone {}
impl MessageFromGsp for GspInitDone {
const FUNCTION: MsgFunction = MsgFunction::GspInitDone;
type InitError = Infallible;
- type Message = GspInitDone;
+ type Message = ();
fn read(
_msg: &Self::Message,
_sbuffer: &mut SBufferIter<array::IntoIter<&[u8], 2>>,
) -> Result<Self, Self::InitError> {
- Ok(GspInitDone {})
+ Ok(GspInitDone)
}
}
@@ -205,11 +206,27 @@ impl MessageFromGsp for GetGspStaticInfoReply {
}
}
+/// Error type for [`GetGspStaticInfoReply::gpu_name`].
+#[derive(Debug)]
+pub(crate) enum GpuNameError {
+ /// The GPU name string does not contain a null terminator.
+ NoNullTerminator(FromBytesUntilNulError),
+
+ /// The GPU name string contains invalid UTF-8.
+ #[expect(dead_code)]
+ InvalidUtf8(Utf8Error),
+}
+
impl GetGspStaticInfoReply {
- /// Returns the name of the GPU as a string, or `None` if the string given by the GSP was
- /// invalid.
- pub(crate) fn gpu_name(&self) -> Option<&str> {
- util::str_from_null_terminated(&self.gpu_name)
+ /// Returns the name of the GPU as a string.
+ ///
+ /// Returns an error if the string given by the GSP does not contain a null terminator or
+ /// contains invalid UTF-8.
+ pub(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
+ CStr::from_bytes_until_nul(&self.gpu_name)
+ .map_err(GpuNameError::NoNullTerminator)?
+ .to_str()
+ .map_err(GpuNameError::InvalidUtf8)
}
}