Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
PATCH 1/1 Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
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.
--- drivers/bluetooth/btintel_pcie.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/bluetooth/btintel_pcie.c +3 -2
@@ -2236,6 +2236,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);
@@ -2252,11 +2253,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);
Signature · 1 line
2.50.1
Dear Thorsten,
Thank you for the patch.
Am 11.08.25 um 11:19 schrieb Thorsten Blum:
Quoted 28 lines
kzalloc()already zero-initializes the destination buffer 'data', makingstrscpy()sufficient for safely copying 'name'. The additional NUL-padding performed bystrscpy_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 <[email protected]>--- drivers/bluetooth/btintel_pcie.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/bluetooth/btintel_pcie.c +1
-0@@ -2236,6 +2236,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);@@ -2252,11 +2253,11 @@ btintel_pcie_get_recovery(struct pci_dev *pdev, struct device *dev)return data; }
drivers/bluetooth/btintel_pcie.c btintel_pcie_get_recovery(struct pci_dev *pdev, struct device *dev) · line 2263
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +2
-2- 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);
Kind regards,
Paul
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 8 lines · On Mon, 11 Aug 2025 11:19:06 +0200 you wrote:
kzalloc()already zero-initializes the destination buffer 'data', makingstrscpy()sufficient for safely copying 'name'. The additional NUL-padding performed bystrscpy_pad()is unnecessary.Add a new local variable to store the length of 'name' and reuse it instead of recalculating the same length.
[...]
Here is the summary with links:
- Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
https://git.kernel.org/bluetooth/bluetooth-next/c/523024537985
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html