diff mbox series

[2/6] hw/rdma/rdma_backend: fix uninitialized variable warning in rdma_poll_cq()

Message ID 20201103015228.2250547-3-kuhn.chenqun@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix uninitialized variable warning | expand

Commit Message

Chen Qun Nov. 3, 2020, 1:52 a.m. UTC
After the WITH_QEMU_LOCK_GUARD macro is added, the compiler cannot identify
 that the statements in the macro must be executed. As a result, some variables
 assignment statements in the macro may be considered as unexecuted by the compiler.

The compiler showed warning:
hw/rdma/rdma_backend.c: In function ‘rdma_poll_cq’:
hw/rdma/rdma_utils.h:25:5: warning: ‘ne’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 25 |     error_report("%s: " fmt, "rdma", ## __VA_ARGS__)
    |     ^~~~~~~~~~~~
hw/rdma/rdma_backend.c:93:12: note: ‘ne’ was declared here
 93 |     int i, ne, total_ne = 0;
    |            ^~

Add a default value for 'ne' to prevented the warning.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
Cc: Yuval Shaia <yuval.shaia.ml@gmail.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
---
 hw/rdma/rdma_backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marcel Apfelbaum Nov. 3, 2020, 4:41 p.m. UTC | #1
Hi Chen,

On Tue, Nov 3, 2020 at 3:53 AM Chen Qun <kuhn.chenqun@huawei.com> wrote:

> After the WITH_QEMU_LOCK_GUARD macro is added, the compiler cannot identify
>  that the statements in the macro must be executed. As a result, some
> variables
>  assignment statements in the macro may be considered as unexecuted by the
> compiler.
>
> The compiler showed warning:
> hw/rdma/rdma_backend.c: In function ‘rdma_poll_cq’:
> hw/rdma/rdma_utils.h:25:5: warning: ‘ne’ may be used uninitialized in this
> function [-Wmaybe-uninitialized]
>  25 |     error_report("%s: " fmt, "rdma", ## __VA_ARGS__)
>     |     ^~~~~~~~~~~~
> hw/rdma/rdma_backend.c:93:12: note: ‘ne’ was declared here
>  93 |     int i, ne, total_ne = 0;
>     |            ^~
>
> Add a default value for 'ne' to prevented the warning.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: Yuval Shaia <yuval.shaia.ml@gmail.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> ---
>  hw/rdma/rdma_backend.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c
> index 5de010b1fa..2fe4a3501c 100644
> --- a/hw/rdma/rdma_backend.c
> +++ b/hw/rdma/rdma_backend.c
> @@ -90,7 +90,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev)
>
>  static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq
> *ibcq)
>  {
> -    int i, ne, total_ne = 0;
> +    int i, ne = 0, total_ne = 0;
>      BackendCtx *bctx;
>      struct ibv_wc wc[2];
>      RdmaProtectedGSList *cqe_ctx_list;
> --
> 2.27.0
>
>
Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>

Thanks for the fix,
Marcel
Yuval Shaia Nov. 3, 2020, 7:49 p.m. UTC | #2
Thanks,

Reviewed-by:  Yuval Shaia <yuval.shaia.ml@gmail.com>

On Tue, 3 Nov 2020 at 03:53, Chen Qun <kuhn.chenqun@huawei.com> wrote:

> After the WITH_QEMU_LOCK_GUARD macro is added, the compiler cannot identify
>  that the statements in the macro must be executed. As a result, some
> variables
>  assignment statements in the macro may be considered as unexecuted by the
> compiler.
>
> The compiler showed warning:
> hw/rdma/rdma_backend.c: In function ‘rdma_poll_cq’:
> hw/rdma/rdma_utils.h:25:5: warning: ‘ne’ may be used uninitialized in this
> function [-Wmaybe-uninitialized]
>  25 |     error_report("%s: " fmt, "rdma", ## __VA_ARGS__)
>     |     ^~~~~~~~~~~~
> hw/rdma/rdma_backend.c:93:12: note: ‘ne’ was declared here
>  93 |     int i, ne, total_ne = 0;
>     |            ^~
>
> Add a default value for 'ne' to prevented the warning.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: Yuval Shaia <yuval.shaia.ml@gmail.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> ---
>  hw/rdma/rdma_backend.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c
> index 5de010b1fa..2fe4a3501c 100644
> --- a/hw/rdma/rdma_backend.c
> +++ b/hw/rdma/rdma_backend.c
> @@ -90,7 +90,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev)
>
>  static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq
> *ibcq)
>  {
> -    int i, ne, total_ne = 0;
> +    int i, ne = 0, total_ne = 0;
>      BackendCtx *bctx;
>      struct ibv_wc wc[2];
>      RdmaProtectedGSList *cqe_ctx_list;
> --
> 2.27.0
>
>
diff mbox series

Patch

diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c
index 5de010b1fa..2fe4a3501c 100644
--- a/hw/rdma/rdma_backend.c
+++ b/hw/rdma/rdma_backend.c
@@ -90,7 +90,7 @@  static void clean_recv_mads(RdmaBackendDev *backend_dev)
 
 static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq)
 {
-    int i, ne, total_ne = 0;
+    int i, ne = 0, total_ne = 0;
     BackendCtx *bctx;
     struct ibv_wc wc[2];
     RdmaProtectedGSList *cqe_ctx_list;