diff options
author | YueHaibing <yuehaibing@huawei.com> | 2022-11-21 14:22:04 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-12-08 13:28:40 +0300 |
commit | 839eeab03c831a52333f7e9737685742a2c0cc1d (patch) | |
tree | 50dff6bae2fb66e8ca751f89457724417e807f5e | |
parent | 34feea3bfb37e09b20b9891ad72a815ac7895bd8 (diff) | |
download | linux-839eeab03c831a52333f7e9737685742a2c0cc1d.tar.xz |
net/mlx5: Fix uninitialized variable bug in outlen_write()
[ Upstream commit 3f5769a074c13d8f08455e40586600419e02a880 ]
If sscanf() return 0, outlen is uninitialized and used in kzalloc(),
this is unexpected. We should return -EINVAL if the string is invalid.
Fixes: e126ba97dba9 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index 85190f2f4d50..41c15a65fb45 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -1434,8 +1434,8 @@ static ssize_t outlen_write(struct file *filp, const char __user *buf, return -EFAULT; err = sscanf(outlen_str, "%d", &outlen); - if (err < 0) - return err; + if (err != 1) + return -EINVAL; ptr = kzalloc(outlen, GFP_KERNEL); if (!ptr) |