Skip to content

Commit 8169453

Browse files
pm215bonzini
authored andcommitted
rust: pl011: Allow NULL chardev argument to pl011_create()
It's valid for the caller to pass a NULL chardev to pl011_create(); this means "don't set the chardev property on the device", which in turn means "act like there's no chardev". All the chardev frontend APIs (in C, at least) accept a NULL pointer to mean "do nothing". This fixes some failures in 'make check-functional' when Rust support is enabled. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 563b1a3 commit 8169453

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rust/hw/char/pl011/src/device.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,12 @@ pub unsafe extern "C" fn pl011_create(
648648
// SAFETY: The callers promise that they have owned references.
649649
// They do not gift them to pl011_create, so use `Owned::from`.
650650
let irq = unsafe { Owned::<IRQState>::from(&*irq) };
651-
let chr = unsafe { Owned::<Chardev>::from(&*chr) };
652651

653652
let dev = PL011State::new();
654-
dev.prop_set_chr("chardev", &chr);
653+
if !chr.is_null() {
654+
let chr = unsafe { Owned::<Chardev>::from(&*chr) };
655+
dev.prop_set_chr("chardev", &chr);
656+
}
655657
dev.sysbus_realize();
656658
dev.mmio_map(0, addr);
657659
dev.connect_irq(0, &irq);

0 commit comments

Comments
 (0)