From patchwork Fri Mar 20 00:07:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 1258544 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=TEvD6Q64; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48k3xr3Tbqz9sSR for ; Fri, 20 Mar 2020 11:07:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727425AbgCTAHl (ORCPT ); Thu, 19 Mar 2020 20:07:41 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46259 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726827AbgCTAHd (ORCPT ); Thu, 19 Mar 2020 20:07:33 -0400 Received: by mail-pg1-f196.google.com with SMTP id k191so1001461pgc.13 for ; Thu, 19 Mar 2020 17:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PQXtrFBK0FlZQNQPvUALv+UR85FSVb3kUvsKXL/U5Nc=; b=TEvD6Q64qVYmIQlbmaLjnNAY+7OlBcvgfXNGmoM8H/sSiTi7kDeL1NdArsDpd6XdQP UopKYZ+HGb4EiFgFJNZUtac5kGMrZRQpz/m4OuxcwNtKFmoTQbeDusSuIIgC+Gpg1MUt +3+VGvMUj5tfzJ/QcW1KuKU/1IEDdJdPTfRQM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PQXtrFBK0FlZQNQPvUALv+UR85FSVb3kUvsKXL/U5Nc=; b=e+bkJxIJc0nvjtsNRZ6puW84tWu8PYyaUmzUjvfPL7s+Q8IApglRFZ6i1GthdsToWA 0xQH2Me960eNT8EWDvhFkaHQ/H4er3t8yyNPdhe4dKMMDkb/EA5rH4kWKp8MvIjpseGn DSoxcsLW1l/7vG98je2y7cQbs39jJm+RnTwaYhbXq3/WZEkdBszLobqEynS38cdo+SZc pLFTORu+sfWQimX++qi41xfWO14NCOv6V817cuyzlEf+BRcgDwZU1vS1K7S/Oh+RrLsn yaHLykyvhUd47H/cU6dTyz03Q8mQ70TnFCJccV2XUdXiChPdAJweDCAe7G7OWMPHDsVP +XBQ== X-Gm-Message-State: ANhLgQ2TJfz5s6ReERocEo63JuSqou5eu1AYTKbLkZH/2MUPEH2asTmI Y1k+JyDhru3o+bNj0hQYHFKlqA== X-Google-Smtp-Source: ADFU+vtOCz6ZIdxB66p7W+0Ice1rjK2QrirMgDN1ixu5hAnGyJU2ZhDTWPnn8LAZR5Dj63+UeS+nxw== X-Received: by 2002:aa7:86ce:: with SMTP id h14mr6580091pfo.311.1584662850242; Thu, 19 Mar 2020 17:07:30 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id m12sm2928292pjf.25.2020.03.19.17.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 17:07:29 -0700 (PDT) From: Abhishek Pandit-Subedi To: marcel@holtmann.org, linux-bluetooth@vger.kernel.org Cc: chromeos-bluetooth-upstreaming@chromium.org, Abhishek Pandit-Subedi , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH 1/2] Bluetooth: Restore running state if suspend fails Date: Thu, 19 Mar 2020 17:07:12 -0700 Message-Id: <20200319170708.1.I83970586f8340022b3909dccac1d79d191c6c70a@changeid> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog In-Reply-To: <20200320000713.32899-1-abhishekpandit@chromium.org> References: <20200320000713.32899-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If Bluetooth fails to enter the suspended state correctly, restore the state to running (re-enabling scans). PM_POST_SUSPEND is only sent to notifiers that successfully return from PM_PREPARE_SUSPEND notification so we should recover gracefully if it fails. Signed-off-by: Abhishek Pandit-Subedi --- net/bluetooth/hci_core.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dbd2ad3a26ed..2e7bc2da8371 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3305,6 +3305,15 @@ static void hci_prepare_suspend(struct work_struct *work) hci_dev_unlock(hdev); } +static int hci_change_suspend_state(struct hci_dev *hdev, + enum suspended_state next) +{ + hdev->suspend_state_next = next; + set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); + queue_work(hdev->req_workqueue, &hdev->suspend_prepare); + return hci_suspend_wait_event(hdev); +} + static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -3330,32 +3339,24 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, * connectable (disabling scanning) * - Second, program event filter/whitelist and enable scan */ - hdev->suspend_state_next = BT_SUSPEND_DISCONNECT; - set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); - queue_work(hdev->req_workqueue, &hdev->suspend_prepare); - ret = hci_suspend_wait_event(hdev); + ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT); - /* If the disconnect portion failed, don't attempt to complete - * by configuring the whitelist. The suspend notifier will - * follow a cancelled suspend with a PM_POST_SUSPEND - * notification. - */ - if (!ret) { - hdev->suspend_state_next = BT_SUSPEND_COMPLETE; - set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); - queue_work(hdev->req_workqueue, &hdev->suspend_prepare); - ret = hci_suspend_wait_event(hdev); - } + /* Only configure whitelist if disconnect succeeded */ + if (!ret) + ret = hci_change_suspend_state(hdev, + BT_SUSPEND_COMPLETE); } else if (action == PM_POST_SUSPEND) { - hdev->suspend_state_next = BT_RUNNING; - set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); - queue_work(hdev->req_workqueue, &hdev->suspend_prepare); - ret = hci_suspend_wait_event(hdev); + ret = hci_change_suspend_state(hdev, BT_RUNNING); } + /* If suspend failed, restore it to running */ + if (ret && action == PM_SUSPEND_PREPARE) + hci_change_suspend_state(hdev, BT_RUNNING); + done: return ret ? notifier_from_errno(-EBUSY) : NOTIFY_STOP; } + /* Alloc HCI device */ struct hci_dev *hci_alloc_dev(void) { From patchwork Fri Mar 20 00:07:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 1258543 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=U4pH9P4l; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48k3xl6lFJz9sSR for ; Fri, 20 Mar 2020 11:07:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727356AbgCTAHd (ORCPT ); Thu, 19 Mar 2020 20:07:33 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:36362 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727297AbgCTAHc (ORCPT ); Thu, 19 Mar 2020 20:07:32 -0400 Received: by mail-pj1-f68.google.com with SMTP id nu11so1716719pjb.1 for ; Thu, 19 Mar 2020 17:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=acxg8uMg4NFbDr08SQGvm9+PmwMFAk5ItZG8WlsBwhw=; b=U4pH9P4lw7V4TqqJGAC4rzIvCYDIBC4taKiNw5Voc2CjmHjW4dcSzroKQPrU/tO2eT qcpTnDOVDZ+oxU/PyLmsccmdzJ50qp5U6+KNCvmiv5I04k5+vqgG56i1XfP/o2zpDkn+ tkv+FKCH6rSJiCeQj86PLhl5xNyh4cFBuN/zo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=acxg8uMg4NFbDr08SQGvm9+PmwMFAk5ItZG8WlsBwhw=; b=hINyGkVfVHN0DDQI/na36kPjIGM5Yzbe1oBlEXJObv/Kg0ijdZFgOSEjHJuwsPDWBh 2xBtbGUT40St/K7qCSwT1NztyTSm0IOy1ZkiV3xyRZW9yY22SB4r49KBc/lsafPyK4ZN IfH99FNgwrk7TjZOBum+B9UiSoWK7cbZ5snn9demdcF+mBtiCW2lZ2Pdfzo4lne0OMQw p3NFqSkf4fZRaeAeOoBojSFoaYSKar7r5eeIGNgNvKUvjvYX7EMVgACwcRweNH0qWiHY 7hxibVU8jLqnQIG+0nqj+5dnmfSPrAclCe1ITUUaCNwuId3opH4IzuYcB151rVtEAkCV oqkA== X-Gm-Message-State: ANhLgQ2w8pmt9MN0g3+WccuaMBKJ5GkM1ZOyQmFiOM4kJjKwmXrpmNjo AI/zX+LyuwnzziCBpGJ4VVx6Kg== X-Google-Smtp-Source: ADFU+vv/toBfL9yTu+DqZU5VqPE3K2kICxRTYJk9CvoYTLtFLKPYYBMa9YYsnozfeUZtqI5h333lRg== X-Received: by 2002:a17:90a:368f:: with SMTP id t15mr6699247pjb.23.1584662851250; Thu, 19 Mar 2020 17:07:31 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id m12sm2928292pjf.25.2020.03.19.17.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 17:07:30 -0700 (PDT) From: Abhishek Pandit-Subedi To: marcel@holtmann.org, linux-bluetooth@vger.kernel.org Cc: chromeos-bluetooth-upstreaming@chromium.org, Abhishek Pandit-Subedi , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH 2/2] Bluetooth: Fix incorrect branch in connection complete Date: Thu, 19 Mar 2020 17:07:13 -0700 Message-Id: <20200319170708.2.Ibcb4900b4d77c3f1df9e43e4c951bf230d65f12d@changeid> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog In-Reply-To: <20200320000713.32899-1-abhishekpandit@chromium.org> References: <20200320000713.32899-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When handling auto-connected devices, we should execute the rest of the connection complete when it was previously discovered and it is an ACL connection. Signed-off-by: Abhishek Pandit-Subedi --- net/bluetooth/hci_event.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 20408d386268..cd3d7d90029b 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2539,16 +2539,17 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) bt_dev_err(hdev, "no memory for new conn"); goto unlock; } - } - - if (ev->link_type != SCO_LINK) - goto unlock; + } else { + if (ev->link_type != SCO_LINK) + goto unlock; - conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); - if (!conn) - goto unlock; + conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, + &ev->bdaddr); + if (!conn) + goto unlock; - conn->type = SCO_LINK; + conn->type = SCO_LINK; + } } if (!ev->status) {