Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Thorsten Blum and committed by
Herbert Xu
1e263397 9048beca

+3 -10
+3 -10
drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c
··· 94 94 { 95 95 struct adf_user_cfg_ctl_data *cfg_data; 96 96 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)) { 105 99 pr_err("QAT: failed to copy from user cfg_data.\n"); 106 - kfree(cfg_data); 107 - return -EIO; 100 + return PTR_ERR(cfg_data); 108 101 } 109 102 110 103 *ctl_data = cfg_data;