diff mbox series

hw/char/sifive_uart: Fix broken UART on big endian hosts

Message ID 20241104163504.305955-1-thuth@redhat.com (mailing list archive)
State New
Headers show
Series hw/char/sifive_uart: Fix broken UART on big endian hosts | expand

Commit Message

Thomas Huth Nov. 4, 2024, 4:35 p.m. UTC
Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit
part of the value does not work on big endian hosts. We've got to
take the proper detour through an 8-bit variable.

Fixes: 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/char/sifive_uart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Peter Maydell Nov. 4, 2024, 4:38 p.m. UTC | #1
On Mon, 4 Nov 2024 at 16:35, Thomas Huth <thuth@redhat.com> wrote:
>
> Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit
> part of the value does not work on big endian hosts. We've got to
> take the proper detour through an 8-bit variable.
>
> Fixes: 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  hw/char/sifive_uart.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Philippe Mathieu-Daudé Nov. 4, 2024, 8:50 p.m. UTC | #2
On 4/11/24 13:35, Thomas Huth wrote:
> Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit
> part of the value does not work on big endian hosts. We've got to
> take the proper detour through an 8-bit variable.
> 
> Fixes: 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   hw/char/sifive_uart.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Alistair Francis Nov. 4, 2024, 10:59 p.m. UTC | #3
On Tue, Nov 5, 2024 at 2:35 AM Thomas Huth <thuth@redhat.com> wrote:
>
> Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit
> part of the value does not work on big endian hosts. We've got to
> take the proper detour through an 8-bit variable.
>
> Fixes: 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Urgh!

Thanks for the fix

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/char/sifive_uart.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
> index aeb45d3601..5ae2a29ed6 100644
> --- a/hw/char/sifive_uart.c
> +++ b/hw/char/sifive_uart.c
> @@ -174,10 +174,11 @@ sifive_uart_write(void *opaque, hwaddr addr,
>  {
>      SiFiveUARTState *s = opaque;
>      uint32_t value = val64;
> +    uint8_t ch = value;
>
>      switch (addr) {
>      case SIFIVE_UART_TXFIFO:
> -        sifive_uart_write_tx_fifo(s, (uint8_t *) &value, 1);
> +        sifive_uart_write_tx_fifo(s, &ch, 1);
>          return;
>      case SIFIVE_UART_IE:
>          s->ie = val64;
> --
> 2.47.0
>
>
Alistair Francis Nov. 4, 2024, 11:05 p.m. UTC | #4
On Tue, Nov 5, 2024 at 2:35 AM Thomas Huth <thuth@redhat.com> wrote:
>
> Casting a "uint32_t *" to a "uint8_t *" to get to the lowest 8-bit
> part of the value does not work on big endian hosts. We've got to
> take the proper detour through an 8-bit variable.
>
> Fixes: 53c1557b23 ("hw/char: sifive_uart: Print uart characters async")
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  hw/char/sifive_uart.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
> index aeb45d3601..5ae2a29ed6 100644
> --- a/hw/char/sifive_uart.c
> +++ b/hw/char/sifive_uart.c
> @@ -174,10 +174,11 @@ sifive_uart_write(void *opaque, hwaddr addr,
>  {
>      SiFiveUARTState *s = opaque;
>      uint32_t value = val64;
> +    uint8_t ch = value;
>
>      switch (addr) {
>      case SIFIVE_UART_TXFIFO:
> -        sifive_uart_write_tx_fifo(s, (uint8_t *) &value, 1);
> +        sifive_uart_write_tx_fifo(s, &ch, 1);
>          return;
>      case SIFIVE_UART_IE:
>          s->ie = val64;
> --
> 2.47.0
>
>
diff mbox series

Patch

diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
index aeb45d3601..5ae2a29ed6 100644
--- a/hw/char/sifive_uart.c
+++ b/hw/char/sifive_uart.c
@@ -174,10 +174,11 @@  sifive_uart_write(void *opaque, hwaddr addr,
 {
     SiFiveUARTState *s = opaque;
     uint32_t value = val64;
+    uint8_t ch = value;
 
     switch (addr) {
     case SIFIVE_UART_TXFIFO:
-        sifive_uart_write_tx_fifo(s, (uint8_t *) &value, 1);
+        sifive_uart_write_tx_fifo(s, &ch, 1);
         return;
     case SIFIVE_UART_IE:
         s->ie = val64;