virtio-devices: mem, balloon: Use struct initialisation

error: field assignment outside of initializer for an instance created with Default::default()
   --> virtio-devices/src/mem.rs:496:9
    |
496 |         resp.resp_type = resp_type;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: consider initializing the variable with `mem::VirtioMemResp { resp_type: resp_type, ..Default::default() }` and removing relevant reassignments
   --> virtio-devices/src/mem.rs:495:9
    |
495 |         let mut resp = VirtioMemResp::default();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-01-02 20:37:05 +00:00 committed by Sebastien Boeuf
parent 6ccd32c904
commit 05cdef17f4
2 changed files with 10 additions and 6 deletions

View File

@ -321,8 +321,10 @@ impl Balloon {
pub fn new(id: String, size: u64, seccomp_action: SeccompAction) -> io::Result<Self> {
let avail_features = 1u64 << VIRTIO_F_VERSION_1;
let mut config = VirtioBalloonConfig::default();
config.num_pages = (size >> VIRTIO_BALLOON_PFN_SHIFT) as u32;
let config = VirtioBalloonConfig {
num_pages: (size >> VIRTIO_BALLOON_PFN_SHIFT) as u32,
..Default::default()
};
Ok(Balloon {
common: VirtioCommon {

View File

@ -489,12 +489,14 @@ impl MemEpollHandler {
fn virtio_mem_send_response(
mem: &GuestMemoryMmap,
resp_type: u16,
resp_state: u16,
state: u16,
status_addr: GuestAddress,
) -> u32 {
let mut resp = VirtioMemResp::default();
resp.resp_type = resp_type;
resp.state.state = resp_state;
let resp = VirtioMemResp {
resp_type,
state: VirtioMemRespState { state },
..Default::default()
};
match mem.write_obj(resp, status_addr) {
Ok(_) => size_of::<VirtioMemResp>() as u32,
Err(e) => {