net/vhost-vdpa.c: Fix clang compilation failure
PATCH 1/1 net/vhost-vdpa.c: Fix clang compilation failure
Commit 8801ccd0500437 introduced a compilation failure with clang version 10.0.0-4ubuntu1:
../../net/vhost-vdpa.c:654:16: error: variable 'vdpa_device_fd' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
} else if (opts->has_vhostfd) {
^~~~~~~~~~~~~~~~~
../../net/vhost-vdpa.c:662:33: note: uninitialized use occurs here
r = vhost_vdpa_get_features(vdpa_device_fd, &features, errp);
^~~~~~~~~~~~~~
../../net/vhost-vdpa.c:654:12: note: remove the 'if' if its condition
is always true
} else if (opts->has_vhostfd) {
^~~~~~~~~~~~~~~~~~~~~~~
../../net/vhost-vdpa.c:629:23: note: initialize the variable
'vdpa_device_fd' to silence this warning
int vdpa_device_fd;
^
= 01 error generated.
It's a false positive -- the compiler doesn't manage to figure out that the error checks further up mean that there's no code path where vdpa_device_fd isn't initialized. Put another way, the problem is that we check "if (opts->has_vhostfd)" when in fact that condition must always be true. A cleverer static analyser would probably warn that we were checking an always-true condition.
Fix the compilation failure by removing the unnecessary if().
---
Stefan, do you want to apply this directly as a build fix?
--- net/vhost-vdpa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/vhost-vdpa.c +2 -1
@@ -651,7 +651,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (vdpa_device_fd ==-1 ) {return -errno; } - }else if (opts->has_vhostfd) { + }else { +/* has_vhostfd */ vdpa_device_fd =monitor_fd_param (monitor_cur (), opts->vhostfd, errp);if (vdpa_device_fd ==-1 ) {error_prepend (errp,"vhost-vdpa: unable to parse vhostfd: " );
Signature · 1 line
2.25.1
Stefan Hajnoczi
AppliedQuoted 31 lines · Peter Maydell
Commit
8801ccd0500437introduced a compilation failure with clang version 10.0.0-4ubuntu1:
../../net/vhost-vdpa.c:654:16: error: variable 'vdpa_device_fd' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]} else if (opts->has_vhostfd) { ^~~~~~~~~~~~~~~~~ ../../net/vhost-vdpa.c:662:33: note: uninitialized use occurs here r = vhost_vdpa_get_features(vdpa_device_fd, &features, errp); ^~~~~~~~~~~~~~ ../../net/vhost-vdpa.c:654:12: note: remove the 'if' if its condition is always true } else if (opts->has_vhostfd) { ^~~~~~~~~~~~~~~~~~~~~~~ ../../net/vhost-vdpa.c:629:23: note: initialize the variable 'vdpa_device_fd' to silence this warning int vdpa_device_fd; ^ = 01 error generated.
It's a false positive -- the compiler doesn't manage to figure out that the error checks further up mean that there's no code path where
vdpa_device_fdisn't initialized. Put another way, the problem is that we check "if (opts->has_vhostfd)" when in fact that condition must always be true. A cleverer static analyser would probably warn that we were checking an always-true condition.Fix the compilation failure by removing the unnecessary
if().
Quoted 7 lines
Fixes 8801ccd0500437 ("vhost-vdpa: allow passing opened vhostfd to vhost-vdpa")Signed-off-by Peter Maydell <[email protected]>---
Stefan, do you want to apply this directly as a build fix?--- net/vhost-vdpa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Thanks, applied to the staging tree:
https://gitlab.com/qemu-project/qemu/commits/staging
Stefan