* [PATCH] crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user()
@ 2025-09-05 16:39 Thorsten Blum
2025-09-13 4:31 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-09-05 16:39 UTC (permalink / raw)
To: Giovanni Cabiddu, Herbert Xu, David S. Miller, Peter Zijlstra,
Greg KH
Cc: Thorsten Blum, qat-linux, linux-crypto, linux-kernel
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify adf_ctl_alloc_resources(). memdup_user() returns
either -ENOMEM or -EFAULT (instead of -EIO) if an error occurs.
Remove the unnecessary device id initialization, since memdup_user()
(like copy_from_user()) immediately overwrites it.
No functional changes intended other than returning the more idiomatic
error code -EFAULT.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c b/drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c
index 48c62a14a6a7..84bc89e16742 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c
@@ -94,17 +94,10 @@ static int adf_ctl_alloc_resources(struct adf_user_cfg_ctl_data **ctl_data,
{
struct adf_user_cfg_ctl_data *cfg_data;
- cfg_data = kzalloc(sizeof(*cfg_data), GFP_KERNEL);
- if (!cfg_data)
- return -ENOMEM;
-
- /* Initialize device id to NO DEVICE as 0 is a valid device id */
- cfg_data->device_id = ADF_CFG_NO_DEVICE;
-
- if (copy_from_user(cfg_data, (void __user *)arg, sizeof(*cfg_data))) {
+ cfg_data = memdup_user((void __user *)arg, sizeof(*cfg_data));
+ if (IS_ERR(cfg_data)) {
pr_err("QAT: failed to copy from user cfg_data.\n");
- kfree(cfg_data);
- return -EIO;
+ return PTR_ERR(cfg_data);
}
*ctl_data = cfg_data;
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user()
2025-09-05 16:39 [PATCH] crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user() Thorsten Blum
@ 2025-09-13 4:31 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2025-09-13 4:31 UTC (permalink / raw)
To: Thorsten Blum
Cc: Giovanni Cabiddu, David S. Miller, Peter Zijlstra, Greg KH,
qat-linux, linux-crypto, linux-kernel
On Fri, Sep 05, 2025 at 06:39:11PM +0200, Thorsten Blum wrote:
> Replace kzalloc() followed by copy_from_user() with memdup_user() to
> improve and simplify adf_ctl_alloc_resources(). memdup_user() returns
> either -ENOMEM or -EFAULT (instead of -EIO) if an error occurs.
>
> Remove the unnecessary device id initialization, since memdup_user()
> (like copy_from_user()) immediately overwrites it.
>
> No functional changes intended other than returning the more idiomatic
> error code -EFAULT.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
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] 2+ messages in thread
end of thread, other threads:[~2025-09-13 4:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05 16:39 [PATCH] crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user() Thorsten Blum
2025-09-13 4:31 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox