public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: qat - use strscpy_pad to simplify buffer initialization
@ 2025-10-22 12:36 Thorsten Blum
  2025-10-22 18:17 ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Thorsten Blum @ 2025-10-22 12:36 UTC (permalink / raw)
  To: Giovanni Cabiddu, Herbert Xu, David S. Miller, Andy Shevchenko,
	Jack Xu, Suman Kumar Chakraborty, Qianfeng Rong
  Cc: Thorsten Blum, qat-linux, linux-crypto, linux-kernel

Use strscpy_pad() to copy the string and zero-pad the destination buffer
in a single step instead of zero-initializing the buffer first and then
immediately overwriting it using strscpy().

Replace the magic number 16 with sizeof(buf) and remove the redundant
parentheses around kstrtoul() while we're at it.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/crypto/intel/qat/qat_common/qat_uclo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c
index 18c3e4416dc5..41a7bd434e97 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c
@@ -200,18 +200,18 @@ qat_uclo_cleanup_batch_init_list(struct icp_qat_fw_loader_handle *handle,
 
 static int qat_uclo_parse_num(char *str, unsigned int *num)
 {
-	char buf[16] = {0};
+	char buf[16] = {};
 	unsigned long ae = 0;
 	int i;
 
-	strscpy(buf, str, sizeof(buf));
-	for (i = 0; i < 16; i++) {
+	strscpy_pad(buf, str);
+	for (i = 0; i < sizeof(buf); i++) {
 		if (!isdigit(buf[i])) {
 			buf[i] = '\0';
 			break;
 		}
 	}
-	if ((kstrtoul(buf, 10, &ae)))
+	if (kstrtoul(buf, 10, &ae))
 		return -EFAULT;
 
 	*num = (unsigned int)ae;
-- 
2.51.0


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

end of thread, other threads:[~2025-10-27  8:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 12:36 [PATCH] crypto: qat - use strscpy_pad to simplify buffer initialization Thorsten Blum
2025-10-22 18:17 ` Andy Shevchenko
2025-10-22 18:29   ` Andy Shevchenko
2025-10-23 15:35   ` Thorsten Blum
2025-10-23 18:44     ` Andy Shevchenko
2025-10-24  8:50       ` Giovanni Cabiddu
2025-10-24  9:49         ` Andy Shevchenko
2025-10-24 18:47       ` Thorsten Blum
2025-10-27  8:19         ` Andy Shevchenko
2025-10-27  8:43           ` Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox