[SRU][Questing][PATCH 3/5] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()

You-Sheng Yang vicamo.yang at canonical.com
Tue Jan 20 08:38:01 UTC 2026


From: Thorsten Blum <thorsten.blum at linux.dev>

BugLink: https://bugs.launchpad.net/bugs/2136804

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 at linux.dev>
Reviewed-by: Paul Menzel <pmenzel at molgen.mpg.de>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz at intel.com>
(cherry picked from commit 5967c08545e9d591e06c205b74fd25f8a702029c)
Signed-off-by: You-Sheng Yang <vicamo.yang at canonical.com>
Acked-by: Kuan-Ying Lee <kuan-ying.lee at canonical.com>
Acked-by: Chia-Lin Kao (AceLan) <chia-lin.kao at canonical.com>
Signed-off-by: Kuan-Ying Lee <kuan-ying.lee at canonical.com>
---
 drivers/bluetooth/btintel_pcie.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index 36fa95cc38335..a075d8ec46773 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -2174,6 +2174,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);
@@ -2190,11 +2191,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);
-- 
2.51.0




More information about the kernel-team mailing list