Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp85924ybb; Thu, 19 Mar 2020 17:08:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs+Q3/kFSt7Ehy9Um1TJKVBOx6HmyD5gEhYKz+ZEwg43KzlWNefZex8mhCj/e39kEQWVmym X-Received: by 2002:aca:57cd:: with SMTP id l196mr4495156oib.1.1584662889093; Thu, 19 Mar 2020 17:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584662889; cv=none; d=google.com; s=arc-20160816; b=wT1H74AWmwXGIFwK9wBXQtfgHUoLC7HqnWBSbTnpvHtVEcgAUGwiLQUZ3d7BWYRQUC O3hTw/4A0AqA+aoGgIUDE8VyJMYzNp5e6/WwcHNw/ibcx+/StI5fuOsxelIvdOKyzWb/ pb0FySjHO7CD32H8efQ9nrlOJv/MXPucNkwVkThrc8AFqUhh/tbhqxyPA7UqUsUGuShU G7W74iZwXhkUQDrt46oVXxjLVFkeCEurqqX1yWYb7hN9fOJ3mXMKAJwHz7ORJEGpcDzP G0hJ7lkuGmRMKABQqX5jJqWOOvOGmvdzxTyK761921rh39STFefkGlfzlB8TGFISFD1k NeYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PQXtrFBK0FlZQNQPvUALv+UR85FSVb3kUvsKXL/U5Nc=; b=O39A8n71lUmlD3gWrJGbY1O6eqqgP5cQlhkLS1Z5uW39Jld9KhR0slHy30OTGiBFmi tB0Zk97XTjzfMpnqN0yDO5ZvEfvX6RD95K0r7HV+TNzxp3UDL5BdRuN9Tur3AXhx5pfH ttV9eGkziRpdnsejdyteysJ16l11igdrk/di2n/wTBjEy4ifNh8Y8Jjvj/+ASlvI/3V7 EKRlyEtVSRSOMe5yzss8HbSRSYw8WiqM/yDCLJq8zyRBxyHoiZzfm4VIvUf/99DmOx46 af5xyy786I2H6g/aT29QZgUIvYqkfvQvd72Hpk6XX+Y2PeOyQV3pExKLyYYBiiczhnEM y1ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TEvD6Q64; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si1795572oii.195.2020.03.19.17.07.37; Thu, 19 Mar 2020 17:08:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TEvD6Q64; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727298AbgCTAHb (ORCPT + 99 others); Thu, 19 Mar 2020 20:07:31 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:33239 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726827AbgCTAHb (ORCPT ); Thu, 19 Mar 2020 20:07:31 -0400 Received: by mail-pf1-f194.google.com with SMTP id n7so2321548pfn.0 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=CYl2nLLKnjZIA3DvM+eDKm+hlCnGuN7h2XpmOslq1MATGt30Pe0wAYevhUyn/Gusf3 ZhK0OCPQiim+q3/6Tz+x/1QykJJa7eTcTAB+2Eb9hnJdr3qy4FQ9AQ3FlpGXg3FOY10Z 19wPLb0iQYuu2X/6lqMfuCJraQBSvZEWtDkjdfrVcLgURmv/Gzrv0MlkJnboJ7nwz9zO bZmgAFHERqrEKjwpN+1Ccru5b2w4FHIRdO1ZjeVRwWhBXd7rzIclsGQM/WeW8HC1/Yb9 3CptgcVLAO67zgjjqoOoiskM5iHzllNzcRA0bm/fyDkZ34huyVLVOthaDLb9OnHfozpV nDWw== X-Gm-Message-State: ANhLgQ0nQstKkYDb7eeB9a3r/82MLrabMHRKXdK4MFCcqSZKlcAAIlzK tLu9rLtOLzlFjKbBVYUoMJEGeQ== 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 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@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) { -- 2.25.1.696.g5e7596f4ac-goog