]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 11 Aug 2025 09:19:06 +0000 (11:19 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sat, 27 Sep 2025 15:37:00 +0000 (11:37 -0400)
kzalloc() already zero-initializes the destination buffer 'data', making
strscpy() sufficient for safely copying 'name'. The additional
NUL-padding performed by strscpy_pad() is unnecessary.

Add a new local variable to store the length of 'name' and reuse it
instead of recalculating the same length.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
drivers/bluetooth/btintel_pcie.c

index 22a2953adbd66e2516664f4c0d9b166c2e35d491..a625a5b2154bd53c1aa12140bf6da635fde3c25e 100644 (file)
@@ -2242,6 +2242,7 @@ btintel_pcie_get_recovery(struct pci_dev *pdev, struct device *dev)
 {
        struct btintel_pcie_dev_recovery *tmp, *data = NULL;
        const char *name = pci_name(pdev);
+       const size_t name_len = strlen(name) + 1;
        struct hci_dev *hdev = to_hci_dev(dev);
 
        spin_lock(&btintel_pcie_recovery_lock);
@@ -2258,11 +2259,11 @@ btintel_pcie_get_recovery(struct pci_dev *pdev, struct device *dev)
                return data;
        }
 
-       data = kzalloc(struct_size(data, name, strlen(name) + 1), GFP_ATOMIC);
+       data = kzalloc(struct_size(data, name, name_len), GFP_ATOMIC);
        if (!data)
                return NULL;
 
-       strscpy_pad(data->name, name, strlen(name) + 1);
+       strscpy(data->name, name, name_len);
        spin_lock(&btintel_pcie_recovery_lock);
        list_add_tail(&data->list, &btintel_pcie_recovery_list);
        spin_unlock(&btintel_pcie_recovery_lock);