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