From patchwork Wed Oct 19 08:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp212800wrs; Wed, 19 Oct 2022 02:08:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6vr2cpvJKbqVjBsp2fW/v35Y0tvL2NZPd1FLBRtLHXA0gM43/DZubOHRRildNFt0MsYcUZ X-Received: by 2002:a17:907:9627:b0:78d:a7d8:9407 with SMTP id gb39-20020a170907962700b0078da7d89407mr5794749ejc.675.1666170498828; Wed, 19 Oct 2022 02:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170498; cv=none; d=google.com; s=arc-20160816; b=iFj+uANVuKqCWl5ZCcPqkmMxe2rDsBO4FgFOxaVhNfOd4DznYpuAwMRS1qzeK3cUWq gqS8OWS/ZTcHHtQ2gqaQ5YJSXDHB28o5WlkPhqOrwmO/gkmW66jU8B+Ex449INnakn19 n4vxXo8CrJAyWI7p6grGvv3N410oSmLU1VScnN0x03/8zI7XQOinWW8PjQVmxEqVZUmW XjTarCLrmMbW/9vLuHQQgBryV4a9fkirlXuJcuMza2WAVjopeVjREOIrFNWYAMZypIQ1 8lIYVHkJijhk3cEAsueQ1MZHE0LKYOpbRzUh6DC9cD6hL1O/m5wJay8i2N53xToroByY bdhg== 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=eyx9WKEv31raS08rAveujdoUmiyFckZaJZ2yYS0B0r4=; b=EALChzDGGjGCOIfR/gME/zrRpVefyggdn33Ey7Ks0zPznKjjGssHdiaHeKWjfqZ4QX 5184R7vMqOq3EbSjbpY2MyiUcYZM++LUNN18b8lYUrOpi6eC9sqJh719qcZRs2ifqRfL KZzdkriem3nNa0i4WBTmE9Mu5bOyaMKHycCdjugoxH/0MuKcXUesu2Pfv1yF1JsX2n6R wKEK9qKrfdgIjyDMBYnw11yJYdiLUU4QyIuae9JDfrJyg83fK/2bFAirzoLrTYDO3h8n NuL2hUQBHMFr37AF+/wtltyPMR8p4fIOq8hA92+L7bcM40k/s5nVTkZ4b6V2IeDVbHqn 7POg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T1JV272B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw8-20020a170907a0c800b0073d8830e4c7si13277914ejc.954.2022.10.19.02.07.41; Wed, 19 Oct 2022 02:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T1JV272B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232081AbiJSJCB (ORCPT + 99 others); Wed, 19 Oct 2022 05:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbiJSI72 (ORCPT ); Wed, 19 Oct 2022 04:59:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD632316E; Wed, 19 Oct 2022 01:54:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6840C61840; Wed, 19 Oct 2022 08:52:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79C46C433D6; Wed, 19 Oct 2022 08:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169568; bh=rMXzGfT+AwXnfRT0f5JD55o8ci30M3mUQCL/5UtoNGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1JV272Bjd1wO+SEr9GEbyUjfVqiol4nCf3vZ/hIs3opzAAdCIhxvt+arZpP+/jWk Pd4DzzBZDcZyZsvazB9I2Qo3ueAS26/ghzUMhtBoqQ/d6QMyQ4sav2HfXJMyYTUCgh g0p+QDcg0ficca7rdMtFwuwT/n6kDaBzAk8dyoZM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Abhishek Pandit-Subedi , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.0 325/862] Bluetooth: Prevent double register of suspend Date: Wed, 19 Oct 2022 10:26:52 +0200 Message-Id: <20221019083304.385189903@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747106396923929344?= X-GMAIL-MSGID: =?utf-8?q?1747106396923929344?= From: Abhishek Pandit-Subedi [ Upstream commit 4b8af331bb4d4cc8bb91c284b11b98dd1e265185 ] Suspend notifier should only be registered and unregistered once per hdev. Simplify this by only registering during driver registration and simply exiting early when HCI_USER_CHANNEL is set. Reported-by: syzbot Fixes: 359ee4f834f5 (Bluetooth: Unregister suspend with userchannel) Signed-off-by: Abhishek Pandit-Subedi Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 4 ++++ net/bluetooth/hci_sock.c | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index e6be18eb7fe6..6ae5aa5c0927 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2400,6 +2400,10 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, container_of(nb, struct hci_dev, suspend_notifier); int ret = 0; + /* Userspace has full control of this device. Do nothing. */ + if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) + return NOTIFY_DONE; + if (action == PM_SUSPEND_PREPARE) ret = hci_suspend_dev(hdev); else if (action == PM_POST_SUSPEND) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 0d015d4a8e41..bd8358b44aa4 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -887,7 +887,6 @@ static int hci_sock_release(struct socket *sock) */ hci_dev_do_close(hdev); hci_dev_clear_flag(hdev, HCI_USER_CHANNEL); - hci_register_suspend_notifier(hdev); mgmt_index_added(hdev); } @@ -1216,7 +1215,6 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, } mgmt_index_removed(hdev); - hci_unregister_suspend_notifier(hdev); err = hci_dev_open(hdev->id); if (err) { @@ -1231,7 +1229,6 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, err = 0; } else { hci_dev_clear_flag(hdev, HCI_USER_CHANNEL); - hci_register_suspend_notifier(hdev); mgmt_index_added(hdev); hci_dev_put(hdev); goto done;