vdpa: fix gcc cvq_isolated uninitialized variable warning
PATCH 1/1 vdpa: fix gcc cvq_isolated uninitialized variable warning
gcc 13.2.1 emits the following warning:
net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]
1394 | s->cvq_isolated = cvq_isolated;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
1355 | int cvq_isolated;
| ^~~~~~~~~~~~cc1: all warnings being treated as errors
--- net/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +1 -1
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated; +int cvq_isolated =0 ;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
Signature · 1 line
2.41.0
Quoted 24 lines · Stefan Hajnoczi
gcc 13.2.1 emits the following warning:
net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized] 1394 | s->cvq_isolated = cvq_isolated; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here 1355 | int cvq_isolated; | ^~~~~~~~~~~~ cc1: all warnings being treated as errorsCc Eugenio Pérez <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- net/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1358
Quoted 8 lines
net/vhost-vdpa.c +1
-1@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated; +int cvq_isolated =0 ;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
Alternatively:
-- >8 --
net/vhost-vdpa.c +1 -2
@@ -1352,13 +1352,12 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated;if (is_datapath) { nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name); }else { - cvq_isolated =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, +int cvq_isolated =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, queue_pair_index
* 2,
errp);
if (unlikely(cvq_isolated < 0)) {@@ -1391,7 +1390,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops;
s->vhost_vdpa.shadow_vq_ops_opaque = s;- s->cvq_isolated = cvq_isolated;
+ s->cvq_isolated = true;
---
Whichever you prefer:
Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Stefan Hajnoczi
gcc 13.2.1 emits the following warning:
net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized] 1394 | s->cvq_isolated = cvq_isolated; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here 1355 | int cvq_isolated; | ^~~~~~~~~~~~ cc1: all warnings being treated as errorsCc Eugenio Pérez <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- net/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1358
Quoted 8 lines
net/vhost-vdpa.c +1
-1@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated; +int cvq_isolated =0 ;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,Alternatively:
-- >8 --
net/vhost-vdpa.c +1
-2@@ -1352,13 +1352,12 @@ static NetClientState *net_vhost_vdpa_init (NetClientState *peer, VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated;if (is_datapath) { nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name); }else { - cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features, + int cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features,
queue_pair_index
* 2,errp); if (unlikely(cvq_isolated < 0)) {
net/vhost-vdpa.c static NetClientState · line 1394
Quoted 6 lines
net/vhost-vdpa.c +1
-1@@ -1391,7 +1390,7 @@ static NetClientState *net_vhost_vdpa_init (NetClientState *peer, s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; - s->cvq_isolated = cvq_isolated; + s->cvq_isolated = true;
This is incorrect because the return value of vhost_vdpa_probe_cvq_isolation() is -errno for errors, 0 for no cvq isolation, and 1 for cvq isolation. A variable is still needed to distinguish between no cvq isolation and cvq isolation.
Quoted 8 lines
net/vhost-vdpa.c +0
-1---Whichever you prefer:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 65 lines · Stefan Hajnoczi
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Stefan Hajnoczi
gcc 13.2.1 emits the following warning:
net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]
1394 |s->cvq_isolated=cvq_isolated;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
1355 | intcvq_isolated;
| ^~~~~~~~~~~~
cc1: all warnings being treated as errorsCc Eugenio Pérez <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- net/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1358
Quoted 8 lines
net/vhost-vdpa.c +1
-1@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated; +int cvq_isolated =0 ;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,Alternatively:
-- >8 --
net/vhost-vdpa.c +1
-2@@ -1352,13 +1352,12 @@ static NetClientState *net_vhost_vdpa_init (NetClientState *peer, VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated;if (is_datapath) { nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name); }else { - cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features, + int cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features,
queue_pair_index
* 2,errp); if (unlikely(cvq_isolated < 0)) {net/vhost-vdpa.c +0
-0@@ -1391,7 +1390,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
Quoted 9 lines
net/vhost-vdpa.c static NetClientState · line 1394
Quoted 4 lines
net/vhost-vdpa.c +1
-1s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; - s->cvq_isolated = cvq_isolated; + s->cvq_isolated = true;This is incorrect because the return value of
vhost_vdpa_probe_cvq_isolation()is -errno for errors, 0 for no cvq isolation, and 1 for cvq isolation. A variable is still needed to distinguish between no cvq isolation and cvq isolation.
Oh, I was expecting a boolean for a field named 'cvq_isolated', my bad. R-b stands for your patch.
Regards,
Phil.
Quoted 9 lines
Quoted 9 lines
net/vhost-vdpa.c +0
-1---Whichever you prefer:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 12 lines · Stefan Hajnoczi
gcc 13.2.1 emits the following warning:
net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]1394 | s->cvq_isolated = cvq_isolated; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here 1355 | int cvq_isolated; | ^~~~~~~~~~~~cc1: all warnings being treated as errors
I think GCC is evaluating the case where (queue_pair_index == 0 && !is_datapath), which should be not possible.
If it is useful we can refactor the conditionals so we don't need the variable at that level of the function. If not,
Thanks!
Quoted 24 lines
Cc Eugenio Pérez <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- net/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/vhost-vdpa.c +1
-2@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated; +int cvq_isolated =0 ;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, --2.41.0
Quoted 10 lines · Stefan Hajnoczi
gcc 13.2.1 emits the following warning:
net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]1394 | s->cvq_isolated = cvq_isolated; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here 1355 | int cvq_isolated; | ^~~~~~~~~~~~
Quoted 6 lines
cc1: all warnings being treated as errors
Cc Eugenio Pérez <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>
Thanks
Quoted 20 lines
--- net/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/vhost-vdpa.c +1
-2@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,VhostVDPAState *s;int ret =0 ;assert (name); -int cvq_isolated; +int cvq_isolated =0 ;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, --2.41.0