Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3706448ybz; Mon, 20 Apr 2020 08:02:28 -0700 (PDT) X-Google-Smtp-Source: APiQypLWgUSX5itivDpL2Yf3Rh0XrBlu1XpyrfN9XWmZ/V69CyFkO4nav/zKneaWh6rREa2qJyrC X-Received: by 2002:a50:cf4d:: with SMTP id d13mr14949535edk.175.1587394947867; Mon, 20 Apr 2020 08:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587394947; cv=none; d=google.com; s=arc-20160816; b=XQJQ/sifKc6At64p92dATRkUNHr+URmHxrdZ+hCsTiMA7qjYs40jjjtYT1fWZQFkZ2 6UjSh5Inl7YhUNu3Nrg+NNjfBLqxj6szUuCo9CvVbI9L2ppvRpbyO1afRa45f8e3pBCE cJ/TOxJpekrRXX5AUiEd6BP7mnO+xxP6Ju9b2IEjsJ0NdfVVcjqDiRoka+TGwcxZgSK1 CB05M1FiH6YcijXhQrtG7yaUxpmVjHoLq7skM05p32uXwCczXzf19vjdGcsoSXwIGa6y +fRYfsBHhMPB9djmhpmCtDeQ/ur0Ytvme9KgVl1bFmGhSUM7iMZCxOXUtwfBmMJadLv6 ysGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=E83LCCR5OyAVEEQDzw3BZGT3kp3WGHgCveGTY6HYQls=; b=r9bR1MoU7TG54loy8EgK1DZMMKcrJt7GNmn47f90bB+/s79wVUwdpCxVjT1NLDCvyR 2pOmsa6WgdQkCmdXdEFJb5491OwN9oBW3sP6P9FOAgdHLSjqWcI7yj1vG9O0uZmZsBgq FUh8vnPZZvFWDgTIzHqnNtVyNWz/PF/e6/6zP8o5h8FQ1wTDLhxv7ethV4E0S9Gl1XaD QOfVBayFQ0H0AfilSaNmi68It3Vk92UkGPnNxV9ZkdiHje2ZhwA/a/PRxItJLjZiiJn3 jaJ+8y0C/KfpFSvDpVI2xX89PJVWCjr2LpqF4UO152TCA6f1d4cG+fZPF7HIaUgrjZLY LwmQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o19si724194edz.588.2020.04.20.08.01.31; Mon, 20 Apr 2020 08:02:27 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgDTNvg (ORCPT + 99 others); Mon, 20 Apr 2020 09:51:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727046AbgDTNve (ORCPT ); Mon, 20 Apr 2020 09:51:34 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 684BDC061A0C for ; Mon, 20 Apr 2020 06:51:34 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: scerveau) with ESMTPSA id 2DEC52A0484 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= To: linux-bluetooth@vger.kernel.org Cc: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Subject: [PATCH 1/1] add hog ref before adding to instances Date: Mon, 20 Apr 2020 15:51:12 +0200 Message-Id: <20200420135112.6749-2-scerveau@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200420135112.6749-1-scerveau@collabora.com> References: <20200420135112.6749-1-scerveau@collabora.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org To avoid a double hog free, need to add a ref when adding the hog to the slist. This bug has been reproduced with gamepad-8718 which was connecting/disconnecting frantically. Fix also a typo in the method hog_attach_instance --- profiles/input/hog-lib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 9c5c814a7..b9b5d565c 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -1357,7 +1357,7 @@ static struct bt_hog *hog_new(int fd, const char *name, uint16_t vendor, return hog; } -static void hog_attach_instace(struct bt_hog *hog, +static void hog_attach_instance(struct bt_hog *hog, struct gatt_db_attribute *attr) { struct bt_hog *instance; @@ -1373,14 +1373,14 @@ static void hog_attach_instace(struct bt_hog *hog, if (!instance) return; - hog->instances = g_slist_append(hog->instances, instance); + hog->instances = g_slist_append(hog->instances, bt_hog_ref(instance)); } static void foreach_hog_service(struct gatt_db_attribute *attr, void *user_data) { struct bt_hog *hog = user_data; - hog_attach_instace(hog, attr); + hog_attach_instance(hog, attr); } static void dis_notify(uint8_t source, uint16_t vendor, uint16_t product, @@ -1528,7 +1528,7 @@ static void hog_attach_hog(struct bt_hog *hog, struct gatt_primary *primary) primary->range.end, find_included_cb, instance); bt_hog_attach(instance, hog->attrib); - hog->instances = g_slist_append(hog->instances, instance); + hog->instances = g_slist_append(hog->instances, bt_hog_ref(instance)); } static void primary_cb(uint8_t status, GSList *services, void *user_data) -- 2.17.1