Skip to contentSkip to conversation

dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()

PATCH Applied Thorsten Blum 3 participants 5 messages Aug 10, 2025 – Aug 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()

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.

---
 drivers/dma/idxd/defaults.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dma/idxd/defaults.c +2 -4
index c607ae8dd12c..2bbbcd02a0da 100644
@@ -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];
 
Signature · 1 line
2.50.1
reviewer
#1 lore raw
Quoted 15 lines · Thorsten Blum

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.

---
 drivers/dma/idxd/defaults.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dma/idxd/defaults.c +0 -0
index c607ae8dd12c..2bbbcd02a0da 100644

drivers/dma/idxd/defaults.c int idxd_load_iaa_device_defaults(struct idxd_device *idxd) · line 39

Quoted 6 lines
drivers/dma/idxd/defaults.c +1 -2
@@ -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?

Quoted 8 lines
drivers/dma/idxd/defaults.c +1 -2
 	/* 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 lore raw

Hi Dave,

Quoted 7 lines · Dave Jiang

drivers/dma/idxd/defaults.c int idxd_load_iaa_device_defaults(struct idxd_device *idxd) · line 39

Quoted 4 lines
	/* set name to "iaa_crypto" */
drivers/dma/idxd/defaults.c +1 -2
-	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

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Thorsten Blum
Quoted 6 lines · Thorsten Blum

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.

Quoted 23 lines
---
 drivers/dma/idxd/defaults.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dma/idxd/defaults.c +2 -4
index c607ae8dd12c..2bbbcd02a0da 100644
@@ -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];
 
maintainer Applied
#4 lore raw
In reply to Thorsten Blum
Quoted 6 lines · Thorsten Blum

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,

Signature · 1 line
~Vinod