[PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit in LCR

Paolo Bonzini posted 7 patches 5 months ago
[PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit in LCR
Posted by Paolo Bonzini 5 months ago
Use ==/!= instead of going through bool and xor.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs | 6 ++----
 rust/hw/char/pl011/src/lib.rs    | 6 ------
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index cfe2734703e..169ff3779c6 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -307,9 +307,7 @@ pub fn write(&mut self, offset: hwaddr, value: u64) {
             Ok(LCR_H) => {
                 let new_val: registers::LineControl = value.into();
                 // Reset the FIFO state on FIFO enable or disable
-                if bool::from(self.line_control.fifos_enabled())
-                    ^ bool::from(new_val.fifos_enabled())
-                {
+                if self.line_control.fifos_enabled() != new_val.fifos_enabled() {
                     self.reset_rx_fifo();
                     self.reset_tx_fifo();
                 }
@@ -502,7 +500,7 @@ pub fn event(&mut self, event: QEMUChrEvent) {
 
     #[inline]
     pub fn fifo_enabled(&self) -> bool {
-        matches!(self.line_control.fifos_enabled(), registers::Mode::FIFO)
+        self.line_control.fifos_enabled() == registers::Mode::FIFO
     }
 
     #[inline]
diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs
index 0747e130cae..69064d6929b 100644
--- a/rust/hw/char/pl011/src/lib.rs
+++ b/rust/hw/char/pl011/src/lib.rs
@@ -419,12 +419,6 @@ pub enum Mode {
         FIFO = 1,
     }
 
-    impl From<Mode> for bool {
-        fn from(val: Mode) -> Self {
-            matches!(val, Mode::FIFO)
-        }
-    }
-
     #[bitsize(2)]
     #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)]
     /// `WLEN` Word length, field of [Line Control register](LineControl).
-- 
2.47.1
Re: [PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit in LCR
Posted by Zhao Liu 4 months, 3 weeks ago
On Thu, Dec 12, 2024 at 06:22:04PM +0100, Paolo Bonzini wrote:
> Date: Thu, 12 Dec 2024 18:22:04 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit
>  in LCR
> X-Mailer: git-send-email 2.47.1
> 
> Use ==/!= instead of going through bool and xor.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  rust/hw/char/pl011/src/device.rs | 6 ++----
>  rust/hw/char/pl011/src/lib.rs    | 6 ------
>  2 files changed, 2 insertions(+), 10 deletions(-)
> 

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Re: [PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit in LCR
Posted by Philippe Mathieu-Daudé 4 months, 3 weeks ago
On 12/12/24 18:22, Paolo Bonzini wrote:
> Use ==/!= instead of going through bool and xor.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   rust/hw/char/pl011/src/device.rs | 6 ++----
>   rust/hw/char/pl011/src/lib.rs    | 6 ------
>   2 files changed, 2 insertions(+), 10 deletions(-)

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