From patchwork Mon Apr 24 13:35:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 87034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2755136vqo; Mon, 24 Apr 2023 06:43:54 -0700 (PDT) X-Google-Smtp-Source: AKy350aCJb6SLRTkrIoB70k184QO0O9Qwv2yCbbGsqe56ncGRBYL+gslTVuyxXYgJegBGa8WzHgB X-Received: by 2002:a17:90a:398c:b0:23f:58a2:7d86 with SMTP id z12-20020a17090a398c00b0023f58a27d86mr14001682pjb.10.1682343833763; Mon, 24 Apr 2023 06:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682343833; cv=none; d=google.com; s=arc-20160816; b=SASuuViklzmw43APauafVwMapVC3aSAmysX51AF7B7Rgas82HjhFUmKxwxKYEppwUI wM+bUFQLhI7Uy6cgvgqZHUg3cv4aqw0Ktaqc491q7j7JOYEr7Rg7yWcUybeEYmx+jzuk TMHbVaKSHAOmaC6UfY9jiejLvYUVRcALay/GGZTqh+WxFx1CMqJRL0OkO+J2jfpmH+MC qdfjzuTxfI+09s2Eio6oyxVPzSQm+pZMiTzc8zCNt7S/IKeTIdVnJlyAPUD/qNu4pWyT wLfbsyJv4maLuwaObz4Wm0/YO0XrsJRNbwLzBKz/CWNejb3Ge9+IAgNG7+J710Y936a6 poxw== 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=ieCO/B1sqK0o/5x81kxoQ4JQQsgKvC7MDRFqbTmSdyE=; b=v4S6FSb65XkdnvQX/9v33UywhTWS8jMHfogsni5N3HbUaC7jUnFQU77K3HJQA9hVdV +qjti+3U2KvAajIZfo7bepeWUjq2mJvNc3XvOXmYX2lWPYhP0X2S6skMINRji0fDA2d2 4OnYy00Lus+JObEFURaQwpV0pRGmNDlrumKpIuNkzeF+V+Xeji7RM9z9UkGH/fvVjC/0 ZqNZa8HJjGVukutMs0c1FXdM/v6oLeKYh5H1n04qLeFgbCu64UK+lxIEoFsxIrKc/+P6 tzlgbBzLQ0w7EuqJM2DXwGbLnGjayF2juAsbAV3AEeecGYQLI8nFL3bD/93cyXHKgBYY d7qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NM031X7O; 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 h16-20020a17090acf1000b0024715c041c3si13695589pju.137.2023.04.24.06.43.41; Mon, 24 Apr 2023 06:43:53 -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=NM031X7O; 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 S232663AbjDXNgE (ORCPT + 99 others); Mon, 24 Apr 2023 09:36:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbjDXNfq (ORCPT ); Mon, 24 Apr 2023 09:35:46 -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 4F5AD196; Mon, 24 Apr 2023 06:35:36 -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 2261F62332; Mon, 24 Apr 2023 13:35:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E89BC433EF; Mon, 24 Apr 2023 13:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682343335; bh=HMtBQELFN9fhTXYtgqc3NqK66rbPQYn9IisD7ItTMJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NM031X7OQ1oQl17XIpcIdy+hf7ZonNI+EzmBBgUzCBQ0S74xtwh/Ymixk+XDsQUAF fJkfHmV9k4Lgrca7VvZgiWCDBHJKxrKaFZuKmb+rqmQL+3z7G2wCtqTbyHdhF2/Eke I2c910Juoo+Y1tsSSgqNiDaAJcvCFJhUHzlmPXNtduPcWLltv4hcx1+MNE+LRKdTlR TFjP7QKY9mkpfSBgQ/5yBHrQeF3kcSoxxM4YCD/Ph5RGyBISko70DffBHtjZCydxdi lBsEUexSd3NKLgxZ1Wp1ffBIDwSCqw2LtLgWmFZGORbFHioN0WrHnw9sllFif/6cWA L7HqHO6O6VmXQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pqwMC-0003kM-A7; Mon, 24 Apr 2023 15:35:52 +0200 From: Johan Hovold To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Matthias Kaehlcke , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Johan Hovold Subject: [PATCH 2/2] Bluetooth: fix use-bdaddr-property quirk Date: Mon, 24 Apr 2023 15:35:42 +0200 Message-Id: <20230424133542.14383-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424133542.14383-1-johan+linaro@kernel.org> References: <20230424133542.14383-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?1764065367677355792?= X-GMAIL-MSGID: =?utf-8?q?1764065367677355792?= 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 f45598b5a532..cc925a240f3b 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4570,16 +4570,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)