Message ID | 20201103015228.2250547-1-kuhn.chenqun@huawei.com |
---|---|
Headers | show |
Series | fix uninitialized variable warning | expand |
On 11/3/20 2:52 AM, Chen Qun 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: > util/qemu-timer.c: In function ‘timer_mod_anticipate_ns’: > util/qemu-timer.c:474:8: warning: ‘rearm’ may be used uninitialized in this function [-Wmaybe-uninitialized] > 474 | if (rearm) { > | ^ > > Change the default value assignment place to prevented the warning. > > Reported-by: Euler Robot <euler.robot@huawei.com> > Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com> > --- > Cc: Paolo Bonzini <pbonzini@redhat.com> > --- > util/qemu-timer.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
On 11/3/20 2:52 AM, Chen Qun 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: > plugins/loader.c: In function ‘plugin_reset_uninstall’: > plugins/loader.c:382:15: warning: ‘ctx’ may be used uninitialized in this function [-Wmaybe-uninitialized] This shouldn't happen as the function returns before (else there is a NULL deref). > 382 | data->ctx = ctx; > | ~~~~~~~~~~^~~~~ > > Add a default value for 'expire_time' to prevented the warning. > > Reported-by: Euler Robot <euler.robot@huawei.com> > Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com> > --- > Cc: "Alex Bennée" <alex.bennee@linaro.org> > --- > plugins/loader.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/plugins/loader.c b/plugins/loader.c > index 8ac5dbc20f..88593fe138 100644 > --- a/plugins/loader.c > +++ b/plugins/loader.c > @@ -367,7 +367,7 @@ void plugin_reset_uninstall(qemu_plugin_id_t id, > bool reset) > { > struct qemu_plugin_reset_data *data; > - struct qemu_plugin_ctx *ctx; > + struct qemu_plugin_ctx *ctx = NULL; > > WITH_QEMU_LOCK_GUARD(&plugin.lock) { > ctx = plugin_id_to_ctx_locked(id); >
> -----Original Message----- > From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com] > Sent: Tuesday, November 3, 2020 10:18 AM > To: Chenqun (kuhn) <kuhn.chenqun@huawei.com>; qemu-devel@nongnu.org; > qemu-trivial@nongnu.org > Cc: Alex Bennée <alex.bennee@linaro.org>; Zhanghailiang > <zhang.zhanghailiang@huawei.com>; ganqixin <ganqixin@huawei.com>; Euler > Robot <euler.robot@huawei.com> > Subject: Re: [PATCH 5/6] plugins/loader: fix uninitialized variable warning in > plugin_reset_uninstall() > > On 11/3/20 2:52 AM, Chen Qun 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: > > plugins/loader.c: In function ‘plugin_reset_uninstall’: > > plugins/loader.c:382:15: warning: ‘ctx’ may be used uninitialized in > > this function [-Wmaybe-uninitialized] > > This shouldn't happen as the function returns before (else there is a NULL > deref). > Yes, in fact, it shouldn't have happened when the program was running. But after added 'WITH_QEMU_LOCK_GUARD', let the compiler think it might happen. So, we add a default value, make the compiler happy. Thanks, Chen Qun > > 382 | data->ctx = ctx; > > | ~~~~~~~~~~^~~~~ > > > > Add a default value for 'expire_time' to prevented the warning. > > > > Reported-by: Euler Robot <euler.robot@huawei.com> > > Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com> > > --- > > Cc: "Alex Bennée" <alex.bennee@linaro.org> > > --- > > plugins/loader.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/plugins/loader.c b/plugins/loader.c index > > 8ac5dbc20f..88593fe138 100644 > > --- a/plugins/loader.c > > +++ b/plugins/loader.c > > @@ -367,7 +367,7 @@ void plugin_reset_uninstall(qemu_plugin_id_t id, > > bool reset) { > > struct qemu_plugin_reset_data *data; > > - struct qemu_plugin_ctx *ctx; > > + struct qemu_plugin_ctx *ctx = NULL; > > > > WITH_QEMU_LOCK_GUARD(&plugin.lock) { > > ctx = plugin_id_to_ctx_locked(id); > >
On Tue, 3 Nov 2020 at 02:07, Chen Qun <kuhn.chenqun@huawei.com> wrote: > > Hi all, > There are some variables initialized warnings reported by the compiler, > even if the default CFLAG for the compiler parameters are uesed. > > This serial has added some default values or changed the assignment places for the variablies to fix them. Hi; if you're reporting/fixing compiler errors/warnings please can you include the compiler version that produced the error in the commit message? This is helpful for telling us whether it's a problem with older compilers or whether this is a new compiler that checks for some things more carefully. thanks -- PMM
> -----Original Message----- > From: Peter Maydell [mailto:peter.maydell@linaro.org] > Sent: Tuesday, November 3, 2020 6:15 PM > To: Chenqun (kuhn) <kuhn.chenqun@huawei.com> > Cc: QEMU Developers <qemu-devel@nongnu.org>; QEMU Trivial > <qemu-trivial@nongnu.org>; Zhanghailiang > <zhang.zhanghailiang@huawei.com>; ganqixin <ganqixin@huawei.com> > Subject: Re: [PATCH 0/6] fix uninitialized variable warning > > On Tue, 3 Nov 2020 at 02:07, Chen Qun <kuhn.chenqun@huawei.com> wrote: > > > > Hi all, > > There are some variables initialized warnings reported by the > > compiler, even if the default CFLAG for the compiler parameters are uesed. > > > > This serial has added some default values or changed the assignment places > for the variablies to fix them. > > > Hi; if you're reporting/fixing compiler errors/warnings please can you include > the compiler version that produced the error in the commit message? This is > helpful for telling us whether it's a problem with older compilers or whether this > is a new compiler that checks for some things more carefully. > Oops, I didn't consider that. These warnings were reported by GCC 9.3, Thanks, Chen Qun
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 <div dir="ltr"><div>Hi Chen,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 3, 2020 at 3:53 AM Chen Qun <<a href="mailto:kuhn.chenqun@huawei.com">kuhn.chenqun@huawei.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">After the WITH_QEMU_LOCK_GUARD macro is added, the compiler cannot identify<br> that the statements in the macro must be executed. As a result, some variables<br> assignment statements in the macro may be considered as unexecuted by the compiler.<br> <br> The compiler showed warning:<br> hw/rdma/rdma_backend.c: In function ‘rdma_poll_cq’:<br> hw/rdma/rdma_utils.h:25:5: warning: ‘ne’ may be used uninitialized in this function [-Wmaybe-uninitialized]<br> 25 | error_report("%s: " fmt, "rdma", ## __VA_ARGS__)<br> | ^~~~~~~~~~~~<br> hw/rdma/rdma_backend.c:93:12: note: ‘ne’ was declared here<br> 93 | int i, ne, total_ne = 0;<br> | ^~<br> <br> Add a default value for 'ne' to prevented the warning.<br> <br> Reported-by: Euler Robot <<a href="mailto:euler.robot@huawei.com" target="_blank">euler.robot@huawei.com</a>><br> Signed-off-by: Chen Qun <<a href="mailto:kuhn.chenqun@huawei.com" target="_blank">kuhn.chenqun@huawei.com</a>><br> ---<br> Cc: Yuval Shaia <<a href="mailto:yuval.shaia.ml@gmail.com" target="_blank">yuval.shaia.ml@gmail.com</a>><br> Cc: Marcel Apfelbaum <<a href="mailto:marcel.apfelbaum@gmail.com" target="_blank">marcel.apfelbaum@gmail.com</a>><br> ---<br> hw/rdma/rdma_backend.c | 2 +-<br> 1 file changed, 1 insertion(+), 1 deletion(-)<br> <br> diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c<br> index 5de010b1fa..2fe4a3501c 100644<br> --- a/hw/rdma/rdma_backend.c<br> +++ b/hw/rdma/rdma_backend.c<br> @@ -90,7 +90,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev)<br> <br> static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq)<br> {<br> - int i, ne, total_ne = 0;<br> + int i, ne = 0, total_ne = 0;<br> BackendCtx *bctx;<br> struct ibv_wc wc[2];<br> RdmaProtectedGSList *cqe_ctx_list;<br> -- <br> 2.27.0<br> <br></blockquote><div><br></div><div><div><div>Reviewed-by: Marcel Apfelbaum <<a href="mailto:marcel.apfelbaum@gmail.com" target="_blank">marcel.apfelbaum@gmail.com</a>></div></div><div><br></div><div>Thanks for the fix,</div><div>Marcel</div></div><div> </div></div></div>
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 > > <div dir="ltr">Thanks,<div><br><div>Reviewed-by: Yuval Shaia <<a href="mailto:yuval.shaia.ml@gmail.com">yuval.shaia.ml@gmail.com</a>><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 3 Nov 2020 at 03:53, Chen Qun <<a href="mailto:kuhn.chenqun@huawei.com">kuhn.chenqun@huawei.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">After the WITH_QEMU_LOCK_GUARD macro is added, the compiler cannot identify<br> that the statements in the macro must be executed. As a result, some variables<br> assignment statements in the macro may be considered as unexecuted by the compiler.<br> <br> The compiler showed warning:<br> hw/rdma/rdma_backend.c: In function ‘rdma_poll_cq’:<br> hw/rdma/rdma_utils.h:25:5: warning: ‘ne’ may be used uninitialized in this function [-Wmaybe-uninitialized]<br> 25 | error_report("%s: " fmt, "rdma", ## __VA_ARGS__)<br> | ^~~~~~~~~~~~<br> hw/rdma/rdma_backend.c:93:12: note: ‘ne’ was declared here<br> 93 | int i, ne, total_ne = 0;<br> | ^~<br> <br> Add a default value for 'ne' to prevented the warning.<br> <br> Reported-by: Euler Robot <<a href="mailto:euler.robot@huawei.com" target="_blank">euler.robot@huawei.com</a>><br> Signed-off-by: Chen Qun <<a href="mailto:kuhn.chenqun@huawei.com" target="_blank">kuhn.chenqun@huawei.com</a>><br> ---<br> Cc: Yuval Shaia <<a href="mailto:yuval.shaia.ml@gmail.com" target="_blank">yuval.shaia.ml@gmail.com</a>><br> Cc: Marcel Apfelbaum <<a href="mailto:marcel.apfelbaum@gmail.com" target="_blank">marcel.apfelbaum@gmail.com</a>><br> ---<br> hw/rdma/rdma_backend.c | 2 +-<br> 1 file changed, 1 insertion(+), 1 deletion(-)<br> <br> diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c<br> index 5de010b1fa..2fe4a3501c 100644<br> --- a/hw/rdma/rdma_backend.c<br> +++ b/hw/rdma/rdma_backend.c<br> @@ -90,7 +90,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev)<br> <br> static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq)<br> {<br> - int i, ne, total_ne = 0;<br> + int i, ne = 0, total_ne = 0;<br> BackendCtx *bctx;<br> struct ibv_wc wc[2];<br> RdmaProtectedGSList *cqe_ctx_list;<br> -- <br> 2.27.0<br> <br> </blockquote></div>