* [PATCH] net/mlx4: Avoid 'may be used uninitialized' warnings
@ 2015-05-14 23:17 Bjorn Helgaas
2015-05-15 2:30 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Bjorn Helgaas @ 2015-05-14 23:17 UTC (permalink / raw)
To: Or Gerlitz, Jack Morgenstein, Matan Barak
Cc: Ido Shamay, netdev, Yishai Hadas, Amir Vadai, linux-kernel,
Roland Dreier, David S. Miller
With a cross-compiler based on gcc-4.9, I see warnings like the following:
drivers/net/ethernet/mellanox/mlx4/resource_tracker.c: In function 'mlx4_SW2HW_CQ_wrapper':
drivers/net/ethernet/mellanox/mlx4/resource_tracker.c:3048:10: error: 'cq' may be used uninitialized in this function [-Werror=maybe-uninitialized]
cq->mtt = mtt;
I think the warning is spurious because we only use cq when
cq_res_start_move_to() returns zero, and it always initializes *cq in that
case. The srq case is similar. But maybe gcc isn't smart enough to figure
that out.
Initialize cq and srq explicitly to avoid the warnings.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
.../net/ethernet/mellanox/mlx4/resource_tracker.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index c7f28bf..cdd32f4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -3187,7 +3187,7 @@ int mlx4_SW2HW_CQ_wrapper(struct mlx4_dev *dev, int slave,
int cqn = vhcr->in_modifier;
struct mlx4_cq_context *cqc = inbox->buf;
int mtt_base = cq_get_mtt_addr(cqc) / dev->caps.mtt_entry_sz;
- struct res_cq *cq;
+ struct res_cq *cq = NULL;
struct res_mtt *mtt;
err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_HW, &cq);
@@ -3223,7 +3223,7 @@ int mlx4_HW2SW_CQ_wrapper(struct mlx4_dev *dev, int slave,
{
int err;
int cqn = vhcr->in_modifier;
- struct res_cq *cq;
+ struct res_cq *cq = NULL;
err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_ALLOCATED, &cq);
if (err)
@@ -3362,7 +3362,7 @@ int mlx4_SW2HW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
int err;
int srqn = vhcr->in_modifier;
struct res_mtt *mtt;
- struct res_srq *srq;
+ struct res_srq *srq = NULL;
struct mlx4_srq_context *srqc = inbox->buf;
int mtt_base = srq_get_mtt_addr(srqc) / dev->caps.mtt_entry_sz;
@@ -3406,7 +3406,7 @@ int mlx4_HW2SW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
{
int err;
int srqn = vhcr->in_modifier;
- struct res_srq *srq;
+ struct res_srq *srq = NULL;
err = srq_res_start_move_to(dev, slave, srqn, RES_SRQ_ALLOCATED, &srq);
if (err)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net/mlx4: Avoid 'may be used uninitialized' warnings
2015-05-14 23:17 [PATCH] net/mlx4: Avoid 'may be used uninitialized' warnings Bjorn Helgaas
@ 2015-05-15 2:30 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2015-05-15 2:30 UTC (permalink / raw)
To: bhelgaas
Cc: ogerlitz, jackm, matanb, idos, netdev, yishaih, amirv,
linux-kernel, roland
From: Bjorn Helgaas <bhelgaas@google.com>
Date: Thu, 14 May 2015 18:17:08 -0500
> With a cross-compiler based on gcc-4.9, I see warnings like the following:
>
> drivers/net/ethernet/mellanox/mlx4/resource_tracker.c: In function 'mlx4_SW2HW_CQ_wrapper':
> drivers/net/ethernet/mellanox/mlx4/resource_tracker.c:3048:10: error: 'cq' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> cq->mtt = mtt;
>
> I think the warning is spurious because we only use cq when
> cq_res_start_move_to() returns zero, and it always initializes *cq in that
> case. The srq case is similar. But maybe gcc isn't smart enough to figure
> that out.
>
> Initialize cq and srq explicitly to avoid the warnings.
>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Applied.
The compiler, generally, is not good at determining use-before-initialized
in situations of the form:
int x;
if (foo)
x = whatever;
...
if (foo)
use(x);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-15 2:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14 23:17 [PATCH] net/mlx4: Avoid 'may be used uninitialized' warnings Bjorn Helgaas
2015-05-15 2:30 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.