dmaengine: idxd: Replace memset(0) + strscpy() with strscpy_pad()
Subsystems (2)
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
@@ -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
Dave Jiang
reviewerQuoted 15 lines · Thorsten Blum
Replace memset(0) followed by
strscpy()withstrscpy_pad()to improveidxd_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 <[email protected]>--- drivers/dma/idxd/defaults.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/dma/idxd/defaults.c +0
-0
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 ];
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
Quoted 6 lines · Thorsten Blum
Replace memset(0) followed by
strscpy()withstrscpy_pad()to improveidxd_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 <[email protected]>
Quoted 23 lines
--- drivers/dma/idxd/defaults.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/dma/idxd/defaults.c +2
-4@@ -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 ];
Quoted 6 lines · Thorsten Blum
Replace memset(0) followed by
strscpy()withstrscpy_pad()to improveidxd_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