* [PATCH 1/1] infiniband: hw: mlx4: fix improper return value
@ 2016-12-04 6:45 Pan Bian
2016-12-04 7:17 ` Leon Romanovsky
2016-12-14 19:35 ` Doug Ledford
0 siblings, 2 replies; 5+ messages in thread
From: Pan Bian @ 2016-12-04 6:45 UTC (permalink / raw)
To: Leon Romanovsky, Yishai Hadas, Doug Ledford, Sean Hefty,
Hal Rosenstock, linux-rdma
Cc: linux-kernel, Pan Bian
From: Pan Bian <bianpan2016@163.com>
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>
---
drivers/infiniband/hw/mlx4/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index b597e82..a87c395 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,
struct mlx4_ib_dev *dev = to_mdev(ibdev);
struct ib_smp *in_mad = NULL;
struct ib_smp *out_mad = NULL;
- int err = -ENOMEM;
+ int err;
int have_ib_ports;
struct mlx4_uverbs_ex_query_device cmd;
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,
sizeof(resp.response_length);
in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
+ err = -ENOMEM;
if (!in_mad || !out_mad)
goto out;
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] infiniband: hw: mlx4: fix improper return value
2016-12-04 6:45 [PATCH 1/1] infiniband: hw: mlx4: fix improper return value Pan Bian
@ 2016-12-04 7:17 ` Leon Romanovsky
2016-12-14 19:35 ` Doug Ledford
1 sibling, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2016-12-04 7:17 UTC (permalink / raw)
To: Pan Bian
Cc: Yishai Hadas, Doug Ledford, Sean Hefty, Hal Rosenstock,
linux-rdma, linux-kernel, Pan Bian
[-- Attachment #1: Type: text/plain, Size: 641 bytes --]
On Sun, Dec 04, 2016 at 02:45:38PM +0800, Pan Bian wrote:
> From: Pan Bian <bianpan2016@163.com>
>
> 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>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] infiniband: hw: mlx4: fix improper return value
2016-12-04 6:45 [PATCH 1/1] infiniband: hw: mlx4: fix improper return value Pan Bian
2016-12-04 7:17 ` Leon Romanovsky
@ 2016-12-14 19:35 ` Doug Ledford
1 sibling, 0 replies; 5+ messages in thread
From: Doug Ledford @ 2016-12-14 19:35 UTC (permalink / raw)
To: Pan Bian, Leon Romanovsky, Yishai Hadas, Sean Hefty,
Hal Rosenstock, linux-rdma
Cc: linux-kernel, Pan Bian
[-- Attachment #1.1: Type: text/plain, Size: 666 bytes --]
On 12/4/2016 1:45 AM, Pan Bian wrote:
> From: Pan Bian <bianpan2016@163.com>
>
> 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>
Thanks, applied.
--
Doug Ledford <dledford@redhat.com>
GPG Key ID: 0E572FDD
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] infiniband: hw: mlx4: fix improper return value
2016-12-04 5:49 Pan Bian
@ 2016-12-04 6:15 ` Leon Romanovsky
0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2016-12-04 6:15 UTC (permalink / raw)
To: Pan Bian
Cc: Yishai Hadas, Doug Ledford, Sean Hefty, Hal Rosenstock,
linux-rdma, linux-kernel, Pan Bian
[-- Attachment #1: Type: text/plain, Size: 1526 bytes --]
On Sun, Dec 04, 2016 at 01:49:04PM +0800, Pan Bian wrote:
> From: Pan Bian <bianpan2016@163.com>
>
> 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, assigning "-ENOMEM" to err before
> the NULL pointer checks.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189031
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
> drivers/infiniband/hw/mlx4/main.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
> index b597e82..f6c5158 100644
> --- a/drivers/infiniband/hw/mlx4/main.c
> +++ b/drivers/infiniband/hw/mlx4/main.c
> @@ -455,6 +455,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
> sizeof(resp.response_length);
> in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
> out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
> + err = -ENOMEM;
> if (!in_mad || !out_mad)
> goto out;
In such case, the err initialization at the beginning of
mlx4_ib_query_device function is not necessary. Can you please remove it?
Besides that, look good.
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
>
> --
> 1.9.1
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/1] infiniband: hw: mlx4: fix improper return value
@ 2016-12-04 5:49 Pan Bian
2016-12-04 6:15 ` Leon Romanovsky
0 siblings, 1 reply; 5+ messages in thread
From: Pan Bian @ 2016-12-04 5:49 UTC (permalink / raw)
To: Yishai Hadas, Doug Ledford, Sean Hefty, Hal Rosenstock, linux-rdma
Cc: linux-kernel, Pan Bian
From: Pan Bian <bianpan2016@163.com>
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, assigning "-ENOMEM" to err before
the NULL pointer checks.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189031
Signed-off-by: Pan Bian <bianpan2016@163.com>
---
drivers/infiniband/hw/mlx4/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index b597e82..f6c5158 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -455,6 +455,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
sizeof(resp.response_length);
in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
+ err = -ENOMEM;
if (!in_mad || !out_mad)
goto out;
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-12-14 19:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-04 6:45 [PATCH 1/1] infiniband: hw: mlx4: fix improper return value Pan Bian
2016-12-04 7:17 ` Leon Romanovsky
2016-12-14 19:35 ` Doug Ledford
-- strict thread matches above, loose matches on Subject: below --
2016-12-04 5:49 Pan Bian
2016-12-04 6:15 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).