Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319153pxb; Mon, 20 Sep 2021 18:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGuPgCLskBx2Ac6sQxAZhKF2eGGUF5ql6QWH/w66o7kYBgucXD/tv1ZPQopD5HkBFuYLjz X-Received: by 2002:a05:6e02:1562:: with SMTP id k2mr4969343ilu.263.1632188522205; Mon, 20 Sep 2021 18:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188522; cv=none; d=google.com; s=arc-20160816; b=s0QbsOBcnFTn9XElJSmzsSWrplJrbANqVlE/yZ9nVyfE2OY56XnQRcfGoaeVf+0krO pv1/xbWPR6vEHOUAZ5j6ptI9ewSzAjnI0aqjhMdHiJSHdgsvRaDdKPRa9szxjJB6T1Kc Sd96wZhneOiViOpnbJei/F897Y0Ou/Ixdfi/AUs/7cmgN8hqlnJnwSXuBroKAAPkyEP5 V5lpi5XbWj8DlR6X51UxRWnReAhm98wXLSrNNwAeX1HiZy+cDU3kbbiKK2JzqHBHTw7e F7fdeDoxMR7gEZEkXb2bHsXQWn0X0k8llhBnzHQFeYUx/DEeEZuxnlh2BORmqK0JDErz eJlg== 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=lWvy0zfdqtcP4xCv0mrDbyKgib8DIRY7qg9mJdD4DK0=; b=DBmid9P5d/NLkUMKsl6siLmL00AqyVg/cLo1VENiF+QwxBCiGFqxBfzJEKfV59k9zs qAw//woPpFB99dOPj/UeC6qeIehWXVGK5QRgH13ZXPXz02YC7MC5pgul1wQC+6N0BqqK iHPkAKJSNsBkJ8/ReVgIUBeJRtUzkiyZYYiT8A+QH9YmlxgWoTY0NzjKC0usHokgwG2/ yBo8dwd1l4gvgz6AYSg7+gOKFg+tB36mPPuYKHSsuvzrlCLy1vrj/iqhmXoagnggkUBl ziCM+dL6BjdhYKuUgHwpgvTGWzOdgMiz8HDctxECviNGnYwGFmWLROU5oTXQjBNv3Bvk v5dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KrZVIzEz; 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 l17si2011629ilt.1.2021.09.20.18.41.50; Mon, 20 Sep 2021 18:42:02 -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=KrZVIzEz; 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 S243759AbhITQvf (ORCPT + 99 others); Mon, 20 Sep 2021 12:51:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:37284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243369AbhITQsf (ORCPT ); Mon, 20 Sep 2021 12:48:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6BEB61244; Mon, 20 Sep 2021 16:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156428; bh=VxJEmnn+dozpsenHvujRYCWutCoXWG37VuCpXSfThXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KrZVIzEzYY40TOvFyxRjQzsYwFdN3HBxBYlKT57+hdvPVPEA5m2By/fh76cGDVlqQ 2o1KXVX6u+GyfPkaAKS5zqCIf5slgILmQ2zT3zVuwSTYvCKPPwJ0VqA7Uh1gT4lldD MYpZlvNhOSbL4eElnXYtUdIhS2E0hsn5mrYrnTf4= 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 4.4 053/133] Bluetooth: Move shutdown callback before flushing tx and rx queue Date: Mon, 20 Sep 2021 18:42:11 +0200 Message-Id: <20210920163914.380474897@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 304abf2af9f3..bf69bfd0b475 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1679,6 +1679,14 @@ int hci_dev_do_close(struct hci_dev *hdev) hci_req_cancel(hdev, ENODEV); hci_req_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_unlock(hdev); -- 2.30.2