Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp635541pxb; Thu, 21 Jan 2021 16:19:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIHuw1PtfrFmxm0le+XguBq75z6OMyfaGtpLhpvfkOettXOlRd0XzkLdhNcBVXhfuTUuxw X-Received: by 2002:a17:906:1288:: with SMTP id k8mr1276098ejb.206.1611274793173; Thu, 21 Jan 2021 16:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611274793; cv=none; d=google.com; s=arc-20160816; b=x/mrNcF4bReAaAsZs619PYBWsqjmfiLOJiKFJIMk5oosagnfP8OEZjQ4vLnCBm2Dlo QO9VM40tmurnQl2wlAqKH+SZ6O0Ncaet2QadTwIWqRyPtq2KMUM5jtDFXeN8NItNftLP dkBjqkuIcLUhlH1hpvisZ6YzOr0sHYfNOq8H2qghHj6d/pRIAXxC3SQngVI9QVirqtJn 8Bm/1sbzQ6crySqupq3Xwupgiq/I/543hkZtcd1ESwJvI4yluGOP0BTzCko3F8dLn8bi qdhXIKwiNJBtg5GKvqWK+b6Jad0S8DV9QSV3nKNFimUnEn7zDxq9g4jjN0uaRwmMKKsB PFSg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=3nnF+bkgtjz25uaf0FNhzS1otuiCUw75IC3zjjwwTtA=; b=lGyEw9683/QcU7TitVGV2alCt68CphmX/8woeujqzMpAhdofhWakYi1+0b2SUbBDZZ wasmnpizeNCltaMK6up9roS7XHlXBti/AzZARoUFoONjJBnBOXe9HNgZ6db6rtC5OJgE bI9oJVk96wae/1rJsGNjEsV7CQgyD5007qPjeBJ3/ZcFyRQCLMo7wDd0WPtXZpeA9h3V nvWj2kS7k0sHKtzB7kcEAxWycmk/2sY4duDsLuLyNow5qjQp37OOA5bEaUAZfa6hnCUb S+Y9EnBE2CgbA5SZpUh2ggKEhGTPkg5v0yav0IFSh6X6e3PBUdRJVYxisjL/PdQYsj8b TkEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bpWQKD+U; 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 y21si2380978ejf.161.2021.01.21.16.19.30; Thu, 21 Jan 2021 16:19:53 -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=bpWQKD+U; 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 S1725918AbhAVAOc (ORCPT + 99 others); Thu, 21 Jan 2021 19:14:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbhAVAOV (ORCPT ); Thu, 21 Jan 2021 19:14:21 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37A3C0613D6 for ; Thu, 21 Jan 2021 16:13:40 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id g3so2258746plp.2 for ; Thu, 21 Jan 2021 16:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3nnF+bkgtjz25uaf0FNhzS1otuiCUw75IC3zjjwwTtA=; b=bpWQKD+UXxBwSgv3lf2TKYmhZF9IHnWZI4BVzjS7M6V0umMcNcee0I+XPoKQnRS0KD D+UH1gOMCV7XPEbeSr3FfYP+qYhLiwP4zKSXiFxPqWzzxmYBzNUo4XDoI1Vp/BcwJbwr zG7lbjQclOEreobob8o0ntIYlsjVPX7Strd+0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3nnF+bkgtjz25uaf0FNhzS1otuiCUw75IC3zjjwwTtA=; b=DFVsIX2Us50pRGSBEBBnq+ADxMyLacjsKPtUlghDiSwQzJ1fBX+xrLUqrJpk/RM3LA 0xnZydbXJ2Inwe8VCvxugdmHGRiECOT/Iwit9PQyu8VANsPucJjyApnhJHpz01MXvjKf At3WcuKvElxkLr0N5hjIHB9fRvQFD8CmHlT6Abr9HIQpru2lHtw44IZsNYCfMCcn1GPO yy076HRu7+c0lKx0n5mUgEGrtHwrVMuatDUiMVjnYdO2kIE9BAbucblZu1S7BulPLRfs Bn1v0H13pAWAubC9RuKMTBiMuB1XRdGvkSNkdIibovsJ2T/C9JQhsJcG9e9Kc+Ur9cJY nIzw== X-Gm-Message-State: AOAM532ZBAelyNp/EJvajNe+ABtcJQdYyTWsIvjOlIEwDP3DkHnry+I6 HXh4BZxwSwPh6aMQiL46bu3eYS/xz0VBzw== X-Received: by 2002:a17:90a:4314:: with SMTP id q20mr2209139pjg.87.1611274420230; Thu, 21 Jan 2021 16:13:40 -0800 (PST) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id b13sm6941900pfi.162.2021.01.21.16.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 16:13:39 -0800 (PST) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka Subject: [PATCH BlueZ v2 1/2] input/hog: Fix double registering report value callbacks Date: Thu, 21 Jan 2021 16:13:25 -0800 Message-Id: <20210122001326.14263-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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; + report->notifyid = g_attrib_register(hog->attrib, ATT_OP_HANDLE_NOTIFY, report->value_handle, @@ -1703,6 +1711,8 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt) report_value_cb, r, NULL); } + hog->report_value_cb_registered = true; + return true; } @@ -1753,6 +1763,8 @@ void bt_hog_detach(struct bt_hog *hog) } } + hog->report_value_cb_registered = false; + if (hog->scpp) bt_scpp_detach(hog->scpp); -- 2.29.2