Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2954907rwa; Mon, 22 Aug 2022 17:47:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR7QW//t/POaJaWoH+j9woLysuZcdR57kztYUZXbr2ZwKqGU/MzqMjmZH4AEvl2RVvfQd6CS X-Received: by 2002:a63:8049:0:b0:42a:6705:49cd with SMTP id j70-20020a638049000000b0042a670549cdmr13314086pgd.113.1661215636049; Mon, 22 Aug 2022 17:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661215636; cv=none; d=google.com; s=arc-20160816; b=AAsKOX+zD8/XLSZR935NVnyz32exqmrTx6zEM6mNK1MSRIvMvFZqKs0dgS1P2cp2j8 zpWIyPYuAKptMxlCC74/Rek4eohHG9GzvpeEH8J6CtoO8nLrp0wj7dx/u3+YBIANE9Z5 eoVTwbg6XMUa0QGkdSqnE9VA9zp7hCawn4G8x8M0vnUqhhKVt+3wkS7kALDUgIqmqUdn fqta8yAN+UdCKLxgwJ+hBPkcPSZX6dwNswbnwtJopA4F9QpcgtOQLirmdr5NxAye//bg +tsID5KBb6OcjavlA07rX73WtGumavX1NajYTFZUVuQAKzdFndRiTb6jojCi/iqdYnhX uPmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3PqTa4Wf3v0Bl4Y/+nYhv4ari+wLY1mF7jRZbgByGrg=; b=ZQoLwS8pQ1B9NFH6BeiL8rm+MEG7fWP7zBM4WznZ38Sexi3uAaCuBVhMDaH5SuoSoc a96gN38V1dDy3OsUia07xNv43WGUJZSNAmBc5IDzyIDgY2R23gc1JTUBvSDGyXCVbQIw sWeTiLVMTdJe36z7cG8o9tNP7Bw44UC5UeTH0t3FKNVwNX/gVZ68pkG3yCUg6iJAKeqD Q6cW0eysCXZ4ZjehOdt6YYEFy6iEbvpV5cKAPX4X7iW9Z6Z9B6HJq16Nfe3c6FdXbDgz yxy1U6eSJESfq+zSYuOa+vixcPVZr5B+FP9Ey3d4yN1SSnvOvvU0MO6Dnlgld+mkqYnc zy0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nmMR+eeL; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a170902e84800b00172eb499315si4938077plg.517.2022.08.22.17.47.04; Mon, 22 Aug 2022 17:47:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@google.com header.s=20210112 header.b=nmMR+eeL; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238895AbiHWA26 (ORCPT + 99 others); Mon, 22 Aug 2022 20:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237871AbiHWA25 (ORCPT ); Mon, 22 Aug 2022 20:28:57 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA2A11CB0F for ; Mon, 22 Aug 2022 17:28:56 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id q2so13903938edb.6 for ; Mon, 22 Aug 2022 17:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=3PqTa4Wf3v0Bl4Y/+nYhv4ari+wLY1mF7jRZbgByGrg=; b=nmMR+eeL/3d90s+8VJK5wm/77hiOmyGtrj9lcDLyz1PlqdnR+v4qqSQrM6bp44jNhF zTpiQgdkSE1SymvikOeeWYzW5FojQOeU5NlRMIMGBI46+avH88Qy/9L+OCbBCUDhsnab +T0NyBpq2XLxvpoDU6iLKvkah4Fr8Mfy/wgfbqcC90yIY2zvUGw0lpDCaQhOWkjlq1sZ VygqtLihVy5S60l+tJUIW1N20LCc8NMFUPzrwLqU59tvnJWNL6pO13wjgN3wkRxa2q2o 6Xv8XWRUKga5GitDf0gJlDPZlDGCLL/qQmGY7vqN10q2SBMp5fuRjvG9s9iuZs+aQ/ZX vAjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=3PqTa4Wf3v0Bl4Y/+nYhv4ari+wLY1mF7jRZbgByGrg=; b=Nc1T+eZEIESSjIQic08Lmy7c86WGV+7yt+2vBHhEmNr+9BV/NWYXzISzWstqoX+NlA 6cSO7aADwLhAiYKIaJ24eogEDcc67wkMgjg7RLhtYMr6N47xmwnL5kMtGl+0iRyst3mf GKYHcZQSLd93MUEIBaGRLlUnK06VkO0u5uxXBjdgfjUwPfJ7k5eY13rqWsj6ThTJsaNs yQnl9rLkn9a76oRnDd89OIlauYEU2Lom4AzF/YZeL3JphhbWPneWStbtHR/UTN52fT9j uUeQvtW3M1OjFO28bgBFAvtB8PhZGf8zwnYjbvH49F5EXBQo03ZtOBCNHg9t4QdYez4F xT0w== X-Gm-Message-State: ACgBeo0ruSw4Auy71zE3PP/b/b5G6mamvNEqS3Jem+SEPdYAt2g3MzSn 3a9baT5E3zPKdTHWp9Q6ImD69lSyNllX+jl2ak6PGw== X-Received: by 2002:a05:6402:f29:b0:446:6629:bbb6 with SMTP id i41-20020a0564020f2900b004466629bbb6mr1357155eda.384.1661214534890; Mon, 22 Aug 2022 17:28:54 -0700 (PDT) MIME-Version: 1.0 References: <20220822125221.Bluez.1.I541cbea9d6295f531c796bf3bda96b22db76bc19@changeid> In-Reply-To: From: Archie Pusaka Date: Tue, 23 Aug 2022 08:28:43 +0800 Message-ID: Subject: Re: [Bluez PATCH] adapter: Reset pending settings when receiving MGMT error To: Luiz Augusto von Dentz Cc: linux-bluetooth , Marcel Holtmann , CrosBT Upstreaming , Archie Pusaka , Sonny Sasaka Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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-bluetooth@vger.kernel.org Hi Luiz, On Tue, 23 Aug 2022 at 06:54, Luiz Augusto von Dentz wrote: > > Hi Archie, > > On Sun, Aug 21, 2022 at 11:33 PM Archie Pusaka wrote: > > > > Hi Paul, > > > > On Mon, 22 Aug 2022 at 14:15, Paul Menzel wrote: > > > > > > Dear Archie, > > > > > > > > > Thank you for the patch. > > > > > > > > > Am 22.08.22 um 06:53 schrieb Archie Pusaka: > > > > From: Archie Pusaka > > > > > > I think the tag in the email subject needs to be [PATCH BlueZ] to be > > > detected by the build bot. > > > > Is the bot the one who just commented about the test result? If so > > probably it can detect this format as well. > > > > > > > We set the pending settings flag when sending MGMT_SETTING_* > > > > commands to the MGMT layer and clear them when receiving success > > > > reply, but we don't clear them when receiving error reply. This > > > > might cause a setting to be stuck in pending state. > > > > > > Were you able to reproduce a problem on real hardware? > > > > I only received some reports, but unfortunately I cannot repro on real > > hardware. The symptom is BlueZ can't be turned off, snoop logs shows > > that MGMT_OP_SET_POWERED fails to be sent, and we are stuck with it > > since the next commands to toggle power are ignored. > > Weird how can you tell MGMT_OP_SET_POWERED fails to be sent or you > meant it was sent but the kernel returned an error? It would be great > to include these errors. Yeah, the kernel returned an error, NOT_AUTHORIZED If I remembered correctly. It was caused by a timed out disconnection procedure, so it's weird that the return value is NOT_AUTHORIZED, but I didn't check why. Will include this in the commit message. On Tue, 23 Aug 2022 at 06:51, Luiz Augusto von Dentz wrote: > > Hi Archie, > > On Sun, Aug 21, 2022 at 9:54 PM Archie Pusaka wrote: > > > > From: Archie Pusaka > > > > We set the pending settings flag when sending MGMT_SETTING_* > > commands to the MGMT layer and clear them when receiving success > > reply, but we don't clear them when receiving error reply. This > > might cause a setting to be stuck in pending state. > > > > Therefore, also clear the pending flag when receiving error. > > Furthermore, this patch also postpone setting the pending flag > > until we queue the MGMT command in order to avoid setting it too > > soon but we return early. > > > > Reviewed-by: Sonny Sasaka > > > > --- > > > > src/adapter.c | 45 +++++++++++++++++++++++++++++++++++++-------- > > 1 file changed, 37 insertions(+), 8 deletions(-) > > > > diff --git a/src/adapter.c b/src/adapter.c > > index ec26aab1a7..4da1fcc3e5 100644 > > --- a/src/adapter.c > > +++ b/src/adapter.c > > @@ -640,14 +640,21 @@ static void new_settings_callback(uint16_t index, uint16_t length, > > settings_changed(adapter, settings); > > } > > > > +struct set_mode_data { > > + struct btd_adapter *adapter; > > + uint32_t setting; > > +}; > > + > > static void set_mode_complete(uint8_t status, uint16_t length, > > const void *param, void *user_data) > > { > > - struct btd_adapter *adapter = user_data; > > + struct set_mode_data *data = user_data; > > + struct btd_adapter *adapter = data->adapter; > > > > if (status != MGMT_STATUS_SUCCESS) { > > btd_error(adapter->dev_id, "Failed to set mode: %s (0x%02x)", > > mgmt_errstr(status), status); > > + adapter->pending_settings &= ~data->setting; > > return; > > } > > > > @@ -677,6 +684,7 @@ static bool set_mode(struct btd_adapter *adapter, uint16_t opcode, > > { > > struct mgmt_mode cp; > > uint32_t setting = 0; > > + struct set_mode_data *data; > > > > memset(&cp, 0, sizeof(cp)); > > cp.val = mode; > > @@ -699,15 +707,23 @@ static bool set_mode(struct btd_adapter *adapter, uint16_t opcode, > > break; > > } > > > > - adapter->pending_settings |= setting; > > - > > DBG("sending set mode command for index %u", adapter->dev_id); > > > > + data = g_try_new0(struct set_mode_data, 1); > > Use new0 instead of g_try_new0. Hmm, we use g_try_new0 in property_set_mode() though, so I thought I should follow. But anyway, will change to g_new0. > > > + if (!data) > > + goto failed; > > + > > + data->adapter = adapter; > > + data->setting = setting; > > + > > if (mgmt_send(adapter->mgmt, opcode, > > adapter->dev_id, sizeof(cp), &cp, > > - set_mode_complete, adapter, NULL) > 0) > > + set_mode_complete, data, g_free) > 0) { > > + adapter->pending_settings |= setting; > > return true; > > + } > > > > +failed: > > btd_error(adapter->dev_id, "Failed to set mode for index %u", > > adapter->dev_id); > > > > @@ -718,6 +734,7 @@ static bool set_discoverable(struct btd_adapter *adapter, uint8_t mode, > > uint16_t timeout) > > { > > struct mgmt_cp_set_discoverable cp; > > + struct set_mode_data *data; > > > > memset(&cp, 0, sizeof(cp)); > > cp.val = mode; > > @@ -734,11 +751,19 @@ static bool set_discoverable(struct btd_adapter *adapter, uint8_t mode, > > mode); > > } > > > > + data = g_try_new0(struct set_mode_data, 1); > > + if (!data) > > + goto failed; > > + > > + data->adapter = adapter; > > + data->setting = 0; > > + > > if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DISCOVERABLE, > > adapter->dev_id, sizeof(cp), &cp, > > - set_mode_complete, adapter, NULL) > 0) > > + set_mode_complete, data, g_free) > 0) > > return true; > > > > +failed: > > btd_error(adapter->dev_id, "Failed to set mode for index %u", > > adapter->dev_id); > > Looks like the data pointer is leaked in case it fails to be sent/queued. Sorry, my bad. Will fix this. > > > @@ -2877,6 +2902,7 @@ static gboolean property_get_mode(struct btd_adapter *adapter, > > > > struct property_set_data { > > struct btd_adapter *adapter; > > + uint32_t setting; > > GDBusPendingPropertySet id; > > }; > > > > @@ -2901,6 +2927,8 @@ static void property_set_mode_complete(uint8_t status, uint16_t length, > > > > g_dbus_pending_property_error(data->id, dbus_err, > > mgmt_errstr(status)); > > + > > + adapter->pending_settings &= ~data->setting; > > return; > > } > > > > @@ -2969,8 +2997,6 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, > > > > mode = (enable == TRUE) ? 0x01 : 0x00; > > > > - adapter->pending_settings |= setting; > > - > > switch (setting) { > > case MGMT_SETTING_POWERED: > > opcode = MGMT_OP_SET_POWERED; > > @@ -3024,11 +3050,14 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, > > goto failed; > > > > data->adapter = adapter; > > + data->setting = setting; > > data->id = id; > > > > if (mgmt_send(adapter->mgmt, opcode, adapter->dev_id, len, param, > > - property_set_mode_complete, data, g_free) > 0) > > + property_set_mode_complete, data, g_free) > 0) { > > + adapter->pending_settings |= setting; > > return; > > + } > > > > g_free(data); > > > > -- > > 2.37.1.595.g718a3a8f04-goog > > -- > Luiz Augusto von Dentz Thanks, Archie