Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1766472pxa; Thu, 20 Aug 2020 21:36:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyv1rbs+xpw9jD3jrElm8njEZ7UK0GSIBVHaEGeyMRiSQUJf9uCLM3fFYI0LaNM55jtFXI X-Received: by 2002:a50:e802:: with SMTP id e2mr1005707edn.129.1597984590234; Thu, 20 Aug 2020 21:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597984590; cv=none; d=google.com; s=arc-20160816; b=Hy3iDNy1M4PAjvcrq2x00k6SZxIcR29MFR10OuVxwxS1AJBQBqQ7piRA2+jMwMCqNe 4xsg94P01D0Q8a84W8DaMlF87PPE36oKivNbuw2Ba3ZvDQ3nFVwjiT/AXpA7nd0HYFNX mKv+XEZBs9Kz5uNTh+mxShSTY1TeFJ9+ImmymzxZkD27V/2kclV58CD2g6IKEzFz08u3 tlcbrLl0rkJk6CtzJ3LmhjPYg14BId4+wfRKXzkIMpOJ7yhMtpo5FCmRVkCEEcy+Wd64 J4I3xvNjTP5tgo+LvDo5OXEisFHpZgjMzJu+LU3SjnfiEWBdyAv7Tw8enmDo99vkKZwO xfwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sOJTXZQPaj2OGZIiejwIYG5vJGEX+qQf5BT+/1KgjFE=; b=S46M1Fd0RDfeN0DMJlOHXENSS97mjZw3zV1HzH6TbIPGkz3bdzMON2EmMEz4xXtOk8 JRqZbjbZ3Zhb2oda426+yp3IaUbkcl/ItZqMe9S7eUVVIdj2KKw2q70qyrAfzkNW/qjY uwB42WkmwMIdHayd62CzZv6QujjIKQx8dsQp0ZpS0d4whLD875L4r5lnUIagqfzj0mnG Oypuz6vNUIU2nA0GPQd/NnNzu5YgwJb3h0Iqp3dztxvvu5IxJ6p4CnHDWqQ1E3QHPm/f dHY1KUkQIMaEjh5RjAqFPSJuSpJTGiwsZ1bZnxQM7Ao0WXYRwewgSblvsOG6pcqXj0mI Kpow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UJm0CjaS; 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 p6si394329edx.443.2020.08.20.21.35.44; Thu, 20 Aug 2020 21:36:30 -0700 (PDT) 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=UJm0CjaS; 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 S1725908AbgHUEfn (ORCPT + 99 others); Fri, 21 Aug 2020 00:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725855AbgHUEfl (ORCPT ); Fri, 21 Aug 2020 00:35:41 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68DC1C061385 for ; Thu, 20 Aug 2020 21:35:41 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id s14so329656plp.4 for ; Thu, 20 Aug 2020 21:35:41 -0700 (PDT) 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=sOJTXZQPaj2OGZIiejwIYG5vJGEX+qQf5BT+/1KgjFE=; b=UJm0CjaSFkOzg56uLjvFWNjhM7HporMyv++nrHK4lgfNo0QbBf84sHlOpJ0GK83Xg/ LV6orMEN7nZTjDEDeCCWm5cHZPBXZaQvl6tUnEvW9hx3cbxojyYsdgj5mDJI06PyuIjc 100YNueQmhKFvIvkEHYuy8s/51M3xa03dYgSo= 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=sOJTXZQPaj2OGZIiejwIYG5vJGEX+qQf5BT+/1KgjFE=; b=TuYajAgHqYNkDS4swwj3RytomgmbrAxyg1iNwKMDy4O+XGMvJdVL3hNZCBiOEPv8Hy 4W9B0DwsNJ/vJaL8YVhbPBJhDCic4MpbLlV/pLvWcHIF7p0s3pE1/Uh1OFetuPP9BV0a S2DpnwP6evTVkB1VqHO92NUvFHMaOkGRZlnmzZRoXyAfjM7kT6r85Oi74Tr5gYImxJHJ wBA7rkRELA1D7KTgXGWraXSvLLnRJe3JaH+MK0qiJW4Rundcz9fPKxfYv6TAQuKmvXvO IxC/XhA/AP4XYvIR9F1OBxPlcLD0TEO53xx6A9esAh9uYJh1366CadIcRMSafb/74m4g 6xgA== X-Gm-Message-State: AOAM531KeQpAqMJW7q8pomvOVMONcIRmBleKPeaaMeiAm51yHYiqQTIV wZm/ClgF2QPAOksSMyHLgjWMK4kK2NIzCg== X-Received: by 2002:a17:90b:4c03:: with SMTP id na3mr1047405pjb.29.1597984540086; Thu, 20 Aug 2020 21:35:40 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id d13sm557480pjz.3.2020.08.20.21.35.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2020 21:35:39 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Archie Pusaka Subject: [PATCH BlueZ] input/device: Unregister all UHID event listeners at UHID_DESTROY Date: Thu, 20 Aug 2020 21:35:36 -0700 Message-Id: <20200821043536.15332-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When destroying UHID, we should also unregister all event listeners so that they don't get double registered at reconnection. It fixes a bug where battery report is not available to kernel after reconnection and also prevents memory leak. Tested with Logitech M535 mouse: * Connect mouse to the device running BlueZ * cat /sys/class/power_supply/hid-{addr}-battery/capacity # works * Disconnect mouse * Reconnect mouse * cat /sys/class/power_supply/hid-{addr}-battery/capacity # still works Reviewed-by: Archie Pusaka --- profiles/input/device.c | 2 ++ src/shared/uhid.c | 9 +++++++++ src/shared/uhid.h | 1 + 3 files changed, 12 insertions(+) diff --git a/profiles/input/device.c b/profiles/input/device.c index 8fc04be37..f6823b7b6 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -982,6 +982,8 @@ static int uhid_disconnect(struct input_device *idev) if (!idev->uhid_created) return 0; + bt_uhid_unregister_all(idev->uhid); + memset(&ev, 0, sizeof(ev)); ev.type = UHID_DESTROY; diff --git a/src/shared/uhid.c b/src/shared/uhid.c index 685f90243..71a4e04ba 100644 --- a/src/shared/uhid.c +++ b/src/shared/uhid.c @@ -219,6 +219,15 @@ bool bt_uhid_unregister(struct bt_uhid *uhid, unsigned int id) return true; } +bool bt_uhid_unregister_all(struct bt_uhid *uhid) +{ + if (!uhid) + return false; + + queue_remove_all(uhid->notify_list, NULL, NULL, free); + return true; +} + int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev) { ssize_t len; diff --git a/src/shared/uhid.h b/src/shared/uhid.h index 459a24900..dbdca852d 100644 --- a/src/shared/uhid.h +++ b/src/shared/uhid.h @@ -40,5 +40,6 @@ typedef void (*bt_uhid_callback_t)(struct uhid_event *ev, void *user_data); unsigned int bt_uhid_register(struct bt_uhid *uhid, uint32_t event, bt_uhid_callback_t func, void *user_data); bool bt_uhid_unregister(struct bt_uhid *uhid, unsigned int id); +bool bt_uhid_unregister_all(struct bt_uhid *uhid); int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev); -- 2.26.2