Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp68055pxb; Mon, 13 Sep 2021 13:08:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwtFJa5IlJeTx8+PxUEXK4TzJp99YSo2p/bSgIZkeiFXIrUaLqxOIKz/jHMpbXdUkE77bc X-Received: by 2002:a17:906:9747:: with SMTP id o7mr14733801ejy.486.1631563731281; Mon, 13 Sep 2021 13:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631563731; cv=none; d=google.com; s=arc-20160816; b=XuQrG8aIzFNUVFl3xPRSLj+L+eB7H7EkysLV8EwfBRvvVX1O6yfZBZusPDGABr9uUr sefe0bIj3ECEmAQis6tdmDp/o4XTA3LLo3CPZM1O/rnQrUr4rjoI15LFku8BsWgDVA1+ oy2+kvcP98caecjH0LqmeoEOe+m+abRxzazY+zHqlIWxuG+jAmL0il5o7W3ALKHiPeZf sAnddcQbzaGRpK9icgbjmoApfe1mpe9HJt5FOJAmGkJgmY4aJx7Ion6XsFTWjFOg57eE peHVdhwM+/Cz+2qtxSF164vkecY31B747+casnckMTLwlcgE8YVpX8EH/BiaBCAekolM kNUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ikM562zc6FNk91uFygU2nwJOaiH9f8664v8tocd4bG8=; b=zCOW4D2vwVNNYkk6SOKXuE/CetglMXPRkqAVjRGzKQ5Sgl56lJmsJvQ6IpMoZfwN9U Vzld+crUdolkbx8p4asD+0OxQO7a9zmWXIbpKvGWIu09OR/5Sbxa/LvpLQGHdaqvPL6b r8YafASWXPpBJ3dCWAR6IYqBLCF6IEXtGoBPK3f80z+MClrZ3TSmvtHC0nHZXJf8jafy 4+VZZdyIey5L0nzJZ1UoBD5T4O6GUACa5ZP9kLDpTUZleFFuByS7D8hBL84pRE/FWL4q KSGiXO/nUrH9TWXDx9kJojilN25SgcbZVWuYz8l32MQoZS31g5PO/KJCqk9tXLq+j2KL 8Jng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EKXyeGjB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p31si1199628edb.554.2021.09.13.13.08.28; Mon, 13 Sep 2021 13:08:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EKXyeGjB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242777AbhIMNqf (ORCPT + 99 others); Mon, 13 Sep 2021 09:46:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:41672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242778AbhIMNk7 (ORCPT ); Mon, 13 Sep 2021 09:40:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B1EB4613DA; Mon, 13 Sep 2021 13:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539779; bh=6YPjIHLgP8retQoc9LwTAepczihwHZKA/omS1yLploM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EKXyeGjB3vl8O5Vh9IfGZoYoHknSMyw741WHQ/by6UViA+v7fQM59Wp/LR8aTzfC8 kpgJiG4Uyi8fgDXY2MJTetlMiPHk6NYDZ+aVKB+MF70z26K7FTlaAt5/W7nY8h2Qau OfStCcwVfWi+A/Avyc513gjO6wcStjlDGjuQ53QI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hsin-Yi Wang , Guenter Roeck , Kai-Heng Feng , Marcel Holtmann , Sasha Levin , Mattijs Korpershoek Subject: [PATCH 5.10 157/236] Bluetooth: Move shutdown callback before flushing tx and rx queue Date: Mon, 13 Sep 2021 15:14:22 +0200 Message-Id: <20210913131105.720088593@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai-Heng Feng [ Upstream commit 0ea53674d07fb6db2dd7a7ec2fdc85a12eb246c2 ] Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled") introduced a regression that makes mtkbtsdio driver stops working: [ 36.593956] Bluetooth: hci0: Firmware already downloaded [ 46.814613] Bluetooth: hci0: Execution of wmt command timed out [ 46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110) The shutdown callback depends on the result of hdev->rx_work, so we should call it before flushing rx_work: -> btmtksdio_shutdown() -> mtk_hci_wmt_sync() -> __hci_cmd_send() -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared -> btmtksdio_recv_event() -> hci_recv_frame() -> queue_work(hdev->workqueue, &hdev->rx_work) -> clears BTMTKSDIO_TX_WAIT_VND_EVT So move the shutdown callback before flushing TX/RX queue to resolve the issue. Reported-and-tested-by: Mattijs Korpershoek Tested-by: Hsin-Yi Wang Cc: Guenter Roeck Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled") Signed-off-by: Kai-Heng Feng Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 65d3f5409963..2f1868e426ab 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1726,6 +1726,14 @@ int hci_dev_do_close(struct hci_dev *hdev) hci_request_cancel_all(hdev); hci_req_sync_lock(hdev); + if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && + !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && + test_bit(HCI_UP, &hdev->flags)) { + /* Execute vendor specific shutdown routine */ + if (hdev->shutdown) + hdev->shutdown(hdev); + } + if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { cancel_delayed_work_sync(&hdev->cmd_timer); hci_req_sync_unlock(hdev); -- 2.30.2