diff options
author | Pan Bian <bianpan2016@163.com> | 2016-12-04 01:45:38 -0500 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2016-12-14 14:35:23 -0500 |
commit | 46d0703fac3ffa12ec36f22f386d96d0f474c9c2 (patch) | |
tree | c15928a73813d5eaf2e54f685d1e0814ae4d8311 | |
parent | 5b4c9cd7e4790f37b595aeb4bf6fcbf7e3ba9e2c (diff) |
IB/mlx4: fix improper return value
If uhw->inlen is non-zero, the value of variable err is 0 if the copy
succeeds. Then, if kzalloc() or kmalloc() returns a NULL pointer, it
will return 0 to the callers. As a result, the callers cannot detect the
errors. This patch fixes the bug, assign "-ENOMEM" to err before the
NULL pointer checks, and remove the initialization of err at the
beginning.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189031
Signed-off-by: Pan Bian <bianpan2016@163.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | drivers/infiniband/hw/mlx4/main.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index b597e8227591..a87c395e185a 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c | |||
@@ -430,7 +430,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev, | |||
430 | struct mlx4_ib_dev *dev = to_mdev(ibdev); | 430 | struct mlx4_ib_dev *dev = to_mdev(ibdev); |
431 | struct ib_smp *in_mad = NULL; | 431 | struct ib_smp *in_mad = NULL; |
432 | struct ib_smp *out_mad = NULL; | 432 | struct ib_smp *out_mad = NULL; |
433 | int err = -ENOMEM; | 433 | int err; |
434 | int have_ib_ports; | 434 | int have_ib_ports; |
435 | struct mlx4_uverbs_ex_query_device cmd; | 435 | struct mlx4_uverbs_ex_query_device cmd; |
436 | struct mlx4_uverbs_ex_query_device_resp resp = {.comp_mask = 0}; | 436 | struct mlx4_uverbs_ex_query_device_resp resp = {.comp_mask = 0}; |
@@ -455,6 +455,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev, | |||
455 | sizeof(resp.response_length); | 455 | sizeof(resp.response_length); |
456 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); | 456 | in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); |
457 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); | 457 | out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); |
458 | err = -ENOMEM; | ||
458 | if (!in_mad || !out_mad) | 459 | if (!in_mad || !out_mad) |
459 | goto out; | 460 | goto out; |
460 | 461 | ||