Skip to content

Commit 5006e39

Browse files
trueptolemybonzini
authored andcommitted
rust/vmstate: Relax array check when build varray in vmstate_struct
The varry of structure created by vmstate_struct is different with vmstate_of. This is because vmstate_struct uses the `vmsd` to traverse the vmstates of structure's fields, rather than treating the structure directly as a well-defined vmstate. Therefore, there's no need to check array flag when building varray by vmstate_struct. Signed-off-by: Zhao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e5655e9 commit 5006e39

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rust/qemu-api/src/vmstate.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,20 @@ impl VMStateField {
275275
}
276276

277277
#[must_use]
278-
pub const fn with_varray_flag(mut self, flag: VMStateFlags) -> VMStateField {
279-
assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) != 0);
278+
pub const fn with_varray_flag_unchecked(mut self, flag: VMStateFlags) -> VMStateField {
280279
self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_ARRAY.0);
281280
self.flags = VMStateFlags(self.flags.0 | flag.0);
282281
self.num = 0; // varray uses num_offset instead of num.
283282
self
284283
}
285284

285+
#[must_use]
286+
#[allow(unused_mut)]
287+
pub const fn with_varray_flag(mut self, flag: VMStateFlags) -> VMStateField {
288+
assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) != 0);
289+
self.with_varray_flag_unchecked(flag)
290+
}
291+
286292
#[must_use]
287293
pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField {
288294
assert!(num <= 0x7FFF_FFFFu32);
@@ -454,7 +460,7 @@ macro_rules! vmstate_struct {
454460
flags: $crate::bindings::VMStateFlags::VMS_STRUCT,
455461
vmsd: $vmsd,
456462
..$crate::zeroable::Zeroable::ZERO
457-
} $(.with_varray_flag(
463+
} $(.with_varray_flag_unchecked(
458464
$crate::call_func_with_field!(
459465
$crate::vmstate::vmstate_varray_flag,
460466
$struct_name,

0 commit comments

Comments
 (0)