From d5b59ec33c5b6f6adb016d6210f8f5123be35b36 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Sun, 26 Oct 2025 02:57:07 +0100 Subject: [PATCH] crypto: qat - use simple_strtoull to improve qat_uclo_parse_num Replace the manual string copying and parsing logic with a call to simple_strtoull() to simplify and improve qat_uclo_parse_num(). Ensure that the parsed number does not exceed UINT_MAX, and add an approximate upper-bound check (no more than 19 digits) to guard against overflow. Signed-off-by: Thorsten Blum Acked-by: Giovanni Cabiddu Reviewed-by: Andy Shevchenko Signed-off-by: Herbert Xu --- drivers/crypto/intel/qat/qat_common/qat_uclo.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c index 18c3e4416dc51..06d49cb781ae8 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c +++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c @@ -200,20 +200,12 @@ 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}; - unsigned long ae = 0; - int i; - - strscpy(buf, str, sizeof(buf)); - for (i = 0; i < 16; i++) { - if (!isdigit(buf[i])) { - buf[i] = '\0'; - break; - } - } - if ((kstrtoul(buf, 10, &ae))) - return -EFAULT; + unsigned long long ae; + char *end; + ae = simple_strtoull(str, &end, 10); + if (ae > UINT_MAX || str == end || (end - str) > 19) + return -EINVAL; *num = (unsigned int)ae; return 0; } -- 2.47.3