// Obtain and display basic GPU information.
let info = commands::get_gsp_info(&mut self.cmdq, bar)?;
- dev_info!(
- pdev.as_ref(),
- "GPU name: {}\n",
- info.gpu_name().unwrap_or("invalid GPU name")
- );
+ match info.gpu_name() {
+ Ok(name) => dev_info!(pdev.as_ref(), "GPU name: {}\n", name),
+ Err(e) => dev_warn!(pdev.as_ref(), "GPU name unavailable: {:?}\n", e),
+ }
Ok(())
}
use core::{
array,
- convert::Infallible, //
+ convert::Infallible,
+ ffi::FromBytesUntilNulError,
+ str::Utf8Error, //
};
use kernel::{
}
}
+/// 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> {
+ /// 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)
- .ok()
- .and_then(|cstr| cstr.to_str().ok())
+ .map_err(GpuNameError::NoNullTerminator)?
+ .to_str()
+ .map_err(GpuNameError::InvalidUtf8)
}
}