]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user()
authorThorsten Blum <thorsten.blum@linux.dev>
Fri, 5 Sep 2025 16:39:11 +0000 (18:39 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 13 Sep 2025 04:11:06 +0000 (12:11 +0800)
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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c

index 48c62a14a6a75bcadef21f7fba40cefc185034df..84bc89e167426f6fc91911e1902e948c7573ab92 100644 (file)
@@ -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;