bluetooth: Fix device->adapter dependency while releasing discovery

Change d7f95170a1 added a dependency on device
adapter pointer being valid while checking if bluetooth profile is supported by
device.

When adapter object is released, each device holding pointer to adapter being
released is notified to reset that to NULL. Since adapter objects are released
first when discovery object is unreferenced, each device will have adapter
pointer reset before the time device objects are released.

Fix observed crash by examining device adapter pointer. If it is NULL report
that device does not support any bluetooth profile instead of looking at UUIDs
supported by adapter.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/646>
This commit is contained in:
Igor V. Kovalenko 2021-11-05 12:52:17 +03:00 committed by PulseAudio Marge Bot
parent 0c5672390b
commit 1a3ffd4cee

View file

@ -257,6 +257,17 @@ static const char *transport_state_to_string(pa_bluetooth_transport_state_t stat
bool pa_bluetooth_device_supports_profile(const pa_bluetooth_device *device, pa_bluetooth_profile_t profile) {
bool show_hfp, show_hsp, r;
pa_assert(device);
/* While discovery is being released adapters will be removed from devices,
* and there are no profiles to support without adapter.
*/
if (!device->adapter) {
pa_log_debug("Device %s (%s) has no adapter to support profile %s",
device->alias, device->address, pa_bluetooth_profile_to_string(profile));
return false;
}
if (device->enable_hfp_hf) {
show_hfp = pa_hashmap_get(device->uuids, PA_BLUETOOTH_UUID_HFP_HF);
show_hsp = !show_hfp;