post_load must return a negative errno on failure, but the BRGR/BDIV
validation was returning 1 (positive), which the caller treats as
success. Return -EINVAL instead.

Reported-by: Pavee Hui <[email protected]>
Fixes: 6e29651c5e3a ("char: cadence: check baud rate generator and divider 
values")
Signed-off-by: Marc-André Lureau <[email protected]>
---
 hw/char/cadence_uart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 1a065e2429eb..263c28bb7197 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -594,8 +594,7 @@ static int cadence_uart_post_load(void *opaque, int 
version_id)
     /* Ensure these two aren't invalid numbers */
     if (s->r[R_BRGR] < 1 || s->r[R_BRGR] & ~0xFFFF ||
         s->r[R_BDIV] <= 3 || s->r[R_BDIV] & ~0xFF) {
-        /* Value is invalid, abort */
-        return 1;
+        return -EINVAL;
     }
 
     uart_parameters_setup(s);

-- 
2.56.0.rc0.29.g47ce80527c56


Reply via email to