From patchwork Wed May 31 09:04:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 101287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2737159vqr; Wed, 31 May 2023 02:11:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lRFr2ZUzMk/7YD5+MO5Os7YwkE4xMcI2Him1FXeh8Kg5xBrRO4oNz56msUcoyIksafM0S X-Received: by 2002:aca:de56:0:b0:39a:531b:db6c with SMTP id v83-20020acade56000000b0039a531bdb6cmr791398oig.47.1685524290004; Wed, 31 May 2023 02:11:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685524289; cv=none; d=google.com; s=arc-20160816; b=Mo2ELR+mlGPKCs6tM2CudRQMdLcSnYMyd9btEuoAhLYFPZ0gzuWDpmu9HF2gAzUUfO 9YNJ56NmXpgcebIiqwMtO48WC3y6fHnjWNx7g5tIJOWMK+CxfS902syLn+oxI2qZgd/4 MAGKq6kiBDRZMwHFGWmO+G4cgS4B6r1KLcKapBMj5ufB1kHecsk1l0q3emNaLNBcC6B3 F53IE/HmYbZhLyFHFOAMkeI8ecT1fifijFkUMVRkBPcIZt4yQypRF+5xHJlgJnF2CPpV ZvGPLw8XI23utStHaDHdu10X3HRY2pib2Y99GHOS9QDggTCSZZrhToBO/UsHH94QvFAt piVw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8IRhEoaibsTBYaHxlYO5t3ytDQ83WytpDctNNBzj2sQ=; b=PtVbVZnIivDVjBzOKrtGQhA2PBxF/RfvbsyJeVtAoKeCKPtzBPAnbZB22+f4yam7ER 5T6X+X5IzR0DUc/JgSoUq6CeFwUmZTn3Po0GoXhWAT2BV2KJIEl9I/SpgF0JhrKXq0Wl XSrC6eV6XFwNDPsDof2jOJgJsXdMOievs0dKm+PhUyv90xIZR+DpJNzCHk5oxDezLVJp H141R2vyAQR2i/JosaDOHG7F5rkwadpq5PfTF452wIXVqOO7VC0v7eUZKQpVTzo+zahV ou/r4s1WAzxFa8grYHstY+0KE7qX5AVW3usxeiGmI2EyUKYncXCpmSYwlb5ZPAwdmUT6 cwUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CD3K4Aw4; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j192-20020a638bc9000000b0053f27c5efe4si603173pge.857.2023.05.31.02.11.17; Wed, 31 May 2023 02:11:29 -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=@kernel.org header.s=k20201202 header.b=CD3K4Aw4; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234876AbjEaJFH (ORCPT + 99 others); Wed, 31 May 2023 05:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235144AbjEaJEv (ORCPT ); Wed, 31 May 2023 05:04:51 -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 3249D12E; Wed, 31 May 2023 02:04:50 -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 BCBD96387D; Wed, 31 May 2023 09:04:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BBB9C4339B; Wed, 31 May 2023 09:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685523889; bh=leb2miRjsDRlGjNiyymZl4M2XNI8gihB2Td+2WkayYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CD3K4Aw4orr/W6XMCQQZ+qGzl+BCZTdr63Xdl7m/aMneI/Q2A2UHWw2UeP+K87v9H KTNWVZR4ICPiaVDwQRCDlgwVGTVkXyvgrfaiHWeK6tBhKaxXpsR4IxV1YYLBzdL1Q1 CljJEOyF/JQtZarbO8gaSxxUFqfJDuDcHH7w1x3ugwyMutHdBMtnQp7gPzdzr/lVMg X5RSYbAxmb03PqYdH9uJZOzS0Xzp/uRYH96Vo/ME6IKkwyvEA+BY7PLpodLS3iKl1e SDTKtlVPEQbaPmboz8y2+0kuKLFsGXgq1atSEvBTslPYiXrIF05ixijLh72rZDXrwN 8q6purx1CswGg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1q4HlF-0000qN-2q; Wed, 31 May 2023 11:04:53 +0200 From: Johan Hovold To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Matthias Kaehlcke , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH RESEND 1/2] Bluetooth: fix invalid-bdaddr quirk for non-persistent setup Date: Wed, 31 May 2023 11:04:23 +0200 Message-Id: <20230531090424.3187-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230531090424.3187-1-johan+linaro@kernel.org> References: <20230531090424.3187-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767400317844205631?= X-GMAIL-MSGID: =?utf-8?q?1767400317844205631?= Devices that lack persistent storage for the device address can indicate this by setting the HCI_QUIRK_INVALID_BDADDR which causes the controller to be marked as unconfigured until user space has set a valid address. Once configured, the device address must be set on every setup for controllers with HCI_QUIRK_NON_PERSISTENT_SETUP to avoid marking the controller as unconfigured and requiring the address to be set again. Fixes: 740011cfe948 ("Bluetooth: Add new quirk for non-persistent setup settings") Signed-off-by: Johan Hovold --- net/bluetooth/hci_sync.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 0efc2253265e..c2a805ee55cc 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4618,23 +4618,17 @@ static int hci_dev_setup_sync(struct hci_dev *hdev) invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); if (!ret) { - if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { - if (!bacmp(&hdev->public_addr, BDADDR_ANY)) - hci_dev_get_bd_addr_from_property(hdev); - - if (bacmp(&hdev->public_addr, BDADDR_ANY) && - hdev->set_bdaddr) { - ret = hdev->set_bdaddr(hdev, - &hdev->public_addr); - - /* If setting of the BD_ADDR from the device - * property succeeds, then treat the address - * as valid even if the invalid BD_ADDR - * quirk indicates otherwise. - */ - if (!ret) - invalid_bdaddr = false; - } + if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks) && + !bacmp(&hdev->public_addr, BDADDR_ANY)) + hci_dev_get_bd_addr_from_property(hdev); + + if ((invalid_bdaddr || + test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && + bacmp(&hdev->public_addr, BDADDR_ANY) && + hdev->set_bdaddr) { + ret = hdev->set_bdaddr(hdev, &hdev->public_addr); + if (!ret) + invalid_bdaddr = false; } } From patchwork Wed May 31 09:04:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 101290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2739052vqr; Wed, 31 May 2023 02:15:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79VXMbYWIAaBeNs646eJN019Q0iab0W7l8WU37UVNlu8QMyFvN3gAi/0uMk1Rmrr8W20ej X-Received: by 2002:a05:6871:2306:b0:19e:d5dd:53f5 with SMTP id sf6-20020a056871230600b0019ed5dd53f5mr3748344oab.45.1685524541815; Wed, 31 May 2023 02:15:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685524541; cv=none; d=google.com; s=arc-20160816; b=D2e4rhZQ1fliEeRKPoqq246mYarnqYKEtGppxwCt7/Zy2Oos6qpo82droyY2PXS54Z dPf8cnsdulncTJPJUY0cBhUomOiEdxUyKFDavHK4FKHdWDhSULoieLjZDn2oWIibn0Yr ZN4ZxnPY7z1h69ViMZQDc98/q02a/hQhHgszFFgM59rHQagvOvF5ZQgN3mDQZBsMHhZ1 sgrEOXKfRjIkAiGz/hgw8WOUFikhAOsFRUo6vXy2UUkJ44+FXt8pBqZUahJVdmx5wtM4 DeRtdCUiUWNv47AyoV237SpUeR918NFBNZwuC/zZr8kswPf6MxmSseafKbwwiGgLq6D8 ZTnA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=icIuh4PfywwKTQ/KFmVJ4lMfbNXjQIM6gX0iRdGN3Jk=; b=emKxoHt0SpKgnUAiMDLaAGmmg6nPumYEGErEUqdLF8D3Ua6XHdSeC2Ytilt/Brenv7 z+l230ozbZ0TxirUrYBbRmaIX4rVv4f4WLUzXqEGbuD0fRlM9n2cGgydwh+o2bDDSAtF 9k/52D2g2L9I9GGMt4b6m82gKbcg59Zac0VMHMwzpTU6XUv4pWdCzXYz6udKYhiLCoj2 e+4zIZF0dAp52xQqXgXnbwLHGt4zRGOYupZijsyG2MoLaBUOyeqA3LkcI6MmCy8MHdoo fPMmF7pFz/duElGKY2pms0Aw3CqNT/MkygCxh57kCbqO9OBVAe6WHdkYe141vFgShQfd 4d4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FOTayPMT; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k28-20020aa79d1c000000b00643aa8d8cb7si3318469pfp.185.2023.05.31.02.15.28; Wed, 31 May 2023 02:15:41 -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=@kernel.org header.s=k20201202 header.b=FOTayPMT; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235259AbjEaJFW (ORCPT + 99 others); Wed, 31 May 2023 05:05:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234973AbjEaJEv (ORCPT ); Wed, 31 May 2023 05:04:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 245E112B; Wed, 31 May 2023 02:04:50 -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 B43E563856; Wed, 31 May 2023 09:04:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BB7BC433D2; Wed, 31 May 2023 09:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685523889; bh=u5BHCw7c9M7g8QMKGLXgrokUzyklSa4XXeOrwzPRmkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FOTayPMTUC5IapDWCZPn8GTzqMc8BiPGS1mH0c3uaAizcFH/jSo8zqjG5yR3vt8eU kFMK7905Hzza74cXMtcBz5hWsFwHFXX2nUOlV1zxKoohrc5BPCfxxDN3NflHFmVxmK ZveyIUDOtLGtpP+qCLhePFYSNrN94KG2P5lHeMBFPJmbxgdfsqLO/XDxwbVJvmu7x6 3A2HrpWjeDe7Ecbkxc3E8/VCFAq8PhW1CabocVvuebbznXeOmIbkqInJLhAEggP15k FdXcQke804M75wTN2bQTk0mdKzvt8wVkynGSUIJz0tKjsNege8+nYIWzS8JbJxQe1a 4zUwGkQNKCrHA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1q4HlF-0000qV-5L; Wed, 31 May 2023 11:04:53 +0200 From: Johan Hovold To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Matthias Kaehlcke , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH RESEND 2/2] Bluetooth: fix use-bdaddr-property quirk Date: Wed, 31 May 2023 11:04:24 +0200 Message-Id: <20230531090424.3187-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230531090424.3187-1-johan+linaro@kernel.org> References: <20230531090424.3187-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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,T_SCC_BODY_TEXT_LINE 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?1767400582013294392?= X-GMAIL-MSGID: =?utf-8?q?1767400582013294392?= Devices that lack persistent storage for the device address can indicate this by setting the HCI_QUIRK_INVALID_BDADDR which causes the controller to be marked as unconfigured until user space has set a valid address. The related HCI_QUIRK_USE_BDADDR_PROPERTY was later added to similarly indicate that the device lacks a valid address but that one may be specified in the devicetree. As is clear from commit 7a0e5b15ca45 ("Bluetooth: Add quirk for reading BD_ADDR from fwnode property") that added and documented this quirk and commits like de79a9df1692 ("Bluetooth: btqcomsmd: use HCI_QUIRK_USE_BDADDR_PROPERTY"), the device address of controllers with this flag should be treated as invalid until user space has had a chance to configure the controller in case the devicetree property is missing. As it does not make sense to allow controllers with invalid addresses, restore the original semantics, which also makes sure that the implementation is consistent (e.g. get_missing_options() indicates that the address must be set) and matches the documentation (including comments in the code, such as, "In case any of them is set, the controller has to start up as unconfigured."). Fixes: e668eb1e1578 ("Bluetooth: hci_core: Don't stop BT if the BD address missing in dts") Signed-off-by: Johan Hovold --- net/bluetooth/hci_sync.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index c2a805ee55cc..ce03038b3460 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4615,16 +4615,14 @@ static int hci_dev_setup_sync(struct hci_dev *hdev) * BD_ADDR invalid before creating the HCI device or in * its setup callback. */ - invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); - + invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || + test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); if (!ret) { if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks) && !bacmp(&hdev->public_addr, BDADDR_ANY)) hci_dev_get_bd_addr_from_property(hdev); - if ((invalid_bdaddr || - test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && - bacmp(&hdev->public_addr, BDADDR_ANY) && + if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) && hdev->set_bdaddr) { ret = hdev->set_bdaddr(hdev, &hdev->public_addr); if (!ret)