From patchwork Fri Sep 15 23:47:41 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: 723343 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 3D241CD37AF for ; Fri, 15 Sep 2023 23:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237489AbjIOXr6 (ORCPT ); Fri, 15 Sep 2023 19:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235142AbjIOXrv (ORCPT ); Fri, 15 Sep 2023 19:47:51 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 453B82119 for ; Fri, 15 Sep 2023 16:47:46 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68a3ced3ec6so2480283b3a.1 for ; Fri, 15 Sep 2023 16:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694821665; x=1695426465; 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=FydRHNuSiU9lI0l5Le9Lmmb62FGr7xwRau34f1XeHkA=; b=He+8fYpkRIg97FEZlfDlYdxsMGqCLFzSUpLoqa/VUD7RMomQ4tHw1ndREKjGXUD9c+ BRXJHiXQ9zLbSKNUY8M0y/oH0GeqGVw/78YRtzU7dROwHUYeneyjvXcjE7ES1xoU6AKp d7A8U91GapLFTUpE1tfSDdjRlSV1kAranCRsRwLC9zzhMDkdNUhYiCam0N4dHkRe9DEp ZAbBEgToKbodWtHG3HbW9mj3VNAsK6XUuw00a1BFmma6Hc3J7zhx6XBYE1jIGXnX2jL8 F4rHsiYzjuIBdVJySrLrrLTiTY4eWMXA7aXKM8SQAIgV+oaNqkjd2pdn0xPjCbh0xtIM eG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694821665; x=1695426465; 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=FydRHNuSiU9lI0l5Le9Lmmb62FGr7xwRau34f1XeHkA=; b=pakLS5LF3Mfh3JuUFNzXQycc/+xAyIQggN6iRLRqlfeMvgU1BImVgxz2k0uANDGwz2 /WBB7sxAb6mTV86Yzwe5MiBD8xhMd0Sb/Rho8T2ygDyH/I7BPFFiEqMKGI1QhAehhVBw Hf7aAde2MsOYYE2N6QnPLFlIEzj2PklL9byLRb0ebyd6d6f6aQqmQePS/Oau04TnKBNM Y27sT4CSUgtqxBHszyIeabYbMPvUMk6nY156KN2L27K9rq/Rrn4tJZNs+YzzfA6/zPgo z2A05l71VSHHB0Y1zijW9a2gh6BAsNi2/Cm68EoDv63Dta1Wt7sRk1ghY+Je/4obyWKb RiLg== X-Gm-Message-State: AOJu0Yw2TZiCAroHZzThzm2sepj73AzukYo/jhkk/O7XwgBLdoDVUGPL TIT/C7YpcopfbYc1fatZr+z2FY1QxRk= X-Google-Smtp-Source: AGHT+IG1ttqC6eWr0cXDFdNd9RAq797rLgEm9E73CSxYkG7m/KkAR0SmfZDyVmqxmYMCb1Y7KF5l3w== X-Received: by 2002:a05:6a00:150e:b0:68a:5449:7436 with SMTP id q14-20020a056a00150e00b0068a54497436mr3460242pfu.32.1694821664983; Fri, 15 Sep 2023 16:47:44 -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 k22-20020aa790d6000000b0068fdb59e9d6sm3438129pfk.78.2023.09.15.16.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:47:44 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 1/2] Bluetooth: hci_core: Fix build warnings Date: Fri, 15 Sep 2023 16:47:41 -0700 Message-ID: <20230915234742.3739283-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 --- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_core.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index bbad301f5781..f36c1fd5d64e 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -350,7 +350,7 @@ struct hci_dev { struct list_head list; struct mutex lock; - char name[8]; + const char *name; unsigned long flags; __u16 id; __u8 bus; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index db4f28d68d71..9e89843c259b 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2617,7 +2617,11 @@ int hci_register_dev(struct hci_dev *hdev) if (id < 0) return id; - snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); + error = dev_set_name(&hdev->dev, "hci%u", id); + if (error) + return error; + + hdev->name = dev_name(&hdev->dev); hdev->id = id; BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); @@ -2639,8 +2643,6 @@ int hci_register_dev(struct hci_dev *hdev) if (!IS_ERR_OR_NULL(bt_debugfs)) hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); - dev_set_name(&hdev->dev, "%s", hdev->name); - error = device_add(&hdev->dev); if (error < 0) goto err_wqueue; From patchwork Fri Sep 15 23:47:42 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: 724211 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 3B9C0CD37AF for ; Fri, 15 Sep 2023 23:48:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235142AbjIOXs3 (ORCPT ); Fri, 15 Sep 2023 19:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235345AbjIOXr5 (ORCPT ); Fri, 15 Sep 2023 19:47:57 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 534542119 for ; Fri, 15 Sep 2023 16:47:48 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-79834a7a5d8so94037039f.3 for ; Fri, 15 Sep 2023 16:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694821667; x=1695426467; 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=gExfKyu4P+fXvrhV3DJ9X7Q/b/774ORr0erJfRAHkMQ=; b=e509Whwql6g42F0fL3Slzp4soqTaAs7heasjIwNIkfWl5JXA8GTCzIz+5iWXEEeYvI k0uOh/iyr3fLxYqsTprL6o0CVrX+D6iFupjIjT6WPse5UicsKrDGk2GEn8Fk4Tmc1wGr pygEcCbwVA9KsA9nwmDPQvX395bNCvlXt739PWn+HRcjX16GlAgwjQSxJodBzArAD/hS IddFNw4RMGyLLpwNfjYIvTR3Vr08aZ7fLSZWeN3cE4bD27aOwkD2F0CmRuLi0AfjmRC2 qhCXNFINQiCuJ3+egvsHts4silgXsWq6nRCTw8UK+G5f3tjLD9TvAP6c/ZQRe335LfMe 57hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694821667; x=1695426467; 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=gExfKyu4P+fXvrhV3DJ9X7Q/b/774ORr0erJfRAHkMQ=; b=TRz8cxGyZGlrpqTfqTn1kAwjWSjjRlko/Ux2Ea15WjyIlFQFzxZhTBbhyK4xT78uJW l3ttL41FTsqG/lPD5yvy5bhgZNSVW5FlCIlWVdo9YNQt/ZcB4kcg20UrwJ9j1UC2pDfP wYzItlslIS1UOs0dLuLtnLoVay22xGrKIT+O1BpDzz9BEzS1nD6yreYKMvB81yWo/L4W FqVrYDTL2dcPM1DZf7I4HzhnxwhbiMs+uuK3Wy7bq3l+xIxSzx9K1OtBr//LgTzLjFs9 rnvUGKZUG1SSDXh1uFDGBAmSsequnCUMaB5pj0iDNHjltJagUjTDvSk1iw7H7q0F+j6U 3hXg== X-Gm-Message-State: AOJu0Yw6dToAQcI0A8CKaWfOjfF2vQ3vGAEpcgkOE+wOKDHOXqGMsqpm fMt8dubmTuIdCdfPTxbeypLAoVbIrMU= X-Google-Smtp-Source: AGHT+IHXWhRHRayR7aQNSH7HbVJBr1XxZPSa5iy0u7LhQ7xJMvfsnD9dETY9FRw3zIVHMVcouFNakg== X-Received: by 2002:a05:6e02:b23:b0:34f:4300:8839 with SMTP id e3-20020a056e020b2300b0034f43008839mr4565828ilu.28.1694821666746; Fri, 15 Sep 2023 16:47:46 -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 k22-20020aa790d6000000b0068fdb59e9d6sm3438129pfk.78.2023.09.15.16.47.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:47:45 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 2/2] Bluetooth: hci_codec: Fix leaking content of local_codecs Date: Fri, 15 Sep 2023 16:47:42 -0700 Message-ID: <20230915234742.3739283-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915234742.3739283-1-luiz.dentz@gmail.com> References: <20230915234742.3739283-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 9e89843c259b..195aea2198a9 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2786,6 +2786,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;