Skip to content

Commit f0bb2d5

Browse files
arndbmstsirkin
authored andcommitted
virtio_balloon: prevent uninitialized variable use
The latest gcc-7.0.1 snapshot reports a new warning: virtio/virtio_balloon.c: In function 'update_balloon_stats': virtio/virtio_balloon.c:258:26: error: 'events[2]' is used uninitialized in this function [-Werror=uninitialized] virtio/virtio_balloon.c:260:26: error: 'events[3]' is used uninitialized in this function [-Werror=uninitialized] virtio/virtio_balloon.c:261:56: error: 'events[18]' is used uninitialized in this function [-Werror=uninitialized] virtio/virtio_balloon.c:262:56: error: 'events[17]' is used uninitialized in this function [-Werror=uninitialized] This seems absolutely right, so we should add an extra check to prevent copying uninitialized stack data into the statistics. >From all I can tell, this has been broken since the statistics code was originally added in 2.6.34. Fixes: 9564e13 ("virtio: Add memory statistics reporting to the balloon driver (V4)") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Ladi Prosek <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 9646b26 commit f0bb2d5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/virtio/virtio_balloon.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,14 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
254254

255255
available = si_mem_available();
256256

257+
#ifdef CONFIG_VM_EVENT_COUNTERS
257258
update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
258259
pages_to_bytes(events[PSWPIN]));
259260
update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,
260261
pages_to_bytes(events[PSWPOUT]));
261262
update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]);
262263
update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]);
264+
#endif
263265
update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE,
264266
pages_to_bytes(i.freeram));
265267
update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,

0 commit comments

Comments
 (0)