diff --git a/drivers/acpid/src/acpi.rs b/drivers/acpid/src/acpi.rs index cc061d8661..94a1eb17ec 100644 --- a/drivers/acpid/src/acpi.rs +++ b/drivers/acpid/src/acpi.rs @@ -279,7 +279,7 @@ impl AmlSymbols { pub fn aml_context_mut( &mut self, pci_fd: Option<&libredox::Fd>, - ) -> &mut Interpreter { + ) -> Result<&mut Interpreter, AmlEvalError> { if self.aml_context.is_none() { match self.init(pci_fd) { Ok(()) => (), @@ -290,7 +290,7 @@ impl AmlSymbols { } self.aml_context .as_mut() - .expect("AML context not initialized") + .ok_or(AmlEvalError::NotInitialized) } pub fn symbols_cache(&self) -> &FxHashMap { @@ -306,7 +306,9 @@ impl AmlSymbols { } pub fn build_cache(&mut self, pci_fd: Option<&libredox::Fd>) { - let aml_context = self.aml_context_mut(pci_fd); + let Ok(aml_context) = self.aml_context_mut(pci_fd) else { + return; + }; let mut symbol_list: Vec<(AmlName, String)> = Vec::with_capacity(5000); @@ -364,6 +366,8 @@ pub enum AmlEvalError { SerializationError, #[error("Failed to deserialize")] DeserializationError, + #[error("AML not initialized")] + NotInitialized, } impl From for AmlEvalError { fn from(value: AmlError) -> Self { @@ -393,7 +397,7 @@ impl AcpiContext { args: Vec, ) -> Result { let mut symbols = self.aml_symbols.write(); - let interpreter = symbols.aml_context_mut(None); + let interpreter = symbols.aml_context_mut(None)?; interpreter.acquire_global_lock(16)?; let args = args