Skip to content

Commit 5ce9891

Browse files
committed
crypto: qat - Return pointer directly in adf_ctl_alloc_resources
Returning values through arguments is confusing and that has upset the compiler with the recent change to memdup_user: ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c: In function ‘adf_ctl_ioctl’: ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:308:26: warning: ‘ctl_data’ may be used uninitialized [-Wmaybe-uninitialized] 308 | ctl_data->device_id); | ^~ ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:294:39: note: ‘ctl_data’ was declared here 294 | struct adf_user_cfg_ctl_data *ctl_data; | ^~~~~~~~ In function ‘adf_ctl_ioctl_dev_stop’, inlined from ‘adf_ctl_ioctl’ at ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:386:9: ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:273:48: warning: ‘ctl_data’ may be used uninitialized [-Wmaybe-uninitialized] 273 | ret = adf_ctl_is_device_in_use(ctl_data->device_id); | ~~~~~~~~^~~~~~~~~~~ ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c: In function ‘adf_ctl_ioctl’: ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:261:39: note: ‘ctl_data’ was declared here 261 | struct adf_user_cfg_ctl_data *ctl_data; | ^~~~~~~~ In function ‘adf_ctl_ioctl_dev_config’, inlined from ‘adf_ctl_ioctl’ at ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:382:9: ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:192:54: warning: ‘ctl_data’ may be used uninitialized [-Wmaybe-uninitialized] 192 | accel_dev = adf_devmgr_get_dev_by_id(ctl_data->device_id); | ~~~~~~~~^~~~~~~~~~~ ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c: In function ‘adf_ctl_ioctl’: ../drivers/crypto/intel/qat/qat_common/adf_ctl_drv.c:185:39: note: ‘ctl_data’ was declared here 185 | struct adf_user_cfg_ctl_data *ctl_data; | ^~~~~~~~ Fix this by returning the pointer directly. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Reviewed-by: Thorsten Blum <thorsten.blum@linux.dev> Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 838d2d5 commit 5ce9891

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,14 @@ static int adf_chr_drv_create(void)
8989
return -EFAULT;
9090
}
9191

92-
static int adf_ctl_alloc_resources(struct adf_user_cfg_ctl_data **ctl_data,
93-
unsigned long arg)
92+
static struct adf_user_cfg_ctl_data *adf_ctl_alloc_resources(unsigned long arg)
9493
{
9594
struct adf_user_cfg_ctl_data *cfg_data;
9695

9796
cfg_data = memdup_user((void __user *)arg, sizeof(*cfg_data));
98-
if (IS_ERR(cfg_data)) {
97+
if (IS_ERR(cfg_data))
9998
pr_err("QAT: failed to copy from user cfg_data.\n");
100-
return PTR_ERR(cfg_data);
101-
}
102-
103-
*ctl_data = cfg_data;
104-
return 0;
99+
return cfg_data;
105100
}
106101

107102
static int adf_add_key_value_data(struct adf_accel_dev *accel_dev,
@@ -181,13 +176,13 @@ static int adf_copy_key_value_data(struct adf_accel_dev *accel_dev,
181176
static int adf_ctl_ioctl_dev_config(struct file *fp, unsigned int cmd,
182177
unsigned long arg)
183178
{
184-
int ret;
185179
struct adf_user_cfg_ctl_data *ctl_data;
186180
struct adf_accel_dev *accel_dev;
181+
int ret = 0;
187182

188-
ret = adf_ctl_alloc_resources(&ctl_data, arg);
189-
if (ret)
190-
return ret;
183+
ctl_data = adf_ctl_alloc_resources(arg);
184+
if (IS_ERR(ctl_data))
185+
return PTR_ERR(ctl_data);
191186

192187
accel_dev = adf_devmgr_get_dev_by_id(ctl_data->device_id);
193188
if (!accel_dev) {
@@ -260,9 +255,9 @@ static int adf_ctl_ioctl_dev_stop(struct file *fp, unsigned int cmd,
260255
int ret;
261256
struct adf_user_cfg_ctl_data *ctl_data;
262257

263-
ret = adf_ctl_alloc_resources(&ctl_data, arg);
264-
if (ret)
265-
return ret;
258+
ctl_data = adf_ctl_alloc_resources(arg);
259+
if (IS_ERR(ctl_data))
260+
return PTR_ERR(ctl_data);
266261

267262
if (adf_devmgr_verify_id(ctl_data->device_id)) {
268263
pr_err("QAT: Device %d not found\n", ctl_data->device_id);
@@ -294,9 +289,9 @@ static int adf_ctl_ioctl_dev_start(struct file *fp, unsigned int cmd,
294289
struct adf_user_cfg_ctl_data *ctl_data;
295290
struct adf_accel_dev *accel_dev;
296291

297-
ret = adf_ctl_alloc_resources(&ctl_data, arg);
298-
if (ret)
299-
return ret;
292+
ctl_data = adf_ctl_alloc_resources(arg);
293+
if (IS_ERR(ctl_data))
294+
return PTR_ERR(ctl_data);
300295

301296
ret = -ENODEV;
302297
accel_dev = adf_devmgr_get_dev_by_id(ctl_data->device_id);

0 commit comments

Comments
 (0)