linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
@ 2025-08-11  9:19 Thorsten Blum
  2025-08-11 10:01 ` Paul Menzel
  2025-08-11 16:16 ` patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-08-11  9:19 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Thorsten Blum, linux-bluetooth, linux-kernel

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>
---
 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 6e7bbbd35279..aad03f8a3e13 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -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);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
  2025-08-11  9:19 [PATCH] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad() Thorsten Blum
@ 2025-08-11 10:01 ` Paul Menzel
  2025-08-11 16:16 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Menzel @ 2025-08-11 10:01 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, linux-bluetooth,
	linux-kernel

Dear Thorsten,


Thank you for the patch.


Am 11.08.25 um 11:19 schrieb Thorsten Blum:
> 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>
> ---
>   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 6e7bbbd35279..aad03f8a3e13 100644
> --- a/drivers/bluetooth/btintel_pcie.c
> +++ b/drivers/bluetooth/btintel_pcie.c
> @@ -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);

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad()
  2025-08-11  9:19 [PATCH] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad() Thorsten Blum
  2025-08-11 10:01 ` Paul Menzel
@ 2025-08-11 16:16 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2025-08-11 16:16 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 11 Aug 2025 11:19:06 +0200 you wrote:
> 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.
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-11 16:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11  9:19 [PATCH] Bluetooth: btintel_pcie: Use strscpy() instead of strscpy_pad() Thorsten Blum
2025-08-11 10:01 ` Paul Menzel
2025-08-11 16:16 ` patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).