Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3286518pxb; Mon, 25 Jan 2021 11:40:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLPpYewBHkF45H5bd9Pormdm1onRWpid9qPAJCvI+ZbbV4/c15ncXYYA3Il6Lr7yqYt5w9 X-Received: by 2002:a17:906:708f:: with SMTP id b15mr1329058ejk.267.1611603646028; Mon, 25 Jan 2021 11:40:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611603646; cv=none; d=google.com; s=arc-20160816; b=tFM+sFOUsUwo8oe4bcrJzQV7R14dcYfZbSzLX2dA/C2Yz4r9RzIjngVj0J39bULhlU Awt0JkbCnKTqFr8Hcwt7p9xfeo9mDOgeoxD/mVbb4hVQEUr7b0yrIvtTDeN1sYzT1/rV hKKnpgtKEfF9XDM4nM06d2n95PHWZ06zR50cqT85j84KJvz7+aKOdXaTA6TVBlCq8yl8 P37pgRGAv5du61vBEvU/9aDz+M7KQdHwoSL6HnfJPZIHGyiSB1qSwniECgIcGCWZE9xH Q+FkItBNhSStkiO86g8lyP4i8RbHNKgkQHzt0rrsxzRIcg5x/uCuVjXHgmxS5Ru1hvOC mL1w== 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=t+Mm021t8XQ28YMnyF7U7y5xgXhoPAsbNMG0IjzYd/A=; b=OMxKnqtFRKpo4e9iKP4/X/qu/BO3Nvxct+8gfi15oqJB6aNq16HfjQixDMYhiJrBxh jLLOiJy9aiiUkqeiqVWhCDBjzjMhwEHu1XBlcqPf8hDEjo0eTxkFk2/Z9bKwztz13drq HPFJRvsdKv/3e5t5aoxfj9E7miyy7fqcRmttw5OG1PlxhxB8LAQQjzQrIov4mjOAIMPg wUffQkpe3q0WlFyB3xP5rt74cNvcd877QK47S9O1JCRB1uG+7WQ+7Op3SMvmL/OXL2SG clRWeMIvh1JzEA5WXYROyUfxvmFryKsVqtSEVq3M1L50qt6RmGxtc5BeELaMnv6xCcLg DiNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="m5e/w9fN"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si7868440ede.328.2021.01.25.11.40.21; Mon, 25 Jan 2021 11:40:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="m5e/w9fN"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731990AbhAYThe (ORCPT + 99 others); Mon, 25 Jan 2021 14:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731983AbhAYTh0 (ORCPT ); Mon, 25 Jan 2021 14:37:26 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63733C061573 for ; Mon, 25 Jan 2021 11:36:46 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id f1so16889040edr.12 for ; Mon, 25 Jan 2021 11:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=t+Mm021t8XQ28YMnyF7U7y5xgXhoPAsbNMG0IjzYd/A=; b=m5e/w9fNDS5Rg17lW6rcLk1uvHmTjrT2NO4ZT/tfxQBCOBZbyCPrh1L5WJ8wKjkaKx b3X1IzCWBHglSsNaozXCFXWKT2WPU9Kr+EJNBRESp30q3yAl41YVvP5F1noax0C2GY7M 86lB84BQ4fatmxGIjbcAhJTJbIDCccYvniyXo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t+Mm021t8XQ28YMnyF7U7y5xgXhoPAsbNMG0IjzYd/A=; b=PZwCwMkqk7A0q5x2Ogst3tKam/a19Gvs7n5CB48oJA/2l6oWnb+LdZKGX6098nzCo3 LgawUqNaiD+pG8D1BDKct4Ldq3NYlI+vWSmyAkpgLt1Ol2sr3v8ZDFPXdtQAM4S5GAmT v1stvree00Xq5l8nr/+r0yecDyx4fsFptMSgM/8DYCxReLKbPkPPMmSWZgPx9BsfE439 ENOL5Jk3GDDv63R3hW+8vWfGXkENEWb3Jvr5+vP0bFiM3kn29wP5VEMp243tF5NFE35I qxOVOVWWfSe/JO6KkUu5BzUqNnyTTnIrQEMc0Bpg6vM+VbEJt79sPpW/jLb/gZNrTLOS Xi+A== X-Gm-Message-State: AOAM533eNeM1zxYbnwBmKsDu3iiygSPibtNplDnF5ZXJtoAyhs/4a6ya IcbUNtUi3uka0NE9S+KxlMZoyxzwugHalw== X-Received: by 2002:a05:6402:757:: with SMTP id p23mr1826890edy.245.1611603405042; Mon, 25 Jan 2021 11:36:45 -0800 (PST) Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com. [209.85.221.54]) by smtp.gmail.com with ESMTPSA id h12sm10637168edb.16.2021.01.25.11.36.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jan 2021 11:36:44 -0800 (PST) Received: by mail-wr1-f54.google.com with SMTP id p15so7522429wrq.8 for ; Mon, 25 Jan 2021 11:36:44 -0800 (PST) X-Received: by 2002:adf:a2ca:: with SMTP id t10mr2619745wra.370.1611603404084; Mon, 25 Jan 2021 11:36:44 -0800 (PST) MIME-Version: 1.0 References: <20210110003033.2528-1-sonnysasaka@chromium.org> In-Reply-To: From: Sonny Sasaka Date: Mon, 25 Jan 2021 11:36:31 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH BlueZ] input/hog: Fix double registering report value callbacks To: Luiz Augusto von Dentz Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, I have revised the patch to using the notifyid to detect double registration. Please take a another look. Thanks! On Mon, Jan 11, 2021 at 9:47 AM Luiz Augusto von Dentz wrote: > > Hi Sonny, > > On Sat, Jan 9, 2021 at 4:34 PM Sonny Sasaka wrote: > > > > In commit 23b69ab3e484 ("input/hog: Cache the HID report map"), we > > optimized HOG reconnection by registering report value callbacks early, > > but there was a bug where we also re-register the same report value > > callbacks after at CCC write callback. We should handle this case by > > avoiding the second callback register if we know we have done it > > earlier. > > > > --- > > profiles/input/hog-lib.c | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c > > index 1f132aa4c..089f42826 100644 > > --- a/profiles/input/hog-lib.c > > +++ b/profiles/input/hog-lib.c > > @@ -80,6 +80,7 @@ struct bt_hog { > > struct bt_uhid *uhid; > > int uhid_fd; > > bool uhid_created; > > + bool report_value_cb_registered; > > gboolean has_report_id; > > uint16_t bcdhid; > > uint8_t bcountrycode; > > @@ -336,6 +337,13 @@ static void report_ccc_written_cb(guint8 status, const guint8 *pdu, > > return; > > } > > > > + /* If we already had the report map cache, we must have registered UHID > > + * and the report value callbacks. In that case, don't re-register the > > + * report value callbacks here. > > + */ > > + if (hog->report_value_cb_registered) > > + return; > > + > > Can't we check the report->notifyid instead of introducing yet another > flag that seems to have the same intent of tracking if the report has > been subscribed? In fact it seem there is something odd related to how > we handle the CCC here, we do read it on ccc_read_cb but we don't > check if its value is already set. Pehaps something like the following > would be more complete solution, though we should really look into > convert hog-lib to use bt_gatt_client instead of keep using GAttrib: > > diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c > index 1f132aa4c..34a4d7c3b 100644 > --- a/profiles/input/hog-lib.c > +++ b/profiles/input/hog-lib.c > @@ -360,15 +360,30 @@ static void ccc_read_cb(guint8 status, const > guint8 *pdu, guint16 len, > { > struct gatt_request *req = user_data; > struct report *report = req->user_data; > + uint16_t value; > > destroy_gatt_req(req); > > - if (status != 0) { > + if (status || !len) { > error("Error reading CCC value: %s", att_ecode2str(status)); > return; > } > > - write_ccc(report->hog, report->hog->attrib, report->ccc_handle, report); > + if (len == 1) > + value = *pdu; > + else > + value = get_le16(pdu); > + > + if (!value) { > + write_ccc(report->hog, report->hog->attrib, report->ccc_handle, > + report); > + return; > + } > + > + report->notifyid = g_attrib_register(report->hog->attrib, > + ATT_OP_HANDLE_NOTIFY, > + report->value_handle, > + report_value_cb, report, NULL); > }