Skip to contentSkip to conversation

rust: pl011: Allow NULL chardev argument to pl011_create()

PATCH In review Peter Maydell 3 participants 3 messages Mar 7, 2025 – Mar 9, 2025 Rust

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
This is my first Rust related patch for QEMU, so I've probably got something wrong here :-)

---
 rust/hw/char/pl011/src/device.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rust/hw/char/pl011/src/device.rs +4 -2
index d0857b470c9..8098f762f4b 100644
@@ -713,10 +713,12 @@ pub fn post_load(&self, _version_id: u32) -> Result<(), ()> {
     // 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);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Peter Maydell

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.

---
This is my first Rust related patch for QEMU, so I've probably got something wrong here :-)

---
  rust/hw/char/pl011/src/device.rs | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
rust/hw/char/pl011/src/device.rs +0 -1
index d0857b470c9..8098f762f4b 100644
@@ -713,10 +713,12 @@ pub fn post_load(&self, _version_id: u32) -> Result<(), ()> {
      // 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) };

rust/hw/char/pl011/src/device.rs pub fn post_load(&self, _version_id: u32) -> Result<(), ()> { · line 724

Quoted 10 lines
rust/hw/char/pl011/src/device.rs +4 -1
 
      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);