qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: pl011: Allow NULL chardev argument to pl011_create()
@ 2025-03-07 19:00 Peter Maydell
  2025-03-07 21:51 ` Philippe Mathieu-Daudé
  2025-03-09 10:25 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2025-03-07 19:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust, Paolo Bonzini

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>
---
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(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index d0857b470c9..8098f762f4b 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -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);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: pl011: Allow NULL chardev argument to pl011_create()
  2025-03-07 19:00 [PATCH] rust: pl011: Allow NULL chardev argument to pl011_create() Peter Maydell
@ 2025-03-07 21:51 ` Philippe Mathieu-Daudé
  2025-03-09 10:25 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-03-07 21:51 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: qemu-rust, Paolo Bonzini, Kevin Wolf, Zhao Liu

On 7/3/25 20:00, Peter Maydell wrote:
> 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>
> ---
> 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(-)
> 
> diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
> index d0857b470c9..8098f762f4b 100644
> --- a/rust/hw/char/pl011/src/device.rs
> +++ b/rust/hw/char/pl011/src/device.rs
> @@ -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);

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: pl011: Allow NULL chardev argument to pl011_create()
  2025-03-07 19:00 [PATCH] rust: pl011: Allow NULL chardev argument to pl011_create() Peter Maydell
  2025-03-07 21:51 ` Philippe Mathieu-Daudé
@ 2025-03-09 10:25 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2025-03-09 10:25 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, qemu-rust

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

No no, that was all good!  Applied, thanks.

Paolo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-09 10:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-07 19:00 [PATCH] rust: pl011: Allow NULL chardev argument to pl011_create() Peter Maydell
2025-03-07 21:51 ` Philippe Mathieu-Daudé
2025-03-09 10:25 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).