Skip to content

Commit 1e26339

Browse files
tobluxherbertx
authored andcommitted
crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user()
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>
1 parent 9048bec commit 1e26339

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,10 @@ static int adf_ctl_alloc_resources(struct adf_user_cfg_ctl_data **ctl_data,
9494
{
9595
struct adf_user_cfg_ctl_data *cfg_data;
9696

97-
cfg_data = kzalloc(sizeof(*cfg_data), GFP_KERNEL);
98-
if (!cfg_data)
99-
return -ENOMEM;
100-
101-
/* Initialize device id to NO DEVICE as 0 is a valid device id */
102-
cfg_data->device_id = ADF_CFG_NO_DEVICE;
103-
104-
if (copy_from_user(cfg_data, (void __user *)arg, sizeof(*cfg_data))) {
97+
cfg_data = memdup_user((void __user *)arg, sizeof(*cfg_data));
98+
if (IS_ERR(cfg_data)) {
10599
pr_err("QAT: failed to copy from user cfg_data.\n");
106-
kfree(cfg_data);
107-
return -EIO;
100+
return PTR_ERR(cfg_data);
108101
}
109102

110103
*ctl_data = cfg_data;

0 commit comments

Comments
 (0)