Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1827233pxb; Mon, 13 Sep 2021 06:26:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5v/d+Z94xE+ipDsdEDPW3tV5vA1hrEyUwBUef6r6j76hBeBNULrCBJfvjXO9abR2dIj9D X-Received: by 2002:a05:6602:22d4:: with SMTP id e20mr8962204ioe.203.1631539592560; Mon, 13 Sep 2021 06:26:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631539592; cv=none; d=google.com; s=arc-20160816; b=z6KvRP+7tNRt+rrcV0NllD00eWWTNvtys4lu5iRyBIj+4Mrsgtlj0Val/VYzTaUy85 Haj+D3rooMKE2DACxvjn+x+9ap8dtlhAp/xbxKcYpGvyATFfbljlHNjQw6erMXT/SH08 sjIJsbTcqQb8hhCUobiGJ6uIOw5UOW8834kxfkQBa9vMxh40KSEPVzD5OGWg6YVv2C35 6i/yj4XrPR6AN2liOr1AGFAw1ZG5j5vQ1GpAuC3VV6v1YVKAj/VPI9qcLKuLhM+S/TTX QacRvIOtjfHqkZGaOfgL1Cyt9vZe7EKZmWzSAc1iufpypVwJPa2kPDcXQak9ArpMcY4S I83w== 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=l5gmS3vaK4+N3nsbzgD9763g4Mh3SzHGDMeJ4bWDKn4=; b=ibjBTeIWKAJVWoRJn3QtwJHJkjB+vECW13hSd0ltV9VKJp8PY/BdQ8Sc3Z3RavehdD k4/BMH2gO/fmsDCKOLoROcW7r/8exN3B2+BGZF4cTghEt2szALhuTjHp/r38tLuzNDu9 Szz/DvRudUKwtgHv5kuNIQ1HgD73oAEd+/rP/VtJjjqwtnLe4hTtCGCYdf+LQo9Bxl5w WqD+MsYN4BqxjrIyEiKd4bS5SFvwZYc1wCRC8e+0v3TMuaNz2dzrSywsQ83dgAfMpXAI LpsRcQ2DVaGgNuRDahE8tffOVxEWofu87V/VuekbUHHTLPvQV591Im3tey4k7thcrgKo 7SqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WrgtDJGr; 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 h5si1385198jar.102.2021.09.13.06.26.19; Mon, 13 Sep 2021 06:26:32 -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=WrgtDJGr; 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 S241096AbhIMN0C (ORCPT + 99 others); Mon, 13 Sep 2021 09:26:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:34848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240553AbhIMNWM (ORCPT ); Mon, 13 Sep 2021 09:22:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 84C80610FE; Mon, 13 Sep 2021 13:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539254; bh=TLIPnckvT8bw1g/n72L45V1ibhUdbVyp7z9fiZkZcVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WrgtDJGr769791laDXS1Q9ER9NcNjq5WJNWWTlbDNy++/VLfyDbSQtDQUOZETqmv7 XP/P0Cs4bXf2fH+ZHvKP+5HsBZdY/bMYi5HKCcWdXphC/TM+NjRqnVbbPRqZR+uadm BhVfS0Xa0KFHAmQQIGSorg1hmG8bP8irgT/GWWXg= 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.4 092/144] Bluetooth: Move shutdown callback before flushing tx and rx queue Date: Mon, 13 Sep 2021 15:14:33 +0200 Message-Id: <20210913131051.026410197@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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 83a07fca9000..4e4972800370 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1685,6 +1685,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