From 2b06065bdd577c0043368d6101ca387c438988c2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 7 Jan 2013 21:32:23 -0800 Subject: [PATCH] core: Cancel pending confirm name commands if present Otherwise this will race against the device found event in some cases and lock up the management queue. --- src/adapter.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index c71dedcd2..e9bd981b8 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -3733,6 +3733,23 @@ static void confirm_name(struct btd_adapter *adapter, const bdaddr_t *bdaddr, DBG("hci%d bdaddr %s name_known %u", adapter->dev_id, addr, name_known); + /* + * If the kernel does not answer the confirm name command with + * a command complete or command status in time, this might + * race against another device found event that also requires + * to confirm the name. If there is a pending command, just + * cancel it to be safe here. + */ + if (adapter->confirm_name_id > 0) { + warn("Found pending confirm name for hci%u", adapter->dev_id); + mgmt_cancel(adapter->mgmt, adapter->confirm_name_id); + } + + if (adapter->confirm_name_timeout > 0) { + g_source_remove(adapter->confirm_name_timeout); + adapter->confirm_name_timeout = 0; + } + memset(&cp, 0, sizeof(cp)); bacpy(&cp.addr.bdaddr, bdaddr); cp.addr.type = bdaddr_type; -- 2.47.3