[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251026015710.1368-1-thorsten.blum@linux.dev>
Date: Sun, 26 Oct 2025 02:57:07 +0100
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: Giovanni Cabiddu <giovanni.cabiddu@...el.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
"David S. Miller" <davem@...emloft.net>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Jack Xu <jack.xu@...el.com>,
Suman Kumar Chakraborty <suman.kumar.chakraborty@...el.com>,
Qianfeng Rong <rongqianfeng@...o.com>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
qat-linux@...el.com,
linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] 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 <thorsten.blum@...ux.dev>
---
Changes in v2:
- Use simple_strtoull(), return -EINVAL, and guard against overflow as
suggested by Andy
- Link to v1: https://lore.kernel.org/lkml/20251022123622.349544-1-thorsten.blum@linux.dev/
---
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 18c3e4416dc5..06d49cb781ae 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.51.0
Powered by blists - more mailing lists