]> xenbits.xensource.com Git - people/aperard/qemu-dm.git/commitdiff
rust: pl011: Allow NULL chardev argument to pl011_create()
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 7 Mar 2025 19:00:51 +0000 (19:00 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 9 Mar 2025 10:25:10 +0000 (11:25 +0100)
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 <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Link: https://lore.kernel.org/r/20250307190051.3274226-1-peter.maydell@linaro.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rust/hw/char/pl011/src/device.rs

index af93ae8bebe169e4ea1e2f062fea65a9a3d526af..f137b49feafca070bfa28e2cfacab28effe3b69f 100644 (file)
@@ -648,10 +648,12 @@ pub unsafe extern "C" fn pl011_create(
     // SAFETY: The callers promise that they have owned references.
     // They do not gift them to pl011_create, so use `Owned::from`.
     let irq = unsafe { Owned::<IRQState>::from(&*irq) };
-    let chr = unsafe { Owned::<Chardev>::from(&*chr) };
 
     let dev = PL011State::new();
-    dev.prop_set_chr("chardev", &chr);
+    if !chr.is_null() {
+        let chr = unsafe { Owned::<Chardev>::from(&*chr) };
+        dev.prop_set_chr("chardev", &chr);
+    }
     dev.sysbus_realize();
     dev.mmio_map(0, addr);
     dev.connect_irq(0, &irq);