Bluetooth: hci_core: Fix build warnings
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 15 Sep 2023 21:42:27 +0000 (14:42 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 20 Sep 2023 18:02:41 +0000 (11:02 -0700)
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 <luiz.von.dentz@intel.com>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c

index e6359f7..c33348b 100644 (file)
@@ -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;
index db4f28d..9e89843 100644 (file)
@@ -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;