linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
@ 2025-08-10 22:58 Thorsten Blum
  2025-08-11 15:37 ` Dave Jiang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thorsten Blum @ 2025-08-10 22:58 UTC (permalink / raw)
  To: Vinicius Costa Gomes, Dave Jiang, Vinod Koul
  Cc: Thorsten Blum, dmaengine, linux-kernel

Replace memset(0) followed by strscpy() with strscpy_pad() to improve
idxd_load_iaa_device_defaults(). This avoids zeroing the memory before
copying the strings and ensures the destination buffers are only written
to once, simplifying the code and improving efficiency.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/dma/idxd/defaults.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/idxd/defaults.c b/drivers/dma/idxd/defaults.c
index c607ae8dd12c..2bbbcd02a0da 100644
--- a/drivers/dma/idxd/defaults.c
+++ b/drivers/dma/idxd/defaults.c
@@ -36,12 +36,10 @@ int idxd_load_iaa_device_defaults(struct idxd_device *idxd)
 	group->num_wqs++;
 
 	/* set name to "iaa_crypto" */
-	memset(wq->name, 0, WQ_NAME_SIZE + 1);
-	strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1);
+	strscpy_pad(wq->name, "iaa_crypto");
 
 	/* set driver_name to "crypto" */
-	memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1);
-	strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1);
+	strscpy_pad(wq->driver_name, "crypto");
 
 	engine = idxd->engines[0];
 
-- 
2.50.1


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

* Re: [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
  2025-08-10 22:58 [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad() Thorsten Blum
@ 2025-08-11 15:37 ` Dave Jiang
  2025-08-11 15:57   ` Thorsten Blum
  2025-08-11 16:02 ` Dave Jiang
  2025-08-20 17:42 ` Vinod Koul
  2 siblings, 1 reply; 5+ messages in thread
From: Dave Jiang @ 2025-08-11 15:37 UTC (permalink / raw)
  To: Thorsten Blum, Vinicius Costa Gomes, Vinod Koul; +Cc: dmaengine, linux-kernel



On 8/10/25 3:58 PM, Thorsten Blum wrote:
> Replace memset(0) followed by strscpy() with strscpy_pad() to improve
> idxd_load_iaa_device_defaults(). This avoids zeroing the memory before
> copying the strings and ensures the destination buffers are only written
> to once, simplifying the code and improving efficiency.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/dma/idxd/defaults.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma/idxd/defaults.c b/drivers/dma/idxd/defaults.c
> index c607ae8dd12c..2bbbcd02a0da 100644
> --- a/drivers/dma/idxd/defaults.c
> +++ b/drivers/dma/idxd/defaults.c
> @@ -36,12 +36,10 @@ int idxd_load_iaa_device_defaults(struct idxd_device *idxd)
>  	group->num_wqs++;
>  
>  	/* set name to "iaa_crypto" */
> -	memset(wq->name, 0, WQ_NAME_SIZE + 1);
> -	strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1);
> +	strscpy_pad(wq->name, "iaa_crypto");

Should also supply the max length?

>  
>  	/* set driver_name to "crypto" */
> -	memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1);
> -	strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1);
> +	strscpy_pad(wq->driver_name, "crypto");
>  
>  	engine = idxd->engines[0];
>  


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

* Re: [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
  2025-08-11 15:37 ` Dave Jiang
@ 2025-08-11 15:57   ` Thorsten Blum
  0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2025-08-11 15:57 UTC (permalink / raw)
  To: Dave Jiang; +Cc: Vinicius Costa Gomes, Vinod Koul, dmaengine, linux-kernel

Hi Dave,

> On 11. Aug 2025, at 17:37, Dave Jiang wrote:
>> 	/* set name to "iaa_crypto" */
>> -	memset(wq->name, 0, WQ_NAME_SIZE + 1);
>> -	strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1);
>> +	strscpy_pad(wq->name, "iaa_crypto");
> 
> Should also supply the max length?

The third argument of strscpy_pad() is optional when the destination
buffer has a fixed size. strscpy_pad() can then infer the size using
sizeof(), which equals 'WQ_NAME_SIZE + 1' and 'DRIVER_NAME_SIZE + 1',
respectively.

Thanks,
Thorsten


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

* Re: [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
  2025-08-10 22:58 [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad() Thorsten Blum
  2025-08-11 15:37 ` Dave Jiang
@ 2025-08-11 16:02 ` Dave Jiang
  2025-08-20 17:42 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2025-08-11 16:02 UTC (permalink / raw)
  To: Thorsten Blum, Vinicius Costa Gomes, Vinod Koul; +Cc: dmaengine, linux-kernel



On 8/10/25 3:58 PM, Thorsten Blum wrote:
> Replace memset(0) followed by strscpy() with strscpy_pad() to improve
> idxd_load_iaa_device_defaults(). This avoids zeroing the memory before
> copying the strings and ensures the destination buffers are only written
> to once, simplifying the code and improving efficiency.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/dma/idxd/defaults.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma/idxd/defaults.c b/drivers/dma/idxd/defaults.c
> index c607ae8dd12c..2bbbcd02a0da 100644
> --- a/drivers/dma/idxd/defaults.c
> +++ b/drivers/dma/idxd/defaults.c
> @@ -36,12 +36,10 @@ int idxd_load_iaa_device_defaults(struct idxd_device *idxd)
>  	group->num_wqs++;
>  
>  	/* set name to "iaa_crypto" */
> -	memset(wq->name, 0, WQ_NAME_SIZE + 1);
> -	strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1);
> +	strscpy_pad(wq->name, "iaa_crypto");
>  
>  	/* set driver_name to "crypto" */
> -	memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1);
> -	strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1);
> +	strscpy_pad(wq->driver_name, "crypto");
>  
>  	engine = idxd->engines[0];
>  


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

* Re: [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
  2025-08-10 22:58 [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad() Thorsten Blum
  2025-08-11 15:37 ` Dave Jiang
  2025-08-11 16:02 ` Dave Jiang
@ 2025-08-20 17:42 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2025-08-20 17:42 UTC (permalink / raw)
  To: Vinicius Costa Gomes, Dave Jiang, Thorsten Blum; +Cc: dmaengine, linux-kernel


On Mon, 11 Aug 2025 00:58:59 +0200, Thorsten Blum wrote:
> Replace memset(0) followed by strscpy() with strscpy_pad() to improve
> idxd_load_iaa_device_defaults(). This avoids zeroing the memory before
> copying the strings and ensures the destination buffers are only written
> to once, simplifying the code and improving efficiency.
> 
> 

Applied, thanks!

[1/1] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
      commit: 847164d47098f55e99503819300b36cca20cb4f7

Best regards,
-- 
~Vinod



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

end of thread, other threads:[~2025-08-20 17:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 22:58 [PATCH] dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad() Thorsten Blum
2025-08-11 15:37 ` Dave Jiang
2025-08-11 15:57   ` Thorsten Blum
2025-08-11 16:02 ` Dave Jiang
2025-08-20 17:42 ` Vinod Koul

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).