Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp432140pxa; Fri, 21 Aug 2020 10:56:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzngX8ota3MqKMua7v//LUjh20ENY39GBINzFMj2He9AkyvR0IUmtBu1OdkDgzqKaWtQi8W X-Received: by 2002:a17:906:3f82:: with SMTP id b2mr4205921ejj.240.1598032579359; Fri, 21 Aug 2020 10:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598032579; cv=none; d=google.com; s=arc-20160816; b=RDD+73eUG+erJF23ZbPRFLp36liQljyspbLG8QX0wqOIyl3ah4L5gV0hrWK7Wbm14F EYis9tYTynaPCF9D7j4MNXwL6uO3tiDBZrYM7xdfuCohYfIJlZQANYWAiqb5V9Bukoh2 vVjXg0ip5k3H7hLk8eks9klRG7g0Bv9hZ9XCkbLliP+8aZlAEcZ9U9GCKnf/VNd/uYrz TANkZZTCybUbAN4nyPZkJJpqdxoCrv1WTJsS+FPJAtkQNT+cjdC145ZVLPKARqeTUKru lpQV1E/IkFvVpAOXx8+t32m8p1+Lqf/aRdXYWvxCw9wl8QQrJR/EYdprs2CmmFimvAky CA4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Krq1uDnHC4wEySxJ4sNYyv48cR1jwx55LtsrcUTUdZE=; b=KQKXAjKwm+RerHQ1IIZ/SYV8T0SNLxJSSls3Q7vcEqEpD+vB5hob0PV3WBQjW3PVTp PjeBfVGn+dEFSc/OKP9d5X4BjvlZ8Yb4SuBv0vCmp9mgJdn6q6aDn452SOoBOvPcOhh7 sTzY4Iq2Rwa351p5KIKOd5CvYLdrTFTBNt3vkuJ864gEPUZxGxgzJDMA3zDl4qGpk9ZK 9TVvrGY6BlhPE3iaJs70hHdDUAS5gYuKgycVB8+c6+vybzAPGb9tCv7UF0BX9/l+nWaV 0tKmDODxSf4Lu9g1GSa0sbsEKEx7TJUAYQA58HvdgFuRMLn50CU6iZud29bWUx4VqQfX rf/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jlRB7yns; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si1404497edl.114.2020.08.21.10.55.54; Fri, 21 Aug 2020 10:56:19 -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=@gmail.com header.s=20161025 header.b=jlRB7yns; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726793AbgHURyT (ORCPT + 99 others); Fri, 21 Aug 2020 13:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbgHURyR (ORCPT ); Fri, 21 Aug 2020 13:54:17 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50EB0C061573 for ; Fri, 21 Aug 2020 10:54:16 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id z22so2238382oid.1 for ; Fri, 21 Aug 2020 10:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Krq1uDnHC4wEySxJ4sNYyv48cR1jwx55LtsrcUTUdZE=; b=jlRB7yns4tl56g3y15Z89EioITiIjX8A6+EY/NtIF3+L9Bx+XClcTJf0irl1mYYf/1 J/t3XUdVwpPo8hDQmic4JSLJmacFy5JMg5uWIrvgi981v8dW+JgVESgFsw45rIeZ5rLE JSGkJrkV5xn4lhSUGGtKW/hMNU7OJys+vvTtBU7ONW5hm4g3gyQzTpsYu18gdkVjV+7C gtpubHDvsqxdLarpqWnnLXV+ehrEeociZgiAubL1Z3hTTX4/v6hInsB4OPraxxpUPJO4 7k9TfcHWc89in6ioEjHgtjbI4S7Xh4NbFOJxVNPCsE9zhCaPh/m7ZwzmEvcP0+iyiqBP 9aYw== 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=Krq1uDnHC4wEySxJ4sNYyv48cR1jwx55LtsrcUTUdZE=; b=j4K4uQVw7rtBH+SDi4aRGXSwrd/TFVGaeLZCltTebuJ20uEIr6oWYXTfayPGstj3lE AgKCZetGU93Dd7+2SUMFWZbO/HEopFmoHhugzHGV+oXrhPTPwJk9qcABF0IVNdpZxzCm 28F0L6UzGI1cZGCIopOEXfkJNXlN9RFCfVqauXibifiGHM1o/papFT39Wh3B3Da0InHO nEYC0xlnlHlOFegRLutcsO3ez/2oliZJzJXg2amVA2UTwx5yh/1p68qzjmbIMfhiQkyN eBENkI/kSzoRA5e+FtPw4kwjLnuQNIWqiqGZPk1z/PpRGw3DrMe0c9wdU8e2opUHEUzN NzUg== X-Gm-Message-State: AOAM53357cvYBHrup3SVghn7i8mpwYLh4KLzlF/PHzNiwK7M/IDzTCuh HtUsItp7AB6C4zQ9vCdyN0xpTd8nUM8njvLffXopkPYE X-Received: by 2002:aca:cc50:: with SMTP id c77mr2398823oig.152.1598032455928; Fri, 21 Aug 2020 10:54:15 -0700 (PDT) MIME-Version: 1.0 References: <20200821043536.15332-1-sonnysasaka@chromium.org> In-Reply-To: <20200821043536.15332-1-sonnysasaka@chromium.org> From: Luiz Augusto von Dentz Date: Fri, 21 Aug 2020 10:54:05 -0700 Message-ID: Subject: Re: [PATCH BlueZ] input/device: Unregister all UHID event listeners at UHID_DESTROY To: Sonny Sasaka Cc: "linux-bluetooth@vger.kernel.org" , Archie Pusaka Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Sonny, On Thu, Aug 20, 2020 at 9:38 PM Sonny Sasaka wrote: > > 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 Applied, thanks. -- Luiz Augusto von Dentz