net/mlx5: Fix uninitialized variable bug in outlen_write()

If sscanf() return 0, outlen is uninitialized and used in kzalloc(),
this is unexpected. We should return -EINVAL if the string is invalid.

Fixes: e126ba97db ("mlx5: Add driver for Mellanox Connect-IB adapters")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
This commit is contained in:
YueHaibing 2022-11-21 19:22:04 +08:00 committed by Saeed Mahameed
parent e87c6a832f
commit 3f5769a074

View File

@ -1497,8 +1497,8 @@ static ssize_t outlen_write(struct file *filp, const char __user *buf,
return -EFAULT; return -EFAULT;
err = sscanf(outlen_str, "%d", &outlen); err = sscanf(outlen_str, "%d", &outlen);
if (err < 0) if (err != 1)
return err; return -EINVAL;
ptr = kzalloc(outlen, GFP_KERNEL); ptr = kzalloc(outlen, GFP_KERNEL);
if (!ptr) if (!ptr)