From patchwork Fri Sep 15 23:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13387822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A95CCD37AF for ; Fri, 15 Sep 2023 23:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237994AbjIOXWM (ORCPT ); Fri, 15 Sep 2023 19:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237950AbjIOXVr (ORCPT ); Fri, 15 Sep 2023 19:21:47 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 211961FE0 for ; Fri, 15 Sep 2023 16:21:43 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so2126075a12.1 for ; Fri, 15 Sep 2023 16:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694820102; x=1695424902; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=oWovvwV6RqYuE0gLiBxHUd3cEuUE/+wFd/+K5yBGVao=; b=gTvqjIHgkjohzDZGoa/WpK4BSGSmNzERuKsyrB+CU5P5NP0g2AutqKrAlnen6VlrsF Dd1r2CYgOeDd5B00m9TFjhzzFsQBo2PBpSS6UYd/b7H9qPubDPpQqlrdlpqRDaNHUltc yExN4YOnbzzW67nlrqs1k03k0cbqQFr5MQQN7oAwfkZdPyGnkbb6xqUeWCfN0gq4i8hd bKlB7QGdSV/75ri5RCDyGXsQ1NpWyyS4Nm52hHSJMNcBpXxaUaMIgtJUyWxA6auppuDO biS8QpwYrCLrlO/413048ZXjImHgQSw7w353LvoijI5ikgMDrhMfbngI6+lXT2fJKGqi nOWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694820102; x=1695424902; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oWovvwV6RqYuE0gLiBxHUd3cEuUE/+wFd/+K5yBGVao=; b=ZepjeFHurn9zNdLu77igjZCB9Di0UbohGipH+blg7BhvN+Mf3y+akb4T4QWE5YFeq6 cQ+tseJOY/0X+v2ZAh3ReQv6ufdLA8oTOldRmayyaBwhqdW0osNenS6GmVAprO4c9xgk mFPy/bfO9epMVjvTTh3xl7C+P1/826NNX5g7kfDDvVV35ovJvE03I9DgBXPX32zATmlJ iTluDZoL/icm2u+ChF0cOHE5nZH2VUBH2275Ke3YDZ/ge0nX6+nKCd4ANwx6LjlyJ3y/ Kp2l4pmJvIsnkXOhZJEg8HAryOVNVc82Aa5PM2gezDFPGYX1i2d8fMr9c3FgQ91VPdlu +evQ== X-Gm-Message-State: AOJu0Yxir7oDHi5SPAppBsRiyLNC4x9cpTy7PaFun1Gkd08RwLFYTw/9 hnBSs8Cmasc5W0couThqwGELEZcYNa4= X-Google-Smtp-Source: AGHT+IEBBp1SaUN59SbayXg6+zV+oRMkhH7KlDFbk5v2lijYut7Wh0HkmkruOFIpZvdz0zd+tLBWqg== X-Received: by 2002:a05:6a20:914d:b0:159:ee33:12f with SMTP id x13-20020a056a20914d00b00159ee33012fmr3743406pzc.56.1694820101877; Fri, 15 Sep 2023 16:21:41 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id p24-20020aa78618000000b0068746ab9aebsm3583212pfn.14.2023.09.15.16.21.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:21:40 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/2] Bluetooth: hci_core: Fix build warnings Date: Fri, 15 Sep 2023 16:21:38 -0700 Message-ID: <20230915232139.3661778-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This fixes the following warnings: net/bluetooth/hci_core.c: In function ‘hci_register_dev’: net/bluetooth/hci_core.c:2620:54: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 5 [-Wformat-truncation=] 2620 | snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); | ^~ net/bluetooth/hci_core.c:2620:50: note: directive argument in the range [0, 2147483647] 2620 | snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); | ^~~~~~~ net/bluetooth/hci_core.c:2620:9: note: ‘snprintf’ output between 5 and 14 bytes into a destination of size 8 2620 | snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index db4f28d68d71..5a7fb496297b 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2617,7 +2617,8 @@ int hci_register_dev(struct hci_dev *hdev) if (id < 0) return id; - snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); + snprintf(hdev->name, sizeof(hdev->name), "hci%u", + id ? id % HCI_MAX_ID : id); hdev->id = id; BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); From patchwork Fri Sep 15 23:21:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13387823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80B29C46CA1 for ; Fri, 15 Sep 2023 23:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238005AbjIOXWN (ORCPT ); Fri, 15 Sep 2023 19:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238001AbjIOXVu (ORCPT ); Fri, 15 Sep 2023 19:21:50 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1F6C1FE0 for ; Fri, 15 Sep 2023 16:21:44 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-68fe2470d81so2443974b3a.1 for ; Fri, 15 Sep 2023 16:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694820103; x=1695424903; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1YMwtIxdzoz0GddQJf6BDXnPkXKHzTmRRJmREH4GHjM=; b=UUjA5N7L53BPWi+X+SqlbZ+wPAYlZSaQNgBnvdTH+VBX9Xm7Zn/nG+b3Nn/O8PL0i5 u8U/Z6pXeLH140xUuNtZwZYM6Xoh4VS6AcMdrzwHZOS/an3TAgPY3vXPTzfXG1oz9U6f xedzO8TQTjmMWrDPJ5eHgSf5sd7Ky1dRb3yz0v0RF4+AwEeT7dUSl8/AwTJ7QsOaeJHb m5C8v491SCMSfB2PT1UHWILS3KSqXvEpj/jQdNVC9/3ugZls0lb5OlcLwUcA8Pa/d4K4 +N5jcrh9beotDkD6EzffYG1gk83W6400y4PpiZLfOe7GVhe1fK1Ea4oUmEw9EuB3SM1f z8vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694820103; x=1695424903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1YMwtIxdzoz0GddQJf6BDXnPkXKHzTmRRJmREH4GHjM=; b=OFc+8siV66nGQnHFwh820A728JEfgE//+aWVaMEAwbzGsoMvsTfUEx/s4JfFvukGdC t7Pqc7fWEyMVilNtVGLrMZyCj8qggFEUhUN5+KEj8m/6RbGDp8RJIsyS6KOec7tl4gqn arue7meNMNYsAomaq0zh2E911cmGi0jq25cNuSJk+DEJYRip+yMYfC9XjYT1fvuyQ6x3 y8qPHMkrv3fKXM4JrfVOT/lhSaYsZhg7jSXWkEjYSm+fAknw9f8QA1m0yIL2Q1g9DRJc 21wbhVTqiavI0H+6BOhmkahyVb5c7DqpMsJ5+6N8YWwZIoOVXrbCUihn7x3h3iJFeSVP FzTA== X-Gm-Message-State: AOJu0YzI/y5A2vD/fzsrv5chvP4rO8kss2LLTwDAuRSAh0c1XsjrVmTC NFNbi8JkGLUVDAT0QT+5hKaDLxL+U+Q= X-Google-Smtp-Source: AGHT+IEG7BkX7Nfp6bcnQGmRb43MTvjOBuTE70PvLFDVSGeEXcBQ3YUJbVBpLu0pbbMerwKx3YwZzA== X-Received: by 2002:a05:6a00:1a86:b0:68f:bbc3:df44 with SMTP id e6-20020a056a001a8600b0068fbbc3df44mr3663619pfv.0.1694820103583; Fri, 15 Sep 2023 16:21:43 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id p24-20020aa78618000000b0068746ab9aebsm3583212pfn.14.2023.09.15.16.21.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:21:42 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 2/2] Bluetooth: hci_codec: Fix leaking content of local_codecs Date: Fri, 15 Sep 2023 16:21:39 -0700 Message-ID: <20230915232139.3661778-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915232139.3661778-1-luiz.dentz@gmail.com> References: <20230915232139.3661778-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz The following memory leak can be observed when the controller supports codecs which are stored in local_codecs list but the elements are never freed: unreferenced object 0xffff88800221d840 (size 32): comm "kworker/u3:0", pid 36, jiffies 4294898739 (age 127.060s) hex dump (first 32 bytes): f8 d3 02 03 80 88 ff ff 80 d8 21 02 80 88 ff ff ..........!..... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] __kmalloc+0x47/0x120 [] hci_codec_list_add.isra.0+0x2d/0x160 [] hci_read_codec_capabilities+0x183/0x270 [] hci_read_supported_codecs+0x1bb/0x2d0 [] hci_read_local_codecs_sync+0x3e/0x60 [] hci_dev_open_sync+0x943/0x11e0 [] hci_power_on+0x10d/0x3f0 [] process_one_work+0x404/0x800 [] worker_thread+0x374/0x670 [] kthread+0x188/0x1c0 [] ret_from_fork+0x2b/0x50 [] ret_from_fork_asm+0x1a/0x30 Cc: stable@vger.kernel.org Fixes: 8961987f3f5f ("Bluetooth: Enumerate local supported codec and cache details") Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_core.c | 1 + net/bluetooth/hci_event.c | 1 + net/bluetooth/hci_sync.c | 1 + 3 files changed, 3 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 5a7fb496297b..956346dcbf82 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2785,6 +2785,7 @@ void hci_release_dev(struct hci_dev *hdev) hci_conn_params_clear_all(hdev); hci_discovery_filter_clear(hdev); hci_blocked_keys_clear(hdev); + hci_codec_list_clear(&hdev->local_codecs); hci_dev_unlock(hdev); ida_simple_remove(&hci_index_ida, hdev->id); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index d532f4c139f9..d242f956dea8 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -33,6 +33,7 @@ #include "hci_request.h" #include "hci_debugfs.h" +#include "hci_codec.h" #include "a2mp.h" #include "amp.h" #include "smp.h" diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 1be5763c261c..3640d73f9595 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5074,6 +5074,7 @@ int hci_dev_close_sync(struct hci_dev *hdev) memset(hdev->eir, 0, sizeof(hdev->eir)); memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); bacpy(&hdev->random_addr, BDADDR_ANY); + hci_codec_list_clear(&hdev->local_codecs); hci_dev_put(hdev); return err;