From da5c593141264399396383074008009daed50dc4 Mon Sep 17 00:00:00 2001 From: Katherine Lai Date: Tue, 25 Feb 2025 16:56:35 +0000 Subject: system/gd/hci: Update MSFT to not crash on read feature failure If on_msft_read_supported_features_complete fails, instead of crash, we should log the error and ensure supports_msft_extensions returns false. Bug: 399023445 Test: mmm packages/modules/Bluetooth Flag: Exempt, only affects desktop and floss Change-Id: Ic645d254c7cb9df9ea2df9e4d25f28c88d7a014a --- system/gd/hci/msft.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/system/gd/hci/msft.cc b/system/gd/hci/msft.cc index b27bcf23d5..1c5a700030 100644 --- a/system/gd/hci/msft.cc +++ b/system/gd/hci/msft.cc @@ -56,10 +56,13 @@ struct MsftExtensionManager::impl { * Query the kernel/drivers to derive the MSFT opcode so that * we can issue MSFT vendor specific commands. */ - if (!supports_msft_extensions()) { + uint16_t opcode = hal_->getMsftOpcode(); + if (opcode == 0) { log::info("MSFT extension is not supported."); return; } + msft_.opcode = opcode; + log::info("MSFT opcode 0x{:04x}", msft_.opcode.value()); /* * The vendor prefix is required to distinguish among the vendor events @@ -121,20 +124,7 @@ struct MsftExtensionManager::impl { } } - bool supports_msft_extensions() { - if (msft_.opcode.has_value()) { - return true; - } - - uint16_t opcode = hal_->getMsftOpcode(); - if (opcode == 0) { - return false; - } - - msft_.opcode = opcode; - log::info("MSFT opcode 0x{:04x}", msft_.opcode.value()); - return true; - } + bool supports_msft_extensions() { return msft_.opcode.has_value(); } void msft_adv_monitor_add(const MsftAdvMonitor& monitor, MsftAdvMonitorAddCallback cb) { if (!supports_msft_extensions()) { @@ -225,7 +215,11 @@ struct MsftExtensionManager::impl { log::assert_that(view.IsValid(), "assert failed: view.IsValid()"); auto status_view = MsftReadSupportedFeaturesCommandCompleteView::Create( MsftCommandCompleteView::Create(view)); - log::assert_that(status_view.IsValid(), "assert failed: status_view.IsValid()"); + if (!status_view.IsValid()) { + log::error("MSFT Read supported features failed"); + msft_.opcode = std::nullopt; + return; + } if (status_view.GetStatus() != ErrorCode::SUCCESS) { log::warn("MSFT Command complete status {}", ErrorCodeText(status_view.GetStatus())); -- cgit v1.2.3-59-g8ed1b