Skip to contentSkip to conversation

Bluetooth: hci_core: Fix build warnings

PATCH Superseded Luiz Augusto von Dentz 2 participants 3 messages Sep 15, 2023 – Sep 16, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/2 Bluetooth: hci_core: Fix build warnings

From: Luiz Augusto von Dentz <[email protected]>

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);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 net/bluetooth/hci_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/hci_core.c +2 -1
index db4f28d68d71..5a7fb496297b 100644
@@ -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);
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH v2 2/2 Bluetooth: hci_codec: Fix leaking content of local_codecs

From: Luiz Augusto von Dentz <[email protected]>

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:
    [<ffffffffb324f557>] __kmalloc+0x47/0x120
    [<ffffffffb39ef37d>] hci_codec_list_add.isra.0+0x2d/0x160
    [<ffffffffb39ef643>] hci_read_codec_capabilities+0x183/0x270
    [<ffffffffb39ef9ab>] hci_read_supported_codecs+0x1bb/0x2d0
    [<ffffffffb39f162e>] hci_read_local_codecs_sync+0x3e/0x60
    [<ffffffffb39ff1b3>] hci_dev_open_sync+0x943/0x11e0
    [<ffffffffb396d55d>] hci_power_on+0x10d/0x3f0
    [<ffffffffb30c99b4>] process_one_work+0x404/0x800
    [<ffffffffb30ca134>] worker_thread+0x374/0x670
    [<ffffffffb30d9108>] kthread+0x188/0x1c0
    [<ffffffffb304db6b>] ret_from_fork+0x2b/0x50
    [<ffffffffb300206a>] ret_from_fork_asm+0x1a/0x30
Fixes 8961987f3f5f ("Bluetooth: Enumerate local supported codec and cache details")
---
 net/bluetooth/hci_core.c  | 1 +
 net/bluetooth/hci_event.c | 1 +
 net/bluetooth/hci_sync.c  | 1 +
 3 files changed, 3 insertions(+)
net/bluetooth/hci_core.c +1 -0
index 5a7fb496297b..956346dcbf82 100644
@@ -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);
net/bluetooth/hci_event.c +1 -0
index d532f4c139f9..d242f956dea8 100644
@@ -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"
net/bluetooth/hci_sync.c +1 -0
index 1be5763c261c..3640d73f9595 100644
@@ -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;
Signature · 1 line
2.41.0
#2 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=784857

---Test result---

Test Summary:

CheckPatch                    PASS      1.72 seconds
GitLint                       PASS      0.68 seconds
SubjectPrefix                 PASS      0.25 seconds
BuildKernel                   PASS      33.24 seconds
CheckAllWarning               PASS      36.14 seconds
CheckSparse                   WARNING   41.19 seconds
CheckSmatch                   WARNING   115.05 seconds
BuildKernel32                 PASS      31.70 seconds
TestRunnerSetup               PASS      488.47 seconds
TestRunner_l2cap-tester       PASS      29.48 seconds
TestRunner_iso-tester         PASS      58.00 seconds
TestRunner_bnep-tester        PASS      9.85 seconds
TestRunner_mgmt-tester        PASS      211.98 seconds
TestRunner_rfcomm-tester      PASS      15.07 seconds
TestRunner_sco-tester         PASS      18.45 seconds
TestRunner_ioctl-tester       PASS      16.89 seconds
TestRunner_mesh-tester        PASS      12.43 seconds
TestRunner_smp-tester         PASS      13.60 seconds
TestRunner_userchan-tester    PASS      10.41 seconds
IncrementalBuild              PASS      37.71 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):

---
Regards,
Linux Bluetooth