From patchwork Tue Apr 12 12:09:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasyl Vavrychuk X-Patchwork-Id: 560093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBD5FC433EF for ; Tue, 12 Apr 2022 12:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353785AbiDLMqM (ORCPT ); Tue, 12 Apr 2022 08:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353904AbiDLMpx (ORCPT ); Tue, 12 Apr 2022 08:45:53 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524997C150; Tue, 12 Apr 2022 05:10:12 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id bg10so36925093ejb.4; Tue, 12 Apr 2022 05:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rq9lR94HUSwFCQZMw7bg3ocQXJ+m1X8SURhYPub1cJc=; b=HdmVvFiWFm5FuLOzxIGZw8PYTX2AkLfWmgtmdMqk3e41zt0SS/amriqzLdBoEhiBVY flJD/cwGV/iOGXd/P8hJQvKbnvXGBXwckMPofJsy+Cfxdvz7h5R5R2JYzxmnHI49oQVz iKxLvvtWOWkKNk6nSvWZUXfLtF+Rnw2x8LnJlzVqP/KB8imACgWjQykUgTVrBNGszmJS P6w4IoTt65gvQnUAZMh5bUrTQitCHY7inTg+D5aLGVxd8wC/YcIv7rD+kDE0dx5tRIp8 89MvNTFX2vEC8YPLPQHiS9WGDTSCBixkSFs7KBzlYRx/Gtyh9BT8Ke6M1+gN5dwn1b36 PJ5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rq9lR94HUSwFCQZMw7bg3ocQXJ+m1X8SURhYPub1cJc=; b=TiJnck0N3h2KfV+tvmLPuPE7FHlkxJnJTzsLuqcdo3g1CgxAJvpKRc8QvE4ApA17yD bxTRYwvJcog7fD3a3aRvkSIYIrz0FpTG/bERQBLvxjaCU/Sqnqzkn6QbYhAvQqmf6XIW FyoluGhJYHwnZ1NBsqR9n6YzVubJ5NuEm1IYte8VuZ4jW8lwn3xUgQpwXaMKq2uSgH9g nAQNpkFEI5lUFufPJ6fD9Te4axcVbeQfLugwz0tWi45Ler4tmZY6wjHFMaPgbzgBNj+x 3N7DW2fGKoOyKx1rWVeu9gPntqwqloFJLUVAoqA48sgT7Y6CxH4vmz7thoXU0GcrIsGy 0wUg== X-Gm-Message-State: AOAM5304HIFMx4ZmDlFavpx4OB7jRNB1uLIZTGL1EgEJUiF2+j0Hdc2M bOMfwr0JuWzlNsiYQ/x0DFXdAro/t7iL2g== X-Google-Smtp-Source: ABdhPJwTAZSruMAB8r/F0xAtfgsPaDIaToqXknRPt2MxMzHNFsXtX+F967xZn+NIgBI/JAMB6MCaug== X-Received: by 2002:a17:907:6e17:b0:6da:83a3:c27a with SMTP id sd23-20020a1709076e1700b006da83a3c27amr33351767ejc.415.1649765409959; Tue, 12 Apr 2022 05:10:09 -0700 (PDT) Received: from localhost.localdomain ([213.174.17.16]) by smtp.gmail.com with ESMTPSA id z16-20020a17090665d000b006e8789e8cedsm3709174ejn.204.2022.04.12.05.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 05:10:09 -0700 (PDT) From: Vasyl Vavrychuk X-Google-Original-From: Vasyl Vavrychuk To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Vasyl Vavrychuk Subject: [RFC PATCH] Bluetooth: core: Allow bind HCI socket user channel when HCI is UP. Date: Tue, 12 Apr 2022 15:09:45 +0300 Message-Id: <20220412120945.28862-1-vasyl.vavrychuk@opensynergy.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This is needed for user-space to ensure that HCI init scheduled from hci_register_dev is completed. Function hci_register_dev queues power_on workqueue which will run hci_power_on > hci_dev_do_open. Function hci_dev_do_open sets HCI_INIT for some time. It is not allowed to bind to HCI socket user channel when HCI_INIT is set. As result, bind might fail when user-space program is run early enough during boot. Now, user-space program can first issue HCIDEVUP ioctl to ensure HCI init scheduled at hci_register_dev was completed. Signed-off-by: Vasyl Vavrychuk --- net/bluetooth/hci_sock.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 33b3c0ffc339..c98de809f856 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -1194,9 +1194,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, if (test_bit(HCI_INIT, &hdev->flags) || hci_dev_test_flag(hdev, HCI_SETUP) || - hci_dev_test_flag(hdev, HCI_CONFIG) || - (!hci_dev_test_flag(hdev, HCI_AUTO_OFF) && - test_bit(HCI_UP, &hdev->flags))) { + hci_dev_test_flag(hdev, HCI_CONFIG)) { err = -EBUSY; hci_dev_put(hdev); goto done;