Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3699578pxk; Tue, 29 Sep 2020 04:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3n69eOPc0ilNp5XzMQMbrXpvUaZ67MbqReWwshx9GZf/O0bVZuAKHh+GHAv9rEXKoZrLJ X-Received: by 2002:aa7:dcd9:: with SMTP id w25mr2489500edu.280.1601377783804; Tue, 29 Sep 2020 04:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601377783; cv=none; d=google.com; s=arc-20160816; b=t6Z/y2AFNvsuadgJeB7u2hSbNO/3FxEPupctjkSUaT/7Ts1zMojtFv5hMC95L1N5uL nrozToxO7VeMLfMQz0ek9j0wXIYGstn8olh7bBpLayoOtbyO5Crfk5rLPXAWE1rfrxq7 sxv87+rJaTjVMrYVuee7pYTkvwvXg9iqJ6QhDGx0/6G5k77Q1tGmFHdudIwV5x9FVXdN wbAL4vwOnyf6kfHXdQTTkYuGriCMXWuaQsYv9tJxHdTpITYE2tMPElvOqFLDMIDad+Ew HZxzfw/c4cpmsj3NBmiZ6BuSSXhOMXhofWqV+y7xvrEGddHK/+mUwgJb/fdzssNK2hpO pJ0w== 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=Qj7G1TJkpJdkwgb93fb8H/H1ZXfLD01Ve0xzUNY4KKA=; b=DI0AEgQCzdXuzDZOcUYXlTsQwXqK7QT1uo8scuguo9CC7aVyGMDZKjnAhvJ/Z/Fus0 iHfLROGwx7BhUVIRYEyhPi1qW7TFOj/m+JTwJoKk8dzS+/Eg3YxFN2MOtk0kL66X2Tv0 Lpvtk+TCkEAbJLcrUV7M/1OLBpJpqj2sh7toHaNFbynG+ZMmyhxMNPRDSWAWZGfHvuUZ J1mNrBlLKTyenhndsWduHphju9VLGJcs/WioN/+0yRp/BAx65JaplFpxfYMigZLk96Fo tZHQkSydQGH61ztr7BdQDCkRsxhyEx83tnkXXUvUtejMGPgiIJndBRUcSTuN+swKfxj/ LJIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FMQQYE+n; 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=fail (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 da1si2475106edb.102.2020.09.29.04.09.21; Tue, 29 Sep 2020 04:09:43 -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=@kernel.org header.s=default header.b=FMQQYE+n; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728731AbgI2LFZ (ORCPT + 99 others); Tue, 29 Sep 2020 07:05:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:41362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728684AbgI2LFD (ORCPT ); Tue, 29 Sep 2020 07:05:03 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5081A21924; Tue, 29 Sep 2020 11:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377503; bh=+rbdhmB+nELvAR5PBIrLE6yII0u3D4M+5+DERJ6SAOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FMQQYE+nrZCzJtE+XrWuMyFzeJVUsFkr53afgbaWjHEmUq+Ip1VQLreHUYuMhg4fm cu4ZEuceyEPwshkw+gCMFJWHE01Z7RmUW1o55XJpSA16YGRf+FI6zZ+0SRJWzdEITe QYv7cU8GPnv5evJjbG2oZte1aftoPPz/ollz6yHQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sonny Sasaka , Marcel Holtmann , Sasha Levin Subject: [PATCH 4.4 57/85] Bluetooth: Handle Inquiry Cancel error after Inquiry Complete Date: Tue, 29 Sep 2020 13:00:24 +0200 Message-Id: <20200929105931.067294717@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105928.198942536@linuxfoundation.org> References: <20200929105928.198942536@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: Sonny Sasaka [ Upstream commit adf1d6926444029396861413aba8a0f2a805742a ] After sending Inquiry Cancel command to the controller, it is possible that Inquiry Complete event comes before Inquiry Cancel command complete event. In this case the Inquiry Cancel command will have status of Command Disallowed since there is no Inquiry session to be cancelled. This case should not be treated as error, otherwise we can reach an inconsistent state. Example of a btmon trace when this happened: < HCI Command: Inquiry Cancel (0x01|0x0002) plen 0 > HCI Event: Inquiry Complete (0x01) plen 1 Status: Success (0x00) > HCI Event: Command Complete (0x0e) plen 4 Inquiry Cancel (0x01|0x0002) ncmd 1 Status: Command Disallowed (0x0c) Signed-off-by: Sonny Sasaka Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_event.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 04c77747a768d..03319ab8a7c6e 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -41,12 +41,27 @@ /* Handle HCI Event packets */ -static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb) +static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb, + u8 *new_status) { __u8 status = *((__u8 *) skb->data); BT_DBG("%s status 0x%2.2x", hdev->name, status); + /* It is possible that we receive Inquiry Complete event right + * before we receive Inquiry Cancel Command Complete event, in + * which case the latter event should have status of Command + * Disallowed (0x0c). This should not be treated as error, since + * we actually achieve what Inquiry Cancel wants to achieve, + * which is to end the last Inquiry session. + */ + if (status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { + bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command"); + status = 0x00; + } + + *new_status = status; + if (status) return; @@ -2758,7 +2773,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, switch (*opcode) { case HCI_OP_INQUIRY_CANCEL: - hci_cc_inquiry_cancel(hdev, skb); + hci_cc_inquiry_cancel(hdev, skb, status); break; case HCI_OP_PERIODIC_INQ: -- 2.25.1