* [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof()
@ 2025-08-21 14:20 Qianfeng Rong
2025-08-21 15:40 ` Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-21 14:20 UTC (permalink / raw)
To: Giovanni Cabiddu, Herbert Xu, David S. Miller, Andy Shevchenko,
Jack Xu, Suman Kumar Chakraborty, Colin Ian King, qat-linux,
linux-crypto, linux-kernel
Cc: Qianfeng Rong
As noted in the kernel documentation [1], open-coded multiplication in
allocator arguments is discouraged because it can lead to integer overflow.
Use kcalloc() to gain built-in overflow protection, making memory
allocation safer when calculating allocation size compared to explicit
multiplication. Similarly, use size_add() instead of explicit addition
for 'uobj_chunk_num + sobj_chunk_num'.
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
v2: Changed explicit addition 'uobj_chunk_num + sobj_chunk_num' to use
size_add().
v3: Revise the version description to keep it consistent with the changes.
---
drivers/crypto/intel/qat/qat_common/qat_uclo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c
index 21d652a1c8ef..18c3e4416dc5 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c
@@ -1900,7 +1900,7 @@ static int qat_uclo_map_objs_from_mof(struct icp_qat_mof_handle *mobj_handle)
if (sobj_hdr)
sobj_chunk_num = sobj_hdr->num_chunks;
- mobj_hdr = kzalloc((uobj_chunk_num + sobj_chunk_num) *
+ mobj_hdr = kcalloc(size_add(uobj_chunk_num, sobj_chunk_num),
sizeof(*mobj_hdr), GFP_KERNEL);
if (!mobj_hdr)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof()
2025-08-21 14:20 [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof() Qianfeng Rong
@ 2025-08-21 15:40 ` Andy Shevchenko
2025-08-27 13:40 ` Giovanni Cabiddu
2025-08-30 8:53 ` Herbert Xu
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-08-21 15:40 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Giovanni Cabiddu, Herbert Xu, David S. Miller, Jack Xu,
Suman Kumar Chakraborty, Colin Ian King, qat-linux, linux-crypto,
linux-kernel
On Thu, Aug 21, 2025 at 10:20:26PM +0800, Qianfeng Rong wrote:
> As noted in the kernel documentation [1], open-coded multiplication in
> allocator arguments is discouraged because it can lead to integer overflow.
>
> Use kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication. Similarly, use size_add() instead of explicit addition
> for 'uobj_chunk_num + sobj_chunk_num'.
FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof()
2025-08-21 14:20 [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof() Qianfeng Rong
2025-08-21 15:40 ` Andy Shevchenko
@ 2025-08-27 13:40 ` Giovanni Cabiddu
2025-08-30 8:53 ` Herbert Xu
2 siblings, 0 replies; 4+ messages in thread
From: Giovanni Cabiddu @ 2025-08-27 13:40 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Herbert Xu, David S. Miller, Andy Shevchenko, Jack Xu,
Suman Kumar Chakraborty, Colin Ian King, qat-linux, linux-crypto,
linux-kernel
On Thu, Aug 21, 2025 at 10:20:26PM +0800, Qianfeng Rong wrote:
> As noted in the kernel documentation [1], open-coded multiplication in
> allocator arguments is discouraged because it can lead to integer overflow.
>
> Use kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication. Similarly, use size_add() instead of explicit addition
> for 'uobj_chunk_num + sobj_chunk_num'.
>
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Regards,
--
Giovanni
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof()
2025-08-21 14:20 [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof() Qianfeng Rong
2025-08-21 15:40 ` Andy Shevchenko
2025-08-27 13:40 ` Giovanni Cabiddu
@ 2025-08-30 8:53 ` Herbert Xu
2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2025-08-30 8:53 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Giovanni Cabiddu, David S. Miller, Andy Shevchenko, Jack Xu,
Suman Kumar Chakraborty, Colin Ian King, qat-linux, linux-crypto,
linux-kernel
On Thu, Aug 21, 2025 at 10:20:26PM +0800, Qianfeng Rong wrote:
> As noted in the kernel documentation [1], open-coded multiplication in
> allocator arguments is discouraged because it can lead to integer overflow.
>
> Use kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication. Similarly, use size_add() instead of explicit addition
> for 'uobj_chunk_num + sobj_chunk_num'.
>
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> v2: Changed explicit addition 'uobj_chunk_num + sobj_chunk_num' to use
> size_add().
> v3: Revise the version description to keep it consistent with the changes.
> ---
> drivers/crypto/intel/qat/qat_common/qat_uclo.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-30 8:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 14:20 [PATCH v3] crypto: qat - use kcalloc() in qat_uclo_map_objs_from_mof() Qianfeng Rong
2025-08-21 15:40 ` Andy Shevchenko
2025-08-27 13:40 ` Giovanni Cabiddu
2025-08-30 8:53 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).