Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp151401pxb; Mon, 13 Sep 2021 15:36:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg03ZOJ669AqzkDDsSqZ7isU1HOcMt4qicXdI/iB817gEYrqdl3t4Di7842MacrMhwkgxb X-Received: by 2002:a92:c744:: with SMTP id y4mr9352411ilp.288.1631572602182; Mon, 13 Sep 2021 15:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631572602; cv=none; d=google.com; s=arc-20160816; b=c6mfZogEKI2uvafMtCp/BdhbcLBX7708pe+ME4mROA658x36x7V0XOZRDbt5eB21Ml HimKykRrpuB7A4V3PI4d44m/KMHoueIaGGwg+qXcC/tYDEbwK0RrTBXaNArxa6VcpU3N pa+RfdOeoXIhKDOHHSIBJ9czw/Z8O6n2sdgjdeLTGSItw7kGxi78nlKNeGymma/VCOF2 sKotvFIJkRhbW3ur2AW2YVa1l9j+kHdU+EPwYo7bIPiJJJHFTBC/atWrqsQ2FKAabE0W zU/jos6qhRv4YQm9MUpr8M7lI4v/2KQW2Wqmr2aFKXQdNtEbd0zAcLJ/YM0+PBN12Ftc YTrg== 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=6iSRetTLKPxwXYarYcDtn/nxPYEOHS3Zz10nmBmdg34=; b=bMLRJHhEoey+aV81UGa/xU7PFrB0TKXqBJKkvu8DNiaYCDhXiembOLJi7MVXQCH5cW W41XaFuWmnQq12Mgp+7g4gqN0EVKzjQwA5XnC2G8jkylwEs9LhzBxFFC5UdBxa91Ls42 NRUplWZCAOhJMTlj95D85IqmFXn05GT8WMoXqZEtjayOd+gC8JOp+a1DATcDPOoTHwm9 D9mWOySNpYdty8nhPGbGeqxdSoMrWU68o/1PNpvZxwSUN+QZjPki0ZVxaX7FsF/wNarc b18O/XbkyWpo3EG/X7w+rGhSA1BxOiW1p0uy5wpXSLxTjtj8+pQ1sckFGMuM8OeAF9A8 UIvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L4wNMIG6; 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 f5si8704579ils.71.2021.09.13.15.36.30; Mon, 13 Sep 2021 15:36:42 -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=L4wNMIG6; 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 S1343492AbhIMOKk (ORCPT + 99 others); Mon, 13 Sep 2021 10:10:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:56012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245547AbhIMOHT (ORCPT ); Mon, 13 Sep 2021 10:07:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1FBFC61A62; Mon, 13 Sep 2021 13:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540435; bh=3ZSUj1LA8Z84TYLE66l9aqUSUuAjgFmY1u7tOR0uqs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L4wNMIG6ny6Fs5p1FB9pw477wezwqzVUuANDKC2AsLKKXV2alBC7U29y0hrwNRcFf TJCt7Iz0uHWX3gWgeNpeobRxuTpxbcN2KhLWtNPaF39TJRqR3XWbl6NOTPu/JRTPgP nVtp3rttcrHkd/TTNHpvTczawbUWYNKXnmCAHTK8= 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.13 191/300] Bluetooth: Move shutdown callback before flushing tx and rx queue Date: Mon, 13 Sep 2021 15:14:12 +0200 Message-Id: <20210913131115.834737393@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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 ee59d1c7f1f6..7154af1fad81 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1734,6 +1734,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